android-android怎么实现只混淆自己的代码,而不混淆第3方jar.201

 我来答
huanglenzhi
2015-06-21 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517174
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
  为了解决第三方包不被混淆,第三方包在混淆后,运行的时候会挂掉。我的错误是java.lang.ExceptionInInitializerError

[java] E/AndroidRuntime( 9608):
java.lang.ExceptionInInitializerError
E/AndroidRuntime( 9608): at
a.a.b.f.<init>(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.b.e.<init>(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.dg.b(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.dg.a(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.b.a(Unknown Source)
E/AndroidRuntime( 9608): at
a.a.c.ad.a(Unknown Source)

  ………………………………………………………………………………中间部分省略
  最终我通过 加LOG的调试方法定位到是由于第三方jar包被混淆后的原因导致的。

  解决方法:
  在proguard-android.txt文件最后加入了-keep class org.jsoup.**这样一句代码,就是保持这个类不被混淆

  附上proguard-android.txt源文件

  

  [html] # This is a configuration file for ProGuard.
  # http://proguard.sourceforge.net/index.html#manual/usage.html
  
  -dontusemixedcaseclassnames
  -dontskipnonpubliclibraryclasses
  -verbose
  
  # Optimization is turned off by default. Dex does not like code run
  # through the ProGuard optimize and preverify steps (and performs some
  # of these optimizations on its own).
  -dontoptimize
  -dontpreverify
  # Note that if you want to enable optimization, you cannot just
  # include optimization flags in your own project configuration file;
  # instead you will need to point to the
  # "proguard-android-optimize.txt" file instead of this one from your
  # project.properties file.
  
  -keepattributes *Annotation*
  -keep public class com.google.vending.licensing.ILicensingService
  -keep public class com.android.vending.licensing.ILicensingService
  
  # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
  -keepclasseswithmembernames class * {
  native <methods>;
  }
  
  # keep setters in Views so that animations can still work.
  # see http://proguard.sourceforge.net/manual/examples.html#beans
  -keepclassmembers public class * extends android.view.View {
  void set*(***);
  *** get*();
  }
  
  # We want to keep methods in Activity that could be used in the XML attribute onClick
  -keepclassmembers class * extends android.app.Activity {
  public void *(android.view.View);
  }
  
  # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
  -keepclassmembers enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
  }
  
  -keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
  }
  
  -keepclassmembers class **.R$* {
  public static <fields>;
  }
  
  # The support library contains references to newer platform versions.
  # Don't warn about those in case this app is linking against an older
  # platform version. We know about them, and they are safe.
  -dontwarn android.support.**
  
  -keep class org.jsoup.**

  # This is a configuration file for ProGuard.
  # http://proguard.sourceforge.net/index.html#manual/usage.html

  -dontusemixedcaseclassnames
  -dontskipnonpubliclibraryclasses
  -verbose

  # Optimization is turned off by default. Dex does not like code run
  # through the ProGuard optimize and preverify steps (and performs some
  # of these optimizations on its own).
  -dontoptimize
  -dontpreverify
  # Note that if you want to enable optimization, you cannot just
  # include optimization flags in your own project configuration file;
  # instead you will need to point to the
  # "proguard-android-optimize.txt" file instead of this one from your
  # project.properties file.

  -keepattributes *Annotation*
  -keep public class com.google.vending.licensing.ILicensingService
  -keep public class com.android.vending.licensing.ILicensingService

  # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
  -keepclasseswithmembernames class * {
  native <methods>;
  }

  # keep setters in Views so that animations can still work.
  # see http://proguard.sourceforge.net/manual/examples.html#beans
  -keepclassmembers public class * extends android.view.View {
  void set*(***);
  *** get*();
  }

  # We want to keep methods in Activity that could be used in the XML attribute onClick
  -keepclassmembers class * extends android.app.Activity {
  public void *(android.view.View);
  }

  # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
  -keepclassmembers enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
  }

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

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

  # The support library contains references to newer platform versions.
  # Don't warn about those in case this app is linking against an older
  # platform version. We know about them, and they are safe.
  -dontwarn android.support.**

  -keep class org.jsoup.**
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式