I am trying to fire up a task to copy the aar files (android libs) to a separate folder, but the task keeps getting triggered before the build starts.
I am using this answer but it does not work for me:
Is there a method in Gradle to execute some task after the build?
Here's my gradle:
def buildLibrary = true;
if (buildLibrary) {
apply plugin: 'com.android.library'
} else {
apply plugin: 'com.android.application'
}
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
if (!buildLibrary) {
applicationId "myapp.com.mysdk"
}
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// Support libraries and widgets
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:gridlayout-v7:23.1.1'
}
// Why this keeps getting called before the build starts????
task copyAARToCommonLibs(type: Copy) {
println 'calling copyAARToCommonLibs before libs are built!!!'
from('../build/outputs/aar') {
include '*-release.arr'
}
into '../MyOutput/libs'
println 'end of calling!!!'
}
build.finalizedBy(copyAARToCommonLibs)
// This did not work either
tasks.build.doLast(){
println 'This is never called!!!'
}
and the output from a clean build:
Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
Configuration on demand is an incubating feature.
Crashlytics was applied to an android-library project.
Android-library support is currently an incubating feature.
Contact support#fabric.io with any issues.
calling copyAARToCommonLibs before libs are built!!!
end of calling!!!
:clean UP-TO-DATE
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:preReleaseUnitTestBuild UP-TO-DATE
... a bunch of stuff
:app:generateDebugAndroidTestBuildConfig
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:compileDebugAndroidTestJavaWithJavac
:app:compileDebugAndroidTestNdk UP-TO-DATE
:app:compileDebugAndroidTestSources
BUILD SUCCESSFUL
Total time: 13.157 secs
The print statements that you added to copyAARToCommonLibs are misleading you. Based on their position in the task definition they are being executed at configuration time independently of any inter-task dependency order. This is why the prints appear before the build process occurs (as the configuration is not dependent on the task dependencies).
Here is a simple example:
task blahTask() {
println "Configuring finalizer"
doLast {
println "Actually running finalizer"
}
}
task toFinalize() {
println "Configuring to finalize"
doLast {
println "Actually running thing to finalize"
}
}
toFinalize.finalizedBy(blahTask)
When I execute toFinalize the output is:
Configuring finalizer
Configuring to finalize
:app:toFinalize
Actually running thing to finalize
:app:blahTask
Actually running finalizer
BUILD SUCCESSFUL
As you can see the finalizer's configuration code is actually executed before the configuration code for the task to be finalized (i.e. independent of task dependencies) whereas the doLast code is running in the desired order.
As such, using the print statements in the way you have is not actually giving an indication of when the copy task is running.
Another thing to realize is that in your output (from what you showed) there are no :app:copyAARToCommonLibs statements indicating that the task is not actually being run (it is being configured, hence the prints). According to the task docs a finalizer task will not run if the task being finalized (in your case build) was up to date. Quote:
On the other hand, finalizer tasks are not executed if the finalized task didn't do any work, for example if it is considered up to date or if a dependent task fails.
Related
I am very new to Android and due to some reason, I am getting following o/p in grade console. Not able to resolve. Can anyone give a suggestion to resolve this error?
Executing tasks: [clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugUnitTestSources, :app:compileDebugAndroidTestSources]
Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (25.0.1) and test app (25.0.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
:clean UP-TO-DATE
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2501Library
:app:prepareComAndroidSupportAppcompatV72501Library
:app:prepareComAndroidSupportSupportCompat2501Library
:app:prepareComAndroidSupportSupportCoreUi2501Library
:app:prepareComAndroidSupportSupportCoreUtils2501Library
:app:prepareComAndroidSupportSupportFragment2501Library
:app:prepareComAndroidSupportSupportMediaCompat2501Library
:app:prepareComAndroidSupportSupportV42501Library
:app:prepareComAndroidSupportSupportVectorDrawable2501Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:mockableAndroidJar
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (25.0.1) and test app (25.0.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:prepareDebugAndroidTestDependencies'.
> Dependency Error. See console for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8.644 secs
build.gradle(Project) contain the following data
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(app) contains the following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.team.test"
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.+'
compile 'junit:junit:4.12'
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultPublishConfig "debug"
defaultConfig {
applicationId "com.youth4work.ibps"
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
versionCode 1
versionName "1.0.0"
}
signingConfigs {
release {
storeFile file('keystore/youth4work_second_key')
keyAlias 'youth4work_second_key_alias'
keyPassword "youth4work"
storePassword "youth4work"
}
debug {
storeFile file('keystore/debug.keystore')
keyAlias 'androiddebugkey'
storePassword 'android'
keyPassword 'android'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
versionNameSuffix "Debug"
debuggable true
}
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
retrolambda {
jvmArgs '-noverify'
}
dependencies {
final PLAY_SERVICES_VERSION = '8.3.0'
final SUPPORT_LIBRARY_VERSION = '23.3.0'
// Google Play Services
compile "com.google.android.gms:play-services-base:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services- analytics:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-gcm:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-plus:$PLAY_SERVICES_VERSION"
// Support Libraries
compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
compile 'com.android.support:support-annotations:23.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton.timber:timber:4.1.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile 'com.github.siyamed:android-shape-imageview:0.9.+#aar'
compile 'com.github.kevinsawicki:timeago:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.8.2'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.mobsandgeeks:android-saripaar:2.0.2'
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1'
compile 'com.github.jakob-grabner:Circle-Progress-View:1.2.8'
compile 'com.github.vlonjatg:progress-activity:v1.0.3'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'
compile 'com.daasuu:animateHorizontalProgressBar:0.2.2'
compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'com.trello:rxlifecycle:0.4.0'
compile 'com.trello:rxlifecycle-components:0.4.0'
compile('com.github.afollestad.material-dialogs:core:0.8.5.6#aar') {
transitive = true
}
compile('com.mikepenz:fastadapter:1.4.0#aar') {
transitive = true
}
testCompile 'junit:junit:4.12'
}
// Log out test results to console
tasks.matching { it instanceof Test }.all {
testLogging.events = ["failed", "passed", "skipped"]
}
here if i make minify enabled = false the code runs fine while if i use true the code shows
Information:Gradle tasks [:app:assembleRelease] google-services plugin
could not detect any version for com.google.android.gms, default
version: 8.3.0 will be used. please apply google-services plugin at
the bottom of the build file. :app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE :app:checkReleaseManifest
:app:preDebugBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2330Library
UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72330Library
UP-TO-DATE :app:prepareComAndroidSupportCardviewV72330Library
UP-TO-DATE :app:prepareComAndroidSupportDesign2330Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2330Library
UP-TO-DATE :app:prepareComDaasuuAnimateHorizontalProgressBar022Library
UP-TO-DATE :app:prepareComFacebookAndroidFacebookAndroidSdk482Library
UP-TO-DATE
:app:prepareComGithubAfollestadMaterialDialogsCore0856Library
UP-TO-DATE
:app:prepareComGithubJakobGrabnerCircleProgressView128Library
UP-TO-DATE :app:prepareComGithubSiyamedAndroidShapeImageview093Library
UP-TO-DATE :app:prepareComGithubVlonjatgProgressActivityV103Library
UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics830Library
UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBase830Library
UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement830Library
UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesGcm830Library
UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement830Library
UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesPlus830Library
UP-TO-DATE :app:prepareComJakewhartonRxbindingRxbinding040Library
UP-TO-DATE :app:prepareComJakewhartonTimberTimber410Library UP-TO-DATE
:app:prepareComJoanzapataIconifyAndroidIconify211Library UP-TO-DATE
:app:prepareComJoanzapataIconifyAndroidIconifyFontawesome211Library
UP-TO-DATE :app:prepareComMikepenzFastadapter140Library UP-TO-DATE
:app:prepareComRengwuxianMaterialedittextLibrary214Library UP-TO-DATE
:app:prepareComTrelloRxlifecycle040Library UP-TO-DATE
:app:prepareComTrelloRxlifecycleComponents040Library UP-TO-DATE
:app:prepareIoReactivexRxandroid110Library UP-TO-DATE
:app:prepareIoRealmRealmAndroidLibrary0883Library UP-TO-DATE
:app:prepareMeZhanghaiAndroidMaterialprogressbarLibrary114Library
UP-TO-DATE :app:prepareReleaseDependencies :app:compileReleaseAidl
:app:compileReleaseRenderscript :app:generateReleaseBuildConfig
:app:generateReleaseAssets UP-TO-DATE :app:mergeReleaseAssets
:app:generateReleaseResValues UP-TO-DATE
:app:processReleaseGoogleServices :app:generateReleaseResources
:app:mergeReleaseResources :app:processReleaseManifest
:app:processReleaseResources :app:generateReleaseSources
:app:compileReleaseJavaWithJavac Note: Some input files use or
override a deprecated API. Note: Recompile with -Xlint:deprecation for
details. Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileRetrolambdaRelease :app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources :app:prePackageMarkerForRelease
:app:transformClassesWithRealmTransformerForRelease
:app:processReleaseJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForRelease
:app:transformClassesAndResourcesWithProguardForRelease assmember)
Warning:there were 1 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning:Exception while processing task java.io.IOException: Please
correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
Error:Execution failed for task
':app:transformClassesAndResourcesWithProguardForRelease'.
java.io.IOException: Please correct the above warnings first. Information:BUILD FAILED Information:Total time: 27.946 secs
Information:1 error Information:91 warnings Information:See complete
output in console
If you enable minifying, the build will call Proguard to strip out every unnecessary classes, members and methods.
For this to work, you'll need a proguard config file, which will tell Proguard which classes are your entrypoint to your classes and which members and methods should be kept.
The error you are seeing is a common error for mismatching method calls.
The error includes a link to the Proguard manual, describing the error a bit more: you'll have to make sure that you are using the right Android Build Target and that you keep all necessary libs and their methods.
Try to adapt the Android Build Target in your properties. If this doesn't work, you'll have to check if you need more entries in your proguard config.
I just installed Android Studio, made a project and when the project was building I got this error in the gardle console:
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources]
Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library
:app:prepareComAndroidSupportSupportV42301Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
Error: org.gradle.process.internal.ExecException: A problem occurred starting process 'command '/home/krisitown/Programming/SDK/android-sdk-linux/build-tools/19.1.0/aapt''
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: org.gradle.process.internal.ExecException: A problem occurred starting process 'command '/home/krisitown/Programming/SDK/android-sdk-linux/build-tools/19.1.0/aapt''
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.585 secs
The only thing I did was change the
compile 'com.android.support:appcompat-v7:23.0.1'
in the dependencies because it was giving me an error, after some google-ing I came to the conclusion that it was giving me an error because in the previous line I had a plus sign (+) for the version
EDIT: Here is my build.gardle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Have 2 of em:
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "com.firstapp.krisitown.myapplication"
minSdkVersion 15
targetSdkVersion 15
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
}
Okay, so apparently the issue was caused by the fact that I was running a 64-bit Ubuntu OS and I needed some extra packages, so in case anyone wonders here is the mystical line solver of this situation:
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
I found the answer here, so props to the guy who answered it:
Error: Unable to run mksdcard SDK tool
I have imported a project from Eclipse into Android Studio 1.0.1 that consists in an Android Library Project (RuletaAfortunadaCore) and an Android Project (RuletaAfortunada), also have some third parties library dependencies. During the import everything seemed fine, but now when I try to build it I get this error message from Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ruletaAfortunadaCore:proguardRelease'.
> java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?
The whole output from the start of the building process:
Executing tasks: [clean, :ruletaAfortunada:compileDebugSources, :facebookSDK:compileDebugSources, :ruletaAfortunadaCore:compileDebugSources]
Configuration on demand is an incubating feature.
:facebookSDK:clean
:ruletaAfortunada:clean UP-TO-DATE
:ruletaAfortunadaCore:clean
:facebookSDK:compileLint
:facebookSDK:copyReleaseLint UP-TO-DATE
:facebookSDK:mergeReleaseProguardFiles UP-TO-DATE
:facebookSDK:preBuild
:facebookSDK:preReleaseBuild
:facebookSDK:checkReleaseManifest
:facebookSDK:prepareReleaseDependencies
:facebookSDK:compileReleaseAidl
:facebookSDK:compileReleaseRenderscript
:facebookSDK:generateReleaseBuildConfig
:facebookSDK:generateReleaseAssets UP-TO-DATE
:facebookSDK:mergeReleaseAssets
:facebookSDK:generateReleaseResValues UP-TO-DATE
:facebookSDK:generateReleaseResources
:facebookSDK:packageReleaseResources
:facebookSDK:processReleaseManifest
:facebookSDK:processReleaseResources
:facebookSDK:generateReleaseSources
:facebookSDK:compileReleaseJava
:facebookSDK:processReleaseJavaRes UP-TO-DATE
:facebookSDK:packageReleaseJar
:facebookSDK:compileReleaseNdk
:facebookSDK:packageReleaseJniLibs UP-TO-DATE
:facebookSDK:packageReleaseLocalJar
:facebookSDK:packageReleaseRenderscript UP-TO-DATE
:facebookSDK:bundleRelease
:ruletaAfortunada:preBuild
:ruletaAfortunada:preDebugBuild
:ruletaAfortunada:checkDebugManifest
:ruletaAfortunada:preReleaseBuild
:ruletaAfortunadaCore:compileLint
:ruletaAfortunadaCore:copyReleaseLint UP-TO-DATE
:ruletaAfortunadaCore:preBuild
:ruletaAfortunadaCore:preReleaseBuild
:ruletaAfortunadaCore:checkReleaseManifest
:ruletaAfortunadaCore:preDebugBuild
:ruletaAfortunadaCore:preDebugTestBuild
:ruletaAfortunadaCore:prepareComAndroidSupportSupportV42100Library
:ruletaAfortunadaCore:prepareComGoogleAndroidGmsPlayServices6587Library
:ruletaAfortunadaCore:prepareRuletaAfortunadaFacebookSDKUnspecifiedLibrary
:ruletaAfortunadaCore:prepareReleaseDependencies
:ruletaAfortunadaCore:compileReleaseAidl
:ruletaAfortunadaCore:compileReleaseRenderscript
:ruletaAfortunadaCore:generateReleaseBuildConfig
:ruletaAfortunadaCore:generateReleaseAssets UP-TO-DATE
:ruletaAfortunadaCore:mergeReleaseAssets
:ruletaAfortunadaCore:generateReleaseResValues UP-TO-DATE
:ruletaAfortunadaCore:generateReleaseResources
:ruletaAfortunadaCore:mergeReleaseResources
:ruletaAfortunadaCore:processReleaseManifest
:ruletaAfortunadaCore:processReleaseResources
:ruletaAfortunadaCore:generateReleaseSources
:ruletaAfortunadaCore:compileReleaseJava
:ruletaAfortunadaCore:extractReleaseAnnotations
:ruletaAfortunadaCore:mergeReleaseProguardFiles UP-TO-DATE
:ruletaAfortunadaCore:compileReleaseNdk
:ruletaAfortunadaCore:packageReleaseJniLibs UP-TO-DATE
:ruletaAfortunadaCore:packageReleaseRenderscript UP-TO-DATE
:ruletaAfortunadaCore:packageReleaseResources
:ruletaAfortunadaCore:proguardRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ruletaAfortunadaCore:proguardRelease'.
> java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?
The contents of the build.gradle file for such library project:
apply plugin: 'com.android.library'
android {
compileSdkVersion 13
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}
dependencies {
compile project(':facebookSDK')
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
compile files('libs/chartboost.jar')
compile files('libs/mint-4.0.7.jar')
}
UPDATE: I have realized that the Android Library Project named RuletaAfortunadaCore can be build as an standalone project or made as a module without problems at all. It only fails to build when building the whole RuletaAfortunada Android Project that uses it.
The build.gradle file for such Android Project is the default one created by Android Studio, I think, so has nothing interesting inside. Anyway, here it is, just in case:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
This is the settings.gradle:
include ':facebookSDK'
include ':ruletaAfortunadaCore'
include ':ruletaAfortunada'
And finally, just to have all of them, this is the facebookSDK module build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 9
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 9
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/bolts-android-1.1.2.jar')
}
As suggested by one guy which answer seem to have vanished now :-?, the solution for me has been to set minifyEnabled to false in the build.gradle of my Library Project. As far as I have it set as true for the Android Project itself, proguard will be executed anyway and the error have disappeared.
I've found some useful info here: http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0
One notable difference is that runProguard was changed to minifyEnabled.
However, after completing the steps from this migration topic, I still run into the same build error.
I noticed that running gradle assembleRelease calls upon an outdated ProGuard version as can be seen from the shell output:
$ gradle assembleRelease
Relying on packaging to define the extension of the main artifact has been \
deprecated and is scheduled to be removed in Gradle 2.0
:Foobar:preBuild UP-TO-DATE
:Foobar:preReleaseBuild UP-TO-DATE
:Foobar:preDebugBuild UP-TO-DATE
:Foobar:prepareComAndroidSupportAppcompatV71900Library UP-TO-DATE
:Foobar:prepareComGoogleAndroidGmsPlayServices3136Library UP-TO-DATE
:Foobar:prepareReleaseDependencies
:Foobar:compileReleaseAidl UP-TO-DATE
:Foobar:compileReleaseRenderscript UP-TO-DATE
:Foobar:generateReleaseBuildConfig UP-TO-DATE
:Foobar:mergeReleaseAssets UP-TO-DATE
:Foobar:mergeReleaseResources UP-TO-DATE
:Foobar:processReleaseManifest UP-TO-DATE
:Foobar:processReleaseResources UP-TO-DATE
:Foobar:generateReleaseSources UP-TO-DATE
:Foobar:compileRelease UP-TO-DATE
:Foobar:proguardRelease
ProGuard, version 4.9
The output seems up to date
:Foobar:dexRelease UP-TO-DATE
:Foobar:processReleaseJavaRes UP-TO-DATE
:Foobar:packageRelease UP-TO-DATE
:Foobar:assembleRelease UP-TO-DATE
BUILD SUCCESSFUL
Total time: 15.703 secs
I use the following configuration in my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard true
proguardFile 'proguard-project.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
}
How can I point gradle to a newer version of ProGuard which might be available from the PATH, e.g. /usr/local/bin/proguard?
An alternative solution is to reference the desired version as follows:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
classpath 'net.sf.proguard:proguard-gradle:4.10'
}
}
...
What is your setup?
The official Proguard doc shows how you can point to proguard in the build.gradle. See here
As per the Proguard manual you can do the below to point to a proguard binary,
buildscript {
repositories {
flatDir dirs: '/usr/local/java/proguard/lib'
}
dependencies {
classpath ':proguard'
}
}
I think this might cause problems with the proguard version that comes shipped with the android SDK. Not tried yet!!