开发者

How to prevent the Proguard obfuscation from destroying jdom.jar

I have a project that uses the jdom SAXBuilder to create a Document from my xml in my Android App.

If I just package my App everything works fine, the content is loaded and there are no exceptions. If I use proguard to obfuscate the code I get the following exception:

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.in开发者_Go百科put.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)

The code that throws this exception is:

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

I obfuscate the project with proguard with the following configuration:

-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 *;
}

Any ideas how to change my proguard configuration to allow an obfuscation?


Cfr ProGuard manual > Troubleshooting > Problems at run-time > ClassNotFoundException

ProGuard doesn't know it has to keep the class, because it is only created by introspection. You therefore have to specify it in your configuration:

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


Try with -skipnonpubliclibraryclasses instead of -dontskipnonpubliclibraryclasses

to skip non-public classes while reading library jars, to speed up processing and reduce memory usage of ProGuard.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