How to reference system ProGuard binary in build.gradle? - android

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

Related

Error when multiple libraries use diferent versions of the same external library in gradle

I'm facing some problems when updating the external libraries that my app uses. Here are the gradle files:
Project build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
daggerVersion = "2.13"
supportVersion = "27.1.1"
}
Application build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.myapp"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:animated-vector-drawable:$supportVersion"
implementation "com.android.support:support-fragment:$supportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-analytics:12.0.1'
// implementation 'com.android.support:multidex:1.0.3'
// Google Sign In SDK (only required for Google Sign In)
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.hannesdorfmann.mosby3:mvp-lce:3.0.4'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
kapt 'com.github.bumptech.glide:compiler:4.6.1'
// Firebase UI
// Used in FirebaseUIActivity. The FirebaseUI-Android library has a minSdk level of 16
// so this library is only included in the minSdkJellybean variant.
implementation 'com.firebaseui:firebase-ui-auth:3.2.1'
// Facebook Android SDK (only required for Facebook Login)
// Used in FacebookLoginActivity. This is only compiled into the minSdkJellybean variant of this
// app. You can build a 'minSdkGingerbread' variant to test on devices with 9 <= SDK <= 15.
implementation 'com.facebook.android:facebook-login:4.31.0'
implementation "com.android.support:customtabs:$supportVersion"
// Twitter Android SDK (only required for Twitter Login)
// implementation('com.twitter.sdk.android:twitter-core:3.2.0#aar') {
// transitive = true
// }
// implementation('com.twitter.sdk.android:twitter:3.2.0#aar') {
// transitive = true
// }
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
// Dagger
implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
// Room
implementation "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
implementation "android.arch.lifecycle:common-java8:1.1.1"
// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
// compile 'io.reactivex.rxjava2:rxkotlin:2.2.0'
// RxFirebase
implementation('com.github.b3er.rxfirebase:firebase-database:11.2.0') {
transitive = false
}
// // PhotoView
// implementation 'com.github.chrisbanes:PhotoView:2.1.3'
// ucrop
// implementation 'com.github.yalantis:ucrop:2.2.2'
}
apply plugin: 'com.google.gms.google-services'
But when I try to run the application I get the following error:
Executing tasks: [:app:assembleDebug]
Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug]
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.github.bumptech.glide:compiler:4.6.1'.
:app:buildInfoDebugLoader
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mainApkListPersistenceDebug UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: /Users/joan/Development/myapp/git/myapp-android/app/google-services.json
:app:mergeDebugResources UP-TO-DATE
:app:createDebugCompatibleScreenManifests UP-TO-DATE
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug UP-TO-DATE
:app:processDebugResources
:app:kaptGenerateStubsDebugKotlin
:app:kaptDebugKotlin
w: Note: [1] Wrote GeneratedAppGlideModule with: []
w: warning: Supported source version 'RELEASE_7' from annotation processor 'org.jetbrains.kotlin.kapt3.ProcessorWrapper' less than -source '1.8'
w: /Users/joan/Development/myapp/git/myapp-android/app/build/tmp/kapt3/stubs/debug/com/myapp/model/ApplicationDatabase.java:7: warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide `room.schemaLocation` annotation processor argument OR set exportSchema to false.
public abstract class ApplicationDatabase extends android.arch.persistence.room.RoomDatabase {
^
:app:compileDebugKotlin
:app:prepareLintJar UP-TO-DATE
:app:generateDebugSources
:app:javaPreCompileDebug
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileDebugJavaWithJavac
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:packageInstantRunResourcesDebug
:app:validateSigningDebug
:app:processInstantRunDebugResourcesApk
:app:checkManifestChangesDebug
:app:transformClassesWithStackFramesFixerForDebug
:app:transformClassesWithDesugarForDebug
:app:transformClassesWithExtractJarsForDebug
:app:transformClassesWithInstantRunVerifierForDebug
:app:transformClassesWithDependencyCheckerForDebug
:app:compileDebugNdk NO-SOURCE
:app:mergeDebugJniLibFolders
:app:transformNativeLibsWithMergeJniLibsForDebug
:app:processDebugJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForDebug
:app:transformNativeLibsAndResourcesWithJavaResourcesVerifierForDebug
:app:transformClassesWithInstantRunForDebug
:app:transformClassesEnhancedWithInstantReloadDexForDebug
:app:incrementalDebugTasks
:app:preColdswapDebug
:app:fastDeployDebugExtractor
:app:generateDebugInstantRunAppInfo
:app:transformClassesWithInstantRunSlicerForDebug
:app:transformClassesWithDexBuilderForDebug
AGPBI: {"kind":"error","text":"Program type already present: android.arch.lifecycle.LiveData$1","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
:app:buildInfoGeneratorDebug
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/0.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/1.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/2.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/3.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/4.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/5.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/6.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/7.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/8.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/9.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/10.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/11.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/12.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/13.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/14.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/15.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/16.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/17.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/18.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/19.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/20.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/21.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/22.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/23.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/24.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/25.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/26.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/27.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/28.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/29.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/30.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/31.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/32.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/33.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/34.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/35.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/36.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/37.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/38.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/39.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/40.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/41.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/42.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/43.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/44.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/45.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/46.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/47.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/48.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/49.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/50.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/51.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/52.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/53.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/54.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/55.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/56.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/57.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/58.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/59.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/60.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/61.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/62.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/63.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/64.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/65.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/66.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/67.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/68.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/69.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/70.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/71.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/72.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/73.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/74.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/75.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/76.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/77.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/78.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/79.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/80.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/81.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/82.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/83.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/84.jar, /Users/joan/Development/myapp/git/myapp-android/app/build/intermediates/transforms/dexBuilder/debug/85.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
45 actionable tasks: 34 executed, 11 up-to-date
But if I change the supportVersion to 27.0.2 everything works fine until I add an other library (implementation 'com.github.yalantis:ucrop:2.2.2'), then I have the same issue. It looks like each library is using different versions of other libs I use, but I don't know how to solve this issue. Any help?

Gradle Error with Android Studio

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

Android Studio 2.1.2 - too slow to build

I have dell inspiron N4010 laptop with Intel Core i5 CPU M 480 # 2.67GHz, 4GB RAM, 500GB Hard disk running ubuntu 16.04LTS - 64bit OS. I have been developing Android Apps in Android Studio 1.5+ Version. Now migrated to Android Studio 2.1.2. Everything was smooth in previous versions of AS in my Laptop.
Building Apps in the latest version is too slow; takes 30seconds to 1.5 minutes to build - only while editing xml files. If I made any change in Java files, then build time went to 10 minutes.
So, I formatted the hard disk to ext4 and installed ubuntu 16.04(Single OS) - 500GB fully...
Downloaded and installed Android Studio 2.1.2 and Oracle jdk 8. Still it takes 10 minutes for every time I change any java files.
Here is my app(module) gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.gmail.balavickey1192"
minSdkVersion 16
targetSdkVersion 24
versionCode 300
versionName "2.0"
multiDexEnabled true
}
dexOptions {
incremental true
preDexLibraries true
javaMaxHeapSize "10g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
url 'http://repo.brightcove.com/releases'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.roughike:bottom-bar:1.4.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.brightcove.player:exoplayer:4.8.2'
}
Project level gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried to search from internet and found some solutions. Here is my gradle.properties file:
org.gradle.jvmargs=-Xmx11000m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
And also disabled few plugins:
CVS integration
Git
Github
Google cloud tools
Subversion Integration
Changed following settings to checked mark by File->Settings->Build,Execution,Deplyment--->
Global Gradle settings- offline work
Compiler- Compile independent modules
- Make project automatically
- command line options: --offline --profile --parallel
- Use in-process build
- Configure on demand
Instant run - unchecked(disabled) everything in that tab.
Still it is too slow... 8 to 10 minutes!
So decided to build via command line; closed every apps even android studio, firefox and everything.
./gradlew assembleDebug --profile -- offline
first time, it said subsequent builds will be faster. Now build time decreased to 3 to 4 minutes...
Here is the report generated while building:
:app 6m47.94s (total)
:app:transformClassesWithDexForDebug 4m7.32s
:app:packageDebug 1m24.23s
:app:mergeDebugJniLibFolders 21.533s UP-TO-DATE
:app:transformClassesWithMultidexlistForDebug 14.906s
:app:transformNative_libsWithMergeJniLibsForDebug 10.125s UP-TO-DATE
:app:compileDebugJavaWithJavac 9.781s
:app:validateDebugSigning 6.251s
:app:transformClassesWithJarMergingForDebug 4.309s
:app:transformResourcesWithMergeJavaResForDebug 3.707s UP-TO-DATE
:app:zipalignDebug 3.657s
:app:processDebugJavaRes 0.543s UP-TO-DATE
:app:mergeDebugResources 0.302s UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72400Library 0.146s UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Library 0.121s UP-TO-DATE
:app:processDebugManifest 0.076s UP-TO-DATE
:app:generateDebugBuildConfig 0.062s UP-TO-DATE
:app:processDebugResources 0.061s UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72400Library 0.054s UP-TO-DATE
:app:assembleDebug 0.051s Did No Work
:app:prepareComAndroidSupportMediarouterV72300Library 0.050s UP-TO-DATE
:app:prepareComFacebookAndroidFacebookAndroidSdk4141Library 0.044s UP-TO-DATE
:app:prePackageMarkerForDebug 0.041s
:app:prepareComGoogleAndroidGmsPlayServicesAds900Library 0.041s UP-TO-DATE
Total Build Time 7m37.73s
Startup 6.695s
Settings and BuildSrc 0.738s
Loading Projects 0.533s
Configuring Projects 10.535s
Task Execution 6m47.94s
Here is my system monitor screen captured while building gradle via terminal:
The same project runs smoothly on another HP Laptop with same configurations(i5, 4GB RAM, 500GB HDD, ubuntu 16.04-64 bit OS), same tools: Android Studio 2.1.2, oracle jdk-8; takes only very few seconds to build and run on that machine.
But for mine, the whole system hangs; Can't do anything while building either from Android Studio or from terminal.
Please help me guys...

Why android gradle task is starting before libs are built?

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.

Android Studio proguardRelease FAILED due empty output jar library

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.

Categories

Resources