Android:配置Proguard

时间:2013-05-07 13:35:53

标签: android proguard

我正在尝试配置proguard并面临一些按优先级排序的问题:

  • 我收到了重复拉链的警告,无法修复。 我在“libs”目录中使用外部库和2个库项目(一个库项目有一个外部库 - 只添加到项目一次),它们只添加到项目一次。我试图将我的外部罐子移动到另一个目录,即“lib” - 只是重命名,因为有些用户已设法解决它,但它对我没有帮助。另一种方法是尝试将custom_rules实现到基本build.xml,因为它可以帮助一些用户避免这些警告。但是它的一切对我没有帮助,我该如何解决呢?经度:

    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-annotations-2.1.4.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-v4.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [google-analytics-v2.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-core-2.1.4.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [httpclientandroidlib-1.1.2.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [deviceprint-lib-1.0.0.jar:META-INF/MANIFEST.MF])
    
  • 最后一件事是签名的apk建设中的一些注意事项:

    ProGuard: Note: com.google.analytics.tracking.android.AdHitIdGenerator: can't find dynamically referenced class com.google.ads.AdRequest
    ProGuard: Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
    ProGuard: Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
    

完整的proguard文件:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

# Otherwise return Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn com.fasterxml.jackson.databind.**

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

# Preserve all fundamental application classes.
-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.view.View
-keep public class * extends android.preference.Preference
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

# Preserve ActionBarSherlock and Android support libraries` classes and interfaces
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }

# Preserve all Jackson library classes
-keep class com.fasterxml.jackson.** { *; }

# Original
-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
  public static <fields>;
}

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

#To remove debug logs:
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}

2 个答案:

答案 0 :(得分:5)

Stackoverflow中讨论了类似的问题:

Android Proguard Duplicate Definition

Duplicate resources when using ProGuard and an Android application

Android - Proguard duplicate zip entry error

在你的情况下,我认为第一个可以帮助你......

如果这没有帮助,我们应该从这个问题的位置看看。我甚至在playstore上有一些应用程序和第三方库,我对proguard没有任何问题。以下是我的一个appuard.cfg设置,其中包含第三方lib和google lvl许可:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn **CompatHoneycomb
-keep class android.support.v4.** { *; }
-dontwarn org.apache.**
-verbose
-dontoptimize
-dontshrink
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-dontwarn com.google.ads.**

好吧,你不需要它们,这取决于你实现的内容或你使用的第三方库。所以,我看不到你的app结构并且没有代码,这将超出范围。我建议您逐个测试。

答案 1 :(得分:5)

您目前列出的6个警告和3个注释是无害的。

您应该确保使用最新版本的Android SDK,这会为您的项目创建一个空的proguard-project.txt。标准的Ant构建和Eclipse构建在内部处理重要的配置(我假设你正在使用IDEA的Ant)。您仍然可以向proguard-project.txt添加特定于应用程序的选项,例如Jackson和ActionBarSherlock的-keep选项。不要添加像-injars / -libraryjars / -outjars这样的选项,因为构建过程会为您指定它们。