我正在尝试在 Android应用程序中使用 Proguard ,它使用 android库项目。 我的核心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*
答案 0 :(得分:7)
build.gradle
:花一些时间来转换这些本地罐子:
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
,一个在您的图书馆项目中,一个在您的主项目中。