我有一個項目使用jdom SAXBuilder在我的Android應用程序中從我的xml創建文檔。如何防止Proguard混淆破壞jdom.jar
如果我只是打包我的應用程序一切正常,內容被加載,並沒有例外。如果我使用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配置,以允許混淆?
此答案解決了我的問題,這與原始問題類似。 – raider33