android – Proguard给出“警告:org.msgpack.*”

使用Eclipse导出我的项目,我收到以下警告:

[2013-08-20 10:45:24 - MyProj] Proguard returned with error code 1. See console
[2013-08-20 10:45:24 - MyProj] Note: there were 3023 duplicate class deFinitions.
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CtNewConstructor
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CannotCompileException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.NotFoundException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CtNewConstructor
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BeansBuildContext: can't find referenced class javassist.CtConstructor
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtNewMethod
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CannotCompileException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.NotFoundException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtNewMethod
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtMethod
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.BuildContext: can't find referenced class javassist.CtMethod
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CtNewConstructor
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CannotCompileException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.NotFoundException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CtNewConstructor
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.DefaultBuildContext: can't find referenced class javassist.CtConstructor
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.LoaderClasspath
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.LoaderClasspath
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.NotFoundException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.Classpool
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.template.builder.JavassistTemplateBuilder: can't find referenced class javassist.CtClass
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.ToolProvider
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.DiagnosticCollector
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.DiagnosticCollector
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaCompiler
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.StandardLocation
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileManager
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileObject
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileObject
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileObject$Kind
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaCompiler
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileManager
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.ToolProvider
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaCompiler
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.StandardLocation
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileManager
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileManager$Location
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileObject
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaCompiler
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileManager
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler: can't find referenced class javax.tools.JavaFileObject$Kind
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler$1: can't find referenced class javax.tools.JavaFileObject$Kind
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler$1: can't find referenced class javax.tools.JavaFileObject$Kind
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler$1: can't find referenced class javax.tools.JavaFileObject
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.TemplatePrecompiler$1: can't find referenced class javax.tools.JavaFileObject$Kind
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.JSONParser
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.JSONParser
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.JSONParser
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.ParseException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.ParseException
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.JSONParser
[2013-08-20 10:45:24 - MyProj] Warning: org.msgpack.util.json.JSONUnpacker: can't find referenced class org.json.simple.parser.ParseException
[2013-08-20 10:45:24 - MyProj]       You should check if you need to specify additional program jars.
[2013-08-20 10:45:24 - MyProj] Warning: there were 81 unresolved references to classes or interfaces.
[2013-08-20 10:45:24 - MyProj]          You may need to specify additional library jars (using '-libraryjars').
[2013-08-20 10:45:24 - MyProj] java.io.IOException: Please correct the above warnings first.
[2013-08-20 10:45:24 - MyProj]  at proguard.Initializer.execute(Initializer.java:321)
[2013-08-20 10:45:24 - MyProj]  at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-08-20 10:45:24 - MyProj]  at proguard.ProGuard.execute(ProGuard.java:86)
[2013-08-20 10:45:24 - MyProj]  at proguard.ProGuard.main(ProGuard.java:492)

project.properties:

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-myproject.txt

# Project target.
target=Google Inc.:Google Apis:17
android.library.reference.1=../../../android/downloaded/JakeWharton-ActionBarSherlock-e5c2d1c/library
android.library.reference.2=../../../android/android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib

ProGuard的-myproject.txt:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar
-libraryjars /Users/tester/Documents/workspace/android_testing/MyProj/libs/MixpanelAPI.jar
-libraryjars /Users/tester/Documents/workspace/android_testing/MyProj/libs/Parse-1.3.2.jar      
-libraryjars /Users/tester/Documents/workspace/android_testing/MyProj/libs/TestFlightLib.jar
-libraryjars /Users/tester/Documents/workspace/android_testing/MyProj/libs/android-support-v13.jar
-libraryjars /Users/tester/Documents/android/android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar

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

-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.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

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

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

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

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

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.parse.** { *; }
-keep class com.mixpanel.** { *; }
-keep class com.testflightapp.** { *; }
-keep class org.json.simple.** { *; }

-dontwarn com.facebook.**
-dontwarn android.support.**

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

我使用的一些第三方的东西是mixpanel.com,parse.com,ActionBarSherlock(http://actionbarsherlock.com/)和TestFlightApp.com.

我确实尝试将以下内容放入我的proguard-myproject.txt中:

-dontwarn javassist.**
-dontwarn javax.tools.**
-dontwarn json.simple.parser.**

但是,如果我在启动应用程序后立即将这些应用程序中的应用程序崩溃,那么我猜我需要通过正确地包含库来清理警告.

题:

我想知道我需要在proguard-myproject.txt文件中包含哪些内容来摆脱这些警告,并且能够在我的手机上启动我的应用程序而不会在我启动应用程序后立即崩溃.如果我只是通过正常的Run ..或Debug选项从eclipse运行应用程序,该应用程序工作正常,所以我猜想Proguard正在删除我需要的一些类.

我也有dump.txt,mapping.txt,seeds.txt和usage.txt,如果有人需要看到它们,但它们相当长,所以我认为现在不需要粘贴.

解决了!

感谢@Eric Lafortune,并期待proguard documentation

主要问题是添加这个:

-keep class com.myapp.** { *; }
-keep interface com.myapp.** { *; }

其中com.myapp.**是我的应用程序的包

ProGuard的-myproject.txt:

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar
-libraryjars libs/MixpanelAPI.jar
-libraryjars libs/Parse-1.3.2.jar       
-libraryjars libs/TestFlightLib.jar
-libraryjars libs/android-support-v13.jar
-libraryjars libs/KiipSDK.jar
-libraryjars /Users/tester/Documents/android/android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar

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

-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 class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

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

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

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

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

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
#-keep class android.support.v4.app.** { *; }
#-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.parse.** { *; }
-keep class com.mixpanel.** { *; }
-keep class com.testflightapp.** { *; }
-keep class org.json.simple.** { *; }
-keep class com.myapp.** { *; }
-keep interface com.myapp.** { *; }

-dontwarn com.facebook.**
-dontwarn android.support.**
-dontwarn org.msgpack.**

解决方法:

Android SDK中的Ant / Eclipse / Gradle构建过程会自动为您指定输入jar,库jar和输出jar,因此您不能在配置中再次指定它们.这就是为什么你会收到很多关于重复类的警告.

另一方面,一些org.msgpack类依赖于不在libs目录中的类.如果您的调试版本工作正常,您可以告诉ProGuard忽略它:

-dontwarn org.msgpack.**

如果您的应用程序崩溃,您应该查看logcat输出.您可以在ProGuard手册的Troubleshooting部分找到建议.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...