0

问题:我有 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
4

1 回答 1

1

需要将该Parcelable类添加到您的proguard-project.txt文件中,然后在项目上再次运行 proguard。

例如,您可能希望在文件中添加类似以下内容,当然替换为您的proguard-project.txt的完全限定名称:

-keep public class com.example.MyParcelableClass
于 2013-07-02T23:50:59.947 回答