I want to copy files before the build starts, but the gradle task dont start.
My section android in my build.gradle file:
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
//Copy app_values.xml
task copy_app_values (type: Copy)<<{
println 'Copy app_values'
copy_app_values.from pathtoValues+'app_values.xml'
copy_app_values.into projectDir+'/'+moduleName+'/src/main/res/values'
}
buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
hockeyapp {
debuggable true
println 'Build HockeyApp'
tasks.add(copy_app_values)
}
}
}
Can anyone explain how this works. I'm newbie in gradle.
I am not sure by your question what exactly you are looking for. Either you just want to run this task once before gradle tries to create the hockeyapp build or just before the compile. Either way, try the following,
task copyDocs(type: Copy) {
from 'src/main/doc'
into 'build/target/doc'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(copyDocs)
}
Place this piece of code out of the Android section and try running it. Hope it helps.
Related
I would like to add a gradle task to my Android build under Android Studio. Various on-line documentation shows clearly how to create a task, but not where to place it in a build.gradle file and which one of them.
A simple, complete example would be perfect.
BTW, I'd like to add a pre-build task to prepare some data, and maybe a post-build task to do some verification/validation.
By trial-and-error and input from Martin Zeitler, I successfuly added pre- and post-build tasks to my build.gradle (app module) as shown below:
This works perfectly.
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "MyPackage"
minSdkVersion 11
targetSdkVersion 26
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
// My libraries here
}
// MY PREBUILD TASK
task PreBuild {
println "MY PRE-BUILD TASK"
}
// MY POSTBUILD TASK
gradle.buildFinished {
println "MY POST_BUILD TASK"
}
}
I add a gradle project to Android Studio.
The project is built like this previously: First call a python script, the script will call ndk-build to build a .so, then call gradle script to archive a .apk.
After import to Android Studio, I add a externalNativeBuild block to the build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "org.cocos2dx.Game"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
abiFilters "x86"
arguments "-j3"
}
}
}
sourceSets.main {
java.srcDir "src"
res.srcDir "res"
jniLibs.srcDir "libs"
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "assets"
}
signingConfigs {
release {
if (project.hasProperty("RELEASE_STORE_FILE")) {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
}
debug {
debuggable true
jniDebuggable true
externalNativeBuild {
ndkBuild {
cFlags "-DDEBUG=1"
}
}
}
}
externalNativeBuild {
ndkBuild {
path "jni/Android.mk"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':libcocos2dx')
}
task cleanAssets(type: Delete) {
delete 'assets'
}
task copyAssets(type: Copy) {
from '../../Resources'
into 'assets'
}
clean.dependsOn cleanAssets
preBuild.dependsOn copyAssets
The project successfully compiled, and installed, and run.But when signal happens, all function names in stack are in gray color, Clicking the function cannot navigate to c++ code (But the name of the function is right). If open the code manually, it always showing "This file is not part of the project" on top of the code.
I'm pretty sure the c++ codes are well compiled, How did this happen?
Fixed it by myself.
I changed the NDK version from 9b to 13, problem solved.
Nobody tells me about this, I tried everything and finally found the solution was so simple. So I post this answer, just in case I can save some other's time.
The error report won't tell you "go and upgrade the NDK", but if some odd thing happens, try this first. In this case, I think it is because of some bugs in ndk toolchain, which are fixed in the higher version.
What I want to do & the problem
I updated my Android Studio and Android Gradle Plugin to 3.0.1 and my Gradle Wrapper to 4.1 and can build & deploy my Android Gradle project in release variant on a device via IDE.
However, the following 'Gradle Sync' warning messages are shown:
Warning:Module 'library' has variant 'release' selected, but the modules ['integration-test'] depend on variant 'debug'
The problem here is, that there is no 'release' variant for the integration-test module which uses the 'com.android.test'
plugin.
If I simply try to add a release build type (buildTypes { release {} }) to the :integration-test module I receive:
Error:VariantInputs initialized with no merged manifest report on: DEFAULT
Details about the project (simplified)
The project consists of:
a :library module
an :app module which builds the app's apk and uses the :library module
an :integration-test module which:
uses the "com.android.test" plugin
dependents on the :app module via targetProjectPath ':app' & targetVariant 'debug'
and contains instrumented tests on the :app functions
only contains a 'main' folder (the test plugin does not support others)
This project is build after the Android Test Blueprint as the goal is here that the :app module does not know anything about the integration-test module's existence.
settings.gradle
include :library
include :app
include :integration-test
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
publishNonDefault true
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationId "xxxxx"
testInstrumentationRunner rootProject.ext.testInstrumentationRunner
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
release {
keyAlias 'xxxx'
}
}
buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
// This is needed by the integration-test module (i.e. com.android.test : integration test)
// in order for targetVariant to work without a flavor
publishNonDefault true
testOptions {
unitTests {
// Required so that logging methods do not throw not mocked exceptions in junit tests.
returnDefaultValues = true
}
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibility
targetCompatibility rootProject.ext.targetCompatibility
}
}
dependencies {
// Local dependencies
compile project(':library')
// i cleaned up all the other dependencies as they wouldn't help here
}
Question
Did anyone get an (integration-)test module using the com.android.test plugin to run with Android Gradle Plugin 3.0.1 without getting the "no release variant" error? If so, how can I avoid this error or how can I add such a release variant to a android test plugin based module (if this makes sense at all)?
I was also getting
VariantInputs initialized with no merged manifest report on: DEFAULT.
Then I followed exactly what is outlined in the https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint
The error went away when I removed release buildType from the `buildTypes' block in the test module's Gradle file.
From this:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
to
buildTypes {
}
I am trying to import 'https://code.google.com/p/android-serialport-api/'into Android Studio. Since this project involves ndk, I followed the instructions to build NDK from the following link: http://tools.android.com/tech-docs/new-build-system/gradle-experimental
But after building, I get this error:
Gradle Project refresh Failed
Error:Cause: org.gradle.api.internal.ExtensibleDynamicObject
EDIT: I have 2.5 gradle version installed
Here's my build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig.with {
applicationId = "android_serialport_api.sample"
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 22
android.ndk {
moduleName = "serial_port"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create("all")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
}
Can you try change
compileSdkVersion 22
buildToolsVersion "22.0.1"
to
compileSdkVersion = 22
buildToolsVersion = "22.0.1"
and
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
to
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
I've got the same error and this works for me.
Unfortunately the NDK preview implementation to support native code development in Android Studio is a moving target. Even if you use an older, developers.android.com stated, "supported" combination of the experimental Android Gradle plugin (from tools.android.com) and Gradle version (from gradle.org), good luck in getting the build to work. Instead, always use the latest released combination with the latest indicated module build.gradle language syntax, according to developers.android.com.
In your case, your mixing the use of assignment operators, "=" and "+=". Depending on the supported combo of gradle plugin and gradle version you're using, it's either use the assignment operators everywhere in module build.gradle file or nowhere - you have to be consistent, all or nothing. For "+=" use the method ".add(...)" instead.
And remember, the gradle scripting language is compiled to the Java runtime so when you see a build error that looks like a Java error, it's the gradle scripting that is likely the problem.
I got this error when I had a parameter not correctly moved from old gradle syntax to new one
(had cFlags "..." rather than CFlags += "...")
Have a look e.g. at http://tools.android.com/tech-docs/new-build-system/gradle-experimental
i found a weird behaviour in Android Studio.
I want to access the dexDebug task in my module build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.testprj.test"
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dexDebug.doFirst {
// do some stuff here
}
But i get the following error: Error:(rowNumber, 0) Could not find property 'dexDebug' on project ':app'.
That's weird because i can call this task over the Android Studio terminal via gradle dexDebug.
What is the reason for it?
Create your own task:
task myTask() {
}
Make your task "process stuff" before dexDebug:
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(dexDebug)) { // <-- check if your task is ready
dexDebug.dependsOn myTask // <-- make it depend on your task
}
}