如何防止Proguard混淆破坏jdom.jar



我有一个项目,它使用jdom SAXBuilder在我的Android应用程序中从我的xml创建文档。

如果我只是打包我的应用程序,一切都很好,内容已经加载,没有例外。如果我使用proguard来混淆代码,我会得到以下异常:

06-22 10:07:26.210: ERROR/b(21255): Error
06-22 10:07:26.210: ERROR/b(21255): org.jdom.JDOMException: Could not load default SAX parser: org.apache.xerces.parsers.SAXParser: SAX2 driver class org.apache.xerces.parsers.SAXParser not found: org.apache.xerces.parsers.SAXParser in loader dalvik.system.PathClassLoader[/data/app/...news.activities-2.apk]
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.createParser(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.build(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.build(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at ....Utils.b.run(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at java.lang.Thread.run(Thread.java:1096)
06-22 10:07:26.210: ERROR/b(21255): Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser in loader dalvik.system.PathClassLoader[....news.activities-2.apk]
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:192)
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:183)
06-22 10:07:26.210: ERROR/b(21255):     ... 5 more
06-22 10:07:26.210: ERROR/b(21255): Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser in loader dalvik.system.PathClassLoader[/data/app/....news.activities-2.apk]
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:192)
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:183)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.createParser(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.build(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.build(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at ....Utils.b.run(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at java.lang.Thread.run(Thread.java:1096)
06-22 10:07:26.210: ERROR/b(21255): Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser in loader dalvik.system.PathClassLoader[/data/app/....news.activities-2.apk]
06-22 10:07:26.210: ERROR/b(21255):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-22 10:07:26.210: ERROR/b(21255):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-22 10:07:26.210: ERROR/b(21255):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.NewInstance.newInstance(NewInstance.java:49)
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:190)
06-22 10:07:26.210: ERROR/b(21255):     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:183)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.createParser(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.build(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at org.jdom.input.SAXBuilder.build(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at ....Utils.b.run(Unknown Source)
06-22 10:07:26.210: ERROR/b(21255):     at java.lang.Thread.run(Thread.java:1096)

引发此异常的代码是:

SAXBuilder builder = new SAXBuilder();
xmlDocument = builder.build(inputStream);

我用以下配置混淆了proguard的项目:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars ./libs/commons-compress-1.0-SNAPSHOT.jar
-libraryjars ./libs/hoptoad-android.jar
-libraryjars ./libs/httpmime-4.1.jar
-libraryjars ./libs/javabase64-1.3.1.jar
-libraryjars ./libs/jdom-1.1.1-android-fork.jar
-libraryjars ./libs/OmnitureAppMeasurement-Android.jar
-ignorewarnings
-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
-keep public class * extends ....news.activities.SuperActivity
-keep public class ....news.xmlparser.VotingParser
-keep public class ....** {
  public protected private *;
}
//my package name removed for the question only
-keep public class....** {
  public protected private *;
}
//my package name removed for the question only
-keep public class org.jdom.** {
  public protected private *;
}
-keep public class org.apache.** {
  public protected private *;
}
-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配置以允许混淆吗?

Cfr ProGuard手册>故障排除>运行时的问题>ClassNotFoundException

ProGuard不知道它必须保留类,因为它只是通过内省创建的。因此,您必须在配置中指定它:

-keep class org.apache.xerces.parsers.SAXParser

尝试使用-skipnonpubliclibraryclasses而不是-dontskipnonpubliclibraryclasses

在读取库jar时跳过非公共类,以加快处理速度并减少ProGuard的内存使用。

相关内容

  • 没有找到相关文章

最新更新