Android项目用ProGuard混淆后报错:NoSuchMethodError的错误
各位高人,小弟有一个项目不混淆运行正常(环境是:Eclipse, Android 2.3.3),如何解决该问题,请高手赐教,多谢!用ProGuard混淆后运行报错如下:
java.lang.NoSuchMethodError:android.util.Xml.newSerializer
at com.abcsoft.abc.a(UnKnown Source)
at ...
在 com.abcsoft.abc.a 类中的代码:
public boolean createConfigXmlFile(String webURL,int iAisID,String strAisName,String strAisPosition,int iUserID,String strUserName,String strPassword )
{
File linceseFile = new File(K3ConfigFile_PATH);
//如果已存在,则先删除
if(linceseFile.exists())
{
linceseFile.delete();
}
try{
linceseFile.createNewFile();
FileOutputStream fileos = null;
fileos = new FileOutputStream(linceseFile);
// 混淆后,运行到这句报错,Xml 是 android.util中的类 newSerializer方法的修饰符是:public static
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(fileos,"UTF-8");
serializer.startDocument(null, true);
....
serializer.endDocument();
serializer.flush();
fileos.close();
return true;
}
catch (FileNotFoundException e) {
Log.e("FileNotFoundException", "can't create FileOutputStream");
return false;
}
catch (IOException e) {
Log.e("IOException", "exception in createConfigXmlFile() method");
return false;
}
catch (Exception e) {
Log.e("Exception","error occurred while creating xml file");
return false;
}
}
我的ProGuard.cfg 的内容如下:
-injars bin/classes
-injars lib
-outjars bin/classes-processed.jar
-libraryjars C:\\android-sdk\\platforms\\android-10\\android.jar
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontoptimize
-verbose
-dontwarn
-dontskipnonpubliclibraryclassmembers
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class android.** { public protected private *; }
-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
-keepclasseswithmembernames class * {
native <methods>;
}
-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.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
--------------------编程问答-------------------- 自已顶 --------------------编程问答-------------------- 解决没啊 --------------------编程问答-------------------- 也遇到了同样的问题,解决没有啊?求帮助啊 --------------------编程问答-------------------- lz可以这样,将编译后的程序反解,然后再到相应的类里面查看该method是否存在,如果不存在证明就是被proguard干掉了。 --------------------编程问答-------------------- 我也遇到这个问题,求解 --------------------编程问答-------------------- LZ是否有引用其他的jar包,并且这些jar包包含了org.xmlpull.v1.XmlSerializer这个类,如果有就会和android自带的org.xmlpull.v1.XmlSerializer冲突,因此把这个jar包的org.xmlpull.v1.XmlSerializer类过滤掉,应该就可以了。 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 疾风胫甲北京开笔记本肩并肩禾本科可好看客户看看拉黑客户可难看客户可能客户可能客户夫妇 --------------------编程问答-------------------- --------------------编程问答-------------------- 看样子是 XmlSerializer的构造函数被混淆掉了
-keep public class android.util.Xml.newSerializer {
protected <methods>;
public <methods>;
public static <methods>;
}
强制keep下试试
--------------------编程问答-------------------- lz解决了吗?类似的问题
补充:移动开发 , Android