gradle android plugin variant dependencies: DSL method not found - android

I have a multi-flavor project, with flavors called "qa" and "prod". I need to include different versions of a library depending on both the build type and the flavor.
The documentation at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Type-Product-Flavor-Build-Variant suggests that build types and flavors can be combined, using a "flavorBuildCompile" notation. However when I do this I get this error:
Error:(88, 0) Gradle DSL method not found: 'qaDebugCompile()'
I'm pretty sure this used to work (in an older version of gradle). Currently using gradle 2.1. I haven't found an explanation if the way to do this has changed.
Note, it works fine if I use "flavorCompile" notation, it only fails when I include the build type as well.
Here is the outline of my build script:
android {
compileSdkVersion 17
buildToolsVersion "20"
...
productFlavors {
qa {
applicationId "com.myapp.qa"
}
prod {
applicationId "com.myapp.prod"
}
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
qa {
res.srcDirs = ['res_qa']
}
prod {
res.srcDirs = ['res_prod']
}
}
}
...
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
qaCompile 'com.myapp.integration:other_lib:3.0+#aar' //this is fine
qaDebugCompile 'com.myapp.integration:mylib_qa:3.0+#aar' //this fails!
prodDebugCompile 'com.myapp.integration:mylib_prod:3.0+#aar'
qaReleaseCompile 'com.myapp.release:mylib_qa:3.0+#aar'
prodReleaseCompile 'com.myapp.release:mylib_prod:3.0+#aar'
}

Related

Unexpected node Android Packaging in Android Gradle build

I am trying to make my project use gradle. The problem is that everytime I try to build, I get the following error:
Error:Internal error: (java.lang.AssertionError) Unexpected node Android Packaging; nodes=[Module 'Serengeti' production, Resources for 'Serengeti' production, Resources for 'Serengeti' tests, Artifact 'Serengeti', gradle-resources-production:Serengeti, gradle-resources-test:Serengeti, Android Gradle Build Target]
java.lang.AssertionError: Unexpected node Android Packaging; nodes=[Module 'Serengeti' production, Resources for 'Serengeti' production, Resources for 'Serengeti' tests, Artifact 'Serengeti', gradle-resources-production:Serengeti, gradle-resources-test:Serengeti, Android Gradle Build Target]
at com.intellij.util.graph.GraphGenerator.buildOuts(GraphGenerator.java:55)
at com.intellij.util.graph.GraphGenerator.<init>(GraphGenerator.java:36)
at com.intellij.util.graph.GraphGenerator.create(GraphGenerator.java:40)
at org.jetbrains.jps.builders.impl.BuildTargetIndexImpl.initializeChunks(BuildTargetIndexImpl.java:86)
at org.jetbrains.jps.builders.impl.BuildTargetIndexImpl.getSortedTargetChunks(BuildTargetIndexImpl.java:50)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:610)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:352)
at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:191)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:131)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:229)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:113)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:158)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
I have no idea what this means. I found this but it's not really helpful...
This is my build.gradle file. This is my first time using gradle so if there is anything wrong with this please point it out.
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'io.fabric'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
// http://gradleplease.appspot.com/
compile 'com.android.support:support-v4:20.+'
compile 'com.google.android.gms:play-services:+'
compile 'joda-time:joda-time:+'
compile 'com.googlecode.android-query:android-query:+'
compile 'me.dm7.barcodescanner:zbar:+'
compile 'com.github.asne.facebook:facebook:3.17.2'
compile('com.twitter.sdk.android:twitter:1.0.1#aar') {
transitive = true;
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
lintOptions {
abortOnError false
}
signingConfigs {
SignConfig {
keyAlias 'removed'
keyPassword 'removed'
storeFile file('removed')
storePassword 'removed'
}
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
release {
zipAlignEnabled
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
productFlavors {
RunConfig {
signingConfig signingConfigs.SignConfig
}
}
}
How can I fix this error?
Found the solution to this problem. If you go to Project Structure -> Modules -> <Your project> -> Android, you will notice that nothing loads. It will look like this:
In order to fix this, select Android and click Remove (the red dash above). Then click Add (the green plus above) and select Android. Click OK and the error should be gone now.

Robotium test case is not working with gradle

I am using Robotium for my test case. When i am using eclipse for run a test case it is working and showing 2 fail result but when i am using gradle for test case it is showing BUILD SUCCESSFUL.But in my code 2 fail results.
I am using this command - gradle clean connectedCheck build
My build.gradle file--
buildscript { repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('MyTestCase')
instrumentTest {
java.srcDirs = ['MyTestCase/src']
manifest.srcFile file('MyTestCase/AndroidManifest.xml')
resources.srcDirs = ['MyTestCase/src']
res.srcDirs = ['MyTestCase/res']
assets.srcDirs = ['MyTestCase/assets']
}
}
dependencies {
compile files('libs/android-support-v4.jar')
}
lintOptions {
abortOnError false
}
}

Android studio cannot resolve annotated class

Im using Android studio 0.4.2 (Gradle project) with AA
My gradle.build looks like below
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
......
dependencies {
compile 'com.android.support:support-v4:19.0.0+'
compile 'com.android.support:appcompat-v7:19.0.0+'
compile 'com.googlecode.androidannotations:androidannotations-api:2.7.1'
compile 'com.googlecode.androidannotations:androidannotations:2.7.1'
compile fileTree(dir: 'libs', include: '*.jar')
}
android.applicationVariants.each { variant ->
println 'Generation dir: ' + annotationDirs
variant.javaCompile.dependsOn annotationsDir
variant.javaCompile.options.compilerArgs += [
'-processor', 'com.googlecode.androidannotations.AndroidAnnotationProcessor',
'-s', annotationDirs
]
}
in my project I just use genereted java class like replaceFragment(new RegistrationFragment_()); , this is a correct way to use annotated class and it works well when I run build task, but IDE shows me an error - 'cannot resolve symbol RegistrationFragment_'. All gen _.java files are stored in PROJECT_NAME\app\build\classes\debug\com\witness\app\RegistrationFragment_.java. How can I fix this?

Gradle + Android, want to overwrite /assets with custom folder in buildFlavor

In my current build scripts I have special /res/ and /assets folders that I copy over the working versions of the files at build time. In /assets/ is bundled data (sql and a text file) while in /res/values/ I have a connection.xml values file.
There are already duplicates of these files in the working directory, however at build time I want to use the ones from the /config/ folder of my project and copy them over the ones in the /res and /assets for the current build.
In my verbose logging I get a
"com.android.ide.common.res2.DuplicateDataException" when it tries to copy the file.
Any idea's how to handle this? I can make the filename unique, but the key/value pairs inside it will not be? Would that solve the issue?
My Build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.0'
}
}
apply plugin: 'android'
android {
compileSdkVersion "Google Inc.:Google APIs:18"
buildToolsVersion "17"
signingConfigs {
release {
storeFile file("../../TioClient/keystore/android.keystore")
storePassword "REDACTED"
keyAlias "pge-android"
keyPassword "lightmaker"
}
}
buildTypes {
dev {
signingConfig signingConfigs.release
}
tps {
signingConfig signingConfigs.release
}
production {
signingConfig signingConfigs.release
}
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 15
}
dependencies {
compile project(':TioClient');
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = []
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
tps {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = []
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res','config/tps/res']
assets.srcDirs = ['assets', 'config/tps/assets']
}
instrumentTest.setRoot('tests')
}
}
You can define assets at the buildtype level or product flavor level by including appropriate folders in your src.
Build type resources override flavor resources which override main resources.

