Gradle Android buildTypes overriding each other - android

I'd appreciate any help with this since I'm a noobie w/ gradle. I've got a build script with multiple buildTypes, but it appears settings for one of them are overwriting the others.
Here's my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile project(':facebook-android-sdk-3.0.1:facebook')
compile project(':google-play-services_lib')
compile project(':nineoldandroids')
compile project(':SlidingMenu-master:library')
compile project(':ViewPagerIndicator')
compile project(':volley')
compile project(':windowed-seek-bar')
compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
}
android {
buildToolsVersion "17.0"
compileSdkVersion 17
signingConfigs {
debug {
storeFile file('keystores/debug.keystore')
}
release {
storeFile file('keystores/release.keystore')
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'normal']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
release {
signingConfig signingConfigs.release
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'normal']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
utest {
debuggable true
signingConfig signingConfigs.debug
sourceSets {
main {
manifest.srcFile 'utest/AndroidManifest.xml'
java.srcDirs = ['src', 'utest']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
}
The settings for utest are overriding the settings for release and debug. Anybody know why?

Your usage of source sets is wrong. It is not inside each build type closure. They are declared on their own:
android {
buildTypes {
debug {
...
}
release {
...
}
utest {
...
}
}
sourceSets {
debug {
...
}
release {
...
}
utest {
...
}
}
}
Note that the build types have their own source sets on top of the 'main' source sets. So you shouldn't set all the build type sourceset to use 'src'. You could do
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
utest {
manifest.srcFile 'utest/AndroidManifest.xml'
java.srcDirs = ['utest']
}
}
}
Note that in this case the manifest under utest/AndroidManifest.xml will be merged in the main manifest.

Related

Task 'prepareReleaseUnitTestDependencies' not found in project ':app'

I'm getting this error in console while building my android project. Please help me understand this.
Messages:
Error:FAILURE: Build failed with an exception.
What went wrong:
Task 'prepareReleaseUnitTestDependencies' not found in project ':app'.
Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Gradle:
buildscript
{
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
//subprojects are added here
project(':external:calendar') {
apply plugin: 'android-library'
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
project(':external:colorpicker') {
apply plugin: 'android-library'
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
project(':external:datetimepicker') {
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:25.3.1'
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
project(':external:timezonepicker') {
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:25.3.1'
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
}
}
lintOptions {
abortOnError false
}
}
}
project(':external:chips') {
apply plugin: 'android-library'
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
compile project(':external:calendar')
compile project(':external:colorpicker')
compile project(':external:datetimepicker')
compile project(':external:timezonepicker')
compile project(':external:chips')
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
}
useLibrary 'org.apache.http.legacy'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'external/ex/common/java'] // NOTE: this includes external/ex/common/java!
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
/*
* To sign release build, create file gradle.properties in ~/.gradle/ with this content:
*
* signingStoreLocation=/home/key.store
* signingStorePassword=xxx
* signingKeyAlias=alias
* signingKeyPassword=xxx
*/
if (project.hasProperty('signingStoreLocation') &&
project.hasProperty('signingStorePassword') &&
project.hasProperty('signingKeyAlias') &&
project.hasProperty('signingKeyPassword')) {
println "Found sign properties in gradle.properties! Signing build…"
signingConfigs {
release {
storeFile file(signingStoreLocation)
storePassword signingStorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}
}
buildTypes.release.signingConfig = signingConfigs.release
} else {
buildTypes.release.signingConfig = null
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
task customClean(type: Delete) {
delete rootProject.buildDir
}
clean.dependsOn customClean
perhaps you need to delete " -x prepareReleaseUnitTestDependencies" from :
Setting / build,execution, deployment/ compiler/ command-line Options
.

Gradle android test

I have project with next structure:
-project_dir
--libmodule
---src[main code path]
---test[test code path]
--app
---src[main code path]
I have just one test class with one test function inside inside project_dir/libmodule/test// folder.
I can run it from source file (I am using Android Studio). But if i try to run it using test gradle task, it has not found any tests. I have followed modified source configuration (just legacy yet, but seems it does not matter):
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
test {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['test']
resources.srcDirs = ['test']
aidl.srcDirs = ['test']
renderscript.srcDirs = ['test']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
Have you any ideas why test task doesn't see any tests?
If this is an android test, you need to set sourceDirs for configuration androidTest instead of test, or alternatively, instead of setting each of those srcDirs, you could do:
androidTest.setRoot('test')

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
}
}

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