【发布时间】:2017-03-01 22:51:32
【问题描述】:
我在开发过程中成功构建了我的应用程序的调试版本,尽管伴随着以下警告:
"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.
当我进行完整版本构建时,我遇到以下错误:
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]))
我正在合并支持库,以便在 Android 6.0+ 中使用 AppCompat 权限。以下是我的 build.gradle 文件。
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')
}
在我的 proguard-project.txt 文件中,由于使用了一些已弃用的类,我的应用程序的一些相关和特定条目是:
-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
对于那些好奇的人,当我从构建中完全删除 proguard 进程并执行应用程序清理,然后是 fullRelease 构建时,我遇到的错误是不同的:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/graphics/drawable/AnimatedVectorDrawableCompat$1;
和:
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
任何人都可以阐明我遇到的错误,并可能提出解决方法吗?当然,理想情况下,我更愿意将 proguard 过程合并到构建过程中。
更新:此外,从命令行运行任何 gradle 任务时,我遇到了错误:
problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
这让我相信在 AppCompat 或 Support 库的某个地方使用了 Java 8 语言功能,而我正在针对 Java 7 进行编译。
【问题讨论】:
-
这意味着您的依赖项中的一些依赖项会被添加两次,并且版本冲突。您可能想检查支持库中的 AnimatedVectorDrawableCompat 类,但也可能在其他库中
-
我认为你是对的,但我认为这是获得正确版本的支持库的问题,如果允许降级支持我们的 appcompat 库有帮助,我愿意为 API 级别 23 构建等
标签: android build.gradle android-permissions android-proguard