问题:我有2个应用程序。通过广播互相互动。我在android库中有parcelable类(它们在库中发送类的内容)。所以在使用Proguard后我得到了ClassNotFondException。怎么解决?
07-03 02:13:51.832: E/AndroidRuntime(6801): FATAL EXCEPTION: main
07-03 02:13:51.832: E/AndroidRuntime(6801): java.lang.RuntimeException: Unable to start receiver <appname>.<name>.ar.free.BRMain: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = <appname>.a.a.b)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2277)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.app.ActivityThread.access$1500(ActivityThread.java:140)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Looper.loop(Looper.java:137)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 02:13:51.832: E/AndroidRuntime(6801): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-03 02:13:51.832: E/AndroidRuntime(6801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-03 02:13:51.832: E/AndroidRuntime(6801): at dalvik.system.NativeStart.main(Native Method)
07-03 02:13:51.832: E/AndroidRuntime(6801): Caused by: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = <appname>.a.a.b)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Parcel.readSerializable(Parcel.java:2148)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Parcel.readValue(Parcel.java:2016)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Parcel.readMapInternal(Parcel.java:2226)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Bundle.unparcel(Bundle.java:223)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Bundle.getInt(Bundle.java:922)
07-03 02:13:51.832: E/AndroidRuntime(6801): at <appname>.<name>.ar.free.BRMain.onReceive(BRMain.java:35)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2270)
07-03 02:13:51.832: E/AndroidRuntime(6801): ... 10 more
07-03 02:13:51.832: E/AndroidRuntime(6801): Caused by: java.lang.ClassNotFoundException: <appname>.a.a.b
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.lang.Class.classForName(Native Method)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.lang.Class.forName(Class.java:217)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2301)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1660)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1803)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
07-03 02:13:51.832: E/AndroidRuntime(6801): at android.os.Parcel.readSerializable(Parcel.java:2142)
07-03 02:13:51.832: E/AndroidRuntime(6801): ... 16 more
07-03 02:13:51.832: E/AndroidRuntime(6801): Caused by: java.lang.NoClassDefFoundError: <appname>/a/a/b
07-03 02:13:51.832: E/AndroidRuntime(6801): ... 26 more
07-03 02:13:51.832: E/AndroidRuntime(6801): Caused by: java.lang.ClassNotFoundException: <appname>.a.a.b
07-03 02:13:51.832: E/AndroidRuntime(6801): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-03 02:13:51.832: E/AndroidRuntime(6801): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-03 02:13:51.832: E/AndroidRuntime(6801): ... 26 more
答案 0 :(得分:1)
需要将Parcelable
类添加到您的proguard-project.txt
文件中,然后再在项目上再次运行。
例如,您希望在proguard-project.txt
文件中添加以下内容,当然要替换您的类的完全限定名称:
-keep public class com.example.MyParcelableClass