gpt4 book ai didi

Android - Proguard 重复 zip 条目错误 - Android 支持库

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:32 24 4
gpt4 key购买 nike

我正在尝试在使用 android 库项目android 应用程序 中使用 Proguard。 我的核心 android 项目依赖于两个 android 库项目。核心和库项目依赖于 android 支持库(在我的例子中:android-support-v4.jar)。 当我尝试使用 ProGuard 对其进行混淆时,我总是会收到以下错误(如果 Gradle 脚本中禁用了 Proguarg,则编译工作正常。):

:MYANDROIDPROJECT:proguardDemoRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MYANDROIDPROJECT:proguardDemoRelease'.
> java.io.IOException: Can't write [MYANDROIDPROJECT_PATH\build\intermediates\classes-proguard\demo\release\classes.jar] (Can't read [MYANDROIDPROJECT_PATH\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\classes.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [classes.jar:android/support/v4/graphics/drawable/DrawableCompat$HoneycombDrawableImpl.class]))

我的核心项目的 Gradle 构建脚本:

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.12.2+'
}
}

apply plugin: 'android'

android {
buildToolsVersion "19.1.0"
compileSdkVersion 19

lintOptions {
abortOnError false
}

signingConfigs {
localks {
storeFile file("keystore/keystore")
storePassword "xx"
keyAlias "xx"
keyPassword "xx"
}
}

buildTypes {
debug {
debuggable true
runProguard false
zipAlign true
signingConfig signingConfigs.localks
}

release {
debuggable false
zipAlign true
proguardFile 'proguard.txt'
runProguard true
signingConfig signingConfigs.localks
}
}

defaultConfig {
minSdkVersion 14
targetSdkVersion 19
ndk{
moduleName "S3DClient"
abiFilter "armeabi-v7a"
stl "gnustl_static"
}
}

sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
jni.srcDirs = []
}
paid {
manifest.srcFile 'src/paid/AndroidManifest.xml'
java.srcDirs = ['src/paid/java']
res.srcDirs = ['src/paid/res']

jni.srcDirs = []
}
demo {
manifest.srcFile 'src/demo/AndroidManifest.xml'
java.srcDirs = ['src/demo/java']
res.srcDirs = ['src/demo/res']

jni.srcDirs = []
}
}

productFlavors {
paid {
applicationId = "hu.myprojectpackage1"
}
demo {
applicationId = "hu.myprojectpackage2"
}
}
}

dependencies {
compile files('src/main/libs/sqliteassethelper-2.0.1.jar',
'src/main/libs/S3DXAndroidTools.jar',
'src/main/libs/roboguice-2.0.jar',
'src/main/libs/open-javageom.jar',
'src/main/libs/openawt.geom.jar',
'src/main/libs/libGoogleAnalyticsServices.jar',
'src/main/libs/javax.inject-1.jar',
'src/main/libs/guice-3.0-no_aop.jar',
'src/main/libs/commons-lang3-3.1.jar',
'src/main/libs/bugsense-3.6.jar')
compile fileTree(dir: "$buildDir/native-libs", include: '*.jar')

compile 'com.android.support:support-v4:21.0.+'

compile project(":lib/SlidingLayer")

compile project(':lib/BlutoothCommunicationHandler')
paidCompile project(':lib/Licencing')
}

库项目之一的 Gradle 构建脚本:

apply plugin: 'android-library'

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.12.2+'
}
}
dependencies {
compile "com.android.support:support-v4:19.0.+"
}

android {
buildToolsVersion "19.1.0"
compileSdkVersion 19

defaultConfig {
minSdkVersion 4
targetSdkVersion 18
}
dexOptions {
preDexLibraries = false
}

lintOptions {
abortOnError false
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}

ProGuard 配置的(相关部分)是:

-libraryjars src/main/libs/android-support-v4.jar

-keep class android.** { *; }
-keep class android.support** { *; }

-dontnote
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-dontwarn org.openawt.**
-dontwarn android.support.**

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-assumenosideeffects class android.util.Log {
public static *** e(...);
public static *** w(...);
public static *** wtf(...);
public static *** d(...);
public static *** v(...);
}
-keepattributes Signature
-keepattributes *Annotation*

最佳答案

主项目build.gradle:

花一些时间来转换这些本地 jar:

dependencies {
compile files('src/main/libs/sqliteassethelper-2.0.1.jar',
'src/main/libs/S3DXAndroidTools.jar',
'src/main/libs/roboguice-2.0.jar',
'src/main/libs/open-javageom.jar',
'src/main/libs/openawt.geom.jar',
'src/main/libs/libGoogleAnalyticsServices.jar',
'src/main/libs/javax.inject-1.jar',
'src/main/libs/guice-3.0-no_aop.jar',
'src/main/libs/commons-lang3-3.1.jar',
'src/main/libs/bugsense-3.6.jar')
compile fileTree(dir: "$buildDir/native-libs", include: '*.jar')

compile 'com.android.support:support-v4:21.0.+'

compile project(":lib/SlidingLayer")

compile project(':lib/BlutoothCommunicationHandler')
paidCompile project(':lib/Licencing')
}

对于可以轻松管理的 Maven 依赖项(我试图为您找到其中的大部分!):

dependencies {
// compile fileTree(dir: 'libs', include: '*.jar') // all others
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
compile file('src/main/libs/S3DXAndroidTools.jar')
compile 'org.roboguice:roboguice:2.0' // latest is 3.0.1
compile 'com.google.android.gms:play-services:6.1.71' // latest is 6.8.57 (issues)
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'com.bugsense.trace:bugsense:3.6'
compile fileTree(dir: "$buildDir/native-libs", include: '*.jar')
compile 'com.android.support:support-v4:21.0.3'
compile project(":lib/SlidingLayer")
compile project(':lib/BlutoothCommunicationHandler')
paidCompile project(':lib/Licencing')
}

在那之后,你应该可以使用android.packagingOptions:

    packagingOptions {
exclude '.readme'
exclude 'LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/README.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}

库项目build.gradle

您的库项目需要更改为:

dependencies {
compile "com.android.support:support-v4:19.0.+"
}

到:

dependencies {
compile 'com.android.support:support-v4:21.0.3'
}

您的主要问题是您有两个不同的 com.android.support:support-v4,一个在您的库项目中,一个在您的主项目中。

关于Android - Proguard 重复 zip 条目错误 - Android 支持库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28510177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com