How to execute task in Gradle one by one

I have this gradle build file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
classpath 'com.eriwen:gradle-css-plugin:1.2.1'
classpath 'com.eriwen:gradle-js-plugin:1.5.1'
}
}
apply plugin: 'android'
apply plugin: 'js'
apply plugin: 'css'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/cordova-2.7.0.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
}
task MinifyJSForRelease {
tasks.add(name:"copyTask2", type:Copy){
from 'assets/'
into 'build/minifiedassets/assets'
}
it.dependsOn copyTask2
def tester = fileTree(dir:"build/minifiedassets/assets", include:"**/*.js");
println tester
tester.eachWithIndex {File file, idx ->
tasks.add(name: "makeMinifyJS${idx}", type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = file
dest = "${file.path}"
closure {
compilerOptions.languageIn = "ECMASCRIPT5"
}
}
}
it.dependsOn tasks.matching { Task task -> task.name.startsWith("makeMinifyJS")}
}
build.dependsOn MinifyJSForRelease
android {
compileSdkVersion 17
buildToolsVersion "17"
signingConfigs {
release {
storeFile file('keystores/mobilecoe_android.keystore')
storePassword "mobilecoe"
keyAlias "MobileCoE"
keyPassword "mobilecoe"
}
}
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
release {
signingConfig signingConfigs.release
zipAlign true
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['build/minifiedassets/assets']
}
instrumentTest.setRoot('tests')
}
}
}
}
I Want to run the task MinifyJSForRelease like the first thing would be to copy the assets folder to where I want and then when that is finished I want to minify the JS files.
Now when I run the task it copies the folder but not reaching the end the next function says it has nothing to minify but if I run the task the second time(when the folder is already copied) it fiends it and does everything.
What am I do in wrong?
I need to:
copy folder
Get the folder and minify its js files
Could some one help me out?
I'm a total virgen to Gradle, So I can only provide you with educated guess:
unify the way you declare the dependencies
taskB.dependsOn tasksA
force the order of the task (in add of the dependency)
taskB.mustRunAfter(taskA)
add logs, to see if the task is executed VS the tasks does not do what you expect.
Adding dependencies to a task / Ordering tasks
http://www.gradle.org/docs/current/userguide/more_about_tasks.html
please, provide us with the solution once you got it !

Categories

Resources