I have been successfully building a debug release of my app during development albeit accompanied by the following warning:
"W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable.
When I do a fullRelease build I encounter the following error:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForFullRelease'.
> java.io.IOException: Can't write [/PATH_TO_APP/app/build/intermediates/transforms/proguard/full/release/jar s/3/1f/main.jar] (Can't read [/PATH_TO_APP/app/build/intermediates/exploded- aar/com.android.support/support- fragment/24.2.1/jars/classes.jar(;;;;;;**.class)] (Duplicate zip entry [android/support/v4/app/r.class == classes.jar:android/support/v4/app/Fragment$1.class]))
I am incorporating the Support Libraries for the purpose of using the AppCompat Permissions in Android 6.0+. The following is my build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '24.0.3'
useLibrary 'org.apache.http.legacy'
ext {
supportLibVersion = '24.2.1'
}
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "com.whatever.appname"
testApplicationId 'com.whatever.appname'
versionCode 8
minSdkVersion 9
targetSdkVersion 24
}
buildTypes {
debug {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFile 'PATH_TO_PROGUARD/proguard-project.txt'
}
}
signingConfigs {
release {
keyPassword 'PASSWORD'
storePassword 'PASSWORD'
keyAlias 'ALIAS'
storeFile file('PATH_TO_KEYSTORE/keystore_file')
}
debug {
keyAlias 'KEY_ALIAS'
keyPassword 'PASSWORD'
storePassword 'PASSWORD'
storeFile file('PATH_TO_DEBUG_KEYSTORE/debug.keystore')
}
}
productFlavors {
full {
versionName '10.6.0'
applicationId 'com.whatever.appname'
testApplicationId 'APP_TEST_ID'
versionCode 8
proguardFile '/PATH_TO_PROGUARD/proguard-project.txt'
signingConfig signingConfigs.release
targetSdkVersion 24
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
dependencies {
compile 'ch.acra:acra:4.7.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-compat:24.2.1'
compile 'com.android.support:support-core-utils:24.2.1'
compile 'com.android.support:support-core-ui:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-annotations:24.2.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
}
In my proguard-project.txt file, due to the use of some deprecated classes, some of the relevant and specific entries for my app are:
-keep class org.apache.http.** { *; }
-dontwarn org.apache.commons.**
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
-ignorewarnings
For those that are curious, when I completely remove the proguard process from the build and do an application clean, followed by a fullRelease build, the errors that I encounter are different:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/graphics/drawable/AnimatedVectorDrawableCompat$1;
and:
Error:Execution failed for task ':app:transformClassesWithDexForFullRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
Can anybody shed some light on the errors that I am encountering, and possibly suggest a work around? Naturally, I would ideally prefer to incorporate the proguard process into build process.
UPDATE: Additionally, when running any gradle tasks from the command line I encountered the error:
problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
which lead me to believe that somewhere in either the AppCompat or Support libraries Java 8 language features were being used, and I was compiling against Java 7.
The solution to my problem was a configuration solution which enables the Java 8 language features as described in the document, Use Java 8 Language Features.
The exact steps I took to solve the issue were to: add the following to the build.gradle defaultConfig section.
jackOptions {
enabled true
}
Add the following to the build.gradle buildTypes, debug & release, respectively:
debug{
shrinkResources false
}
release {
shrinkResources false
}
Changed the build.gradle sourceCompatability and targetCompatability Java versions from VERSION_1_7 to the following
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
After carrying out these changes, I carried out a clean and Build and was able to successfully build the application.