我有一个项目A,它使用项目B作为库项目。它们都使用android-support-v4.jar作为参考库。当我试图用安卓SDK提供的ant脚本构建项目A时,我在模糊步骤中出现了以下错误:
[proguard] Preparing output jar [E:WorkspaceGuosenAndroid1.1binproguardobfuscated.jar]
[proguard] Copying resources from program jar [E:WorkspaceGuosenAndroid1.1binproguardoriginal.jar]
[proguard] Copying resources from program jar [E:WorkspaceGuosenAndroid1.1libsandroid-support-v4.jar]
[proguard] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-v4.jar:META-INF/MANIFEST.MF])
[proguard] Copying resources from program jar [E:Workspacecom_viewpagerindicatorbinclasses.jar]
[proguard] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
[proguard] Copying resources from program jar [E:Workspacecom_viewpagerindicatorlibsandroid-support-v4.jar]
[proguard] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-v4.jar:META-INF/MANIFEST.MF])
生成失败E: \Workspace\GuosenAndroid1.1\basicbuild.xml:723:无法写入[E:\Workspace\GuosenAndroid1.1\bin\proguard\fuzzed.jar](无法读取[E:\Workspace \com_viewpagerindicator \libs\android-support-v4.jar](重复的zip条目[android-support-v4.jar:android/support/v4/content/ModernAsyncTask$WorkerRunable.class])
这是我的proguard配置:
-libraryjars libs/android-support-v4.jar
-dontwarn android.support.v4.**
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep class android.support.** { *; }
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
以下是使用Proguard执行模糊步骤的ant脚本:
<target name="-obfuscate">
<echo>proguard enabled: ${proguard.enabled}</echo>
<if condition="${proguard.enabled}">
<then>
<property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" />
<property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" />
<property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" />
<!-- input for dex will be proguard's output -->
<property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" />
<!-- Add Proguard Tasks -->
<property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" />
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
<!-- Set the android classpath Path object into a single property. It'll be
all the jar files separated by a platform path-separator.
Each path must be quoted if it contains spaces.
-->
<pathconvert property="android.libraryjars" refid="android.target.classpath">
<firstmatchmapper>
<regexpmapper from='^([^ ]*)( .*)$$' to='"12"'/>
<identitymapper/>
</firstmatchmapper>
</pathconvert>
<!-- Build a path object with all the jar files that must be obfuscated.
This include the project compiled source code and any 3rd party jar
files. -->
<path id="project.jars.ref">
<pathelement location="${preobfuscate.jar.file}" />
<path refid="jar.libs.ref" />
</path>
<!-- Set the project jar files Path object into a single property. It'll be
all the jar files separated by a platform path-separator.
Each path must be quoted if it contains spaces.
-->
<pathconvert property="project.jars" refid="project.jars.ref">
<firstmatchmapper>
<regexpmapper from='^([^ ]*)( .*)$$' to='"12"'/>
<identitymapper/>
</firstmatchmapper>
</pathconvert>
<mkdir dir="${obfuscate.absolute.dir}" />
<delete file="${preobfuscate.jar.file}"/>
<delete file="${obfuscated.jar.file}"/>
<jar basedir="${out.classes.absolute.dir}"
destfile="${preobfuscate.jar.file}" />
<proguard>
@${proguard.config}
-injars ${project.jars}
-outjars "${obfuscated.jar.file}"
-libraryjars ${android.libraryjars}
-dump "${obfuscate.absolute.dir}/dump.txt"
-printseeds "${obfuscate.absolute.dir}/seeds.txt"
-printusage "${obfuscate.absolute.dir}/usage.txt"
-printmapping "${obfuscate.absolute.dir}/mapping.txt"
</proguard>
</then>
</if>
我应该怎么做才能消除这个错误?谢谢
android-support-v4.jar
被包含在Proguard正在优化的代码集中两次,这是不允许的。你有两个地方包括android支持jar吗?这就是您的错误消息中的真实情况。我认为你漏掉了一行,上面写着其他事件在你的项目中的位置。
我刚刚解决了一个类似的问题。我使用的是viewpagerindicator库,它对android支持库v4有依赖关系,我也使用android appcompat,它有同样的依赖关系。
因此,我从Gradle中的viewpagerindicator中排除了支持库依赖项,如下所示:
compile ('fr.avianey.com.viewpagerindicator:library:2.4.1') {
// exclude redundant transitive dependency
exclude (group: 'com.google.android', module: 'support-v4')
}