After updating ADT to 22.3, sometimes APKs can be signed, but throws ClassNotFoundException
when testing, as exemplified below (it seems to always affect the class extending Application
):
12-19 16:32:04.374: E/AndroidRuntime(25074): FATAL EXCEPTION: main
12-19 16:32:04.374: E/AndroidRuntime(25074): java.lang.RuntimeException: Unable to instantiate application com.innostreams.vieshow.ApplicationSettings: java.lang.ClassNotFoundException: com.innostreams.vieshow.ApplicationSettings
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4201)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.ActivityThread.access$1300(ActivityThread.java:140)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.os.Handler.dispatchMessage(Handler.java:99)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.os.Looper.loop(Looper.java:137)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-19 16:32:04.374: E/AndroidRuntime(25074): at java.lang.reflect.Method.invokeNative(Native Method)
12-19 16:32:04.374: E/AndroidRuntime(25074): at java.lang.reflect.Method.invoke(Method.java:511)
12-19 16:32:04.374: E/AndroidRuntime(25074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-19 16:32:04.374: E/AndroidRuntime(25074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-19 16:32:04.374: E/AndroidRuntime(25074): at dalvik.system.NativeStart.main(Native Method)
12-19 16:32:04.374: E/AndroidRuntime(25074): Caused by: java.lang.ClassNotFoundException: com.innostreams.vieshow.ApplicationSettings
12-19 16:32:04.374: E/AndroidRuntime(25074): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-19 16:32:04.374: E/AndroidRuntime(25074): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-19 16:32:04.374: E/AndroidRuntime(25074): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.Instrumentation.newApplication(Instrumentation.java:971)
12-19 16:32:04.374: E/AndroidRuntime(25074): at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
12-19 16:32:04.374: E/AndroidRuntime(25074): ... 11 more
When this is encountered, generating another signed APK would usually solve the problem and the APK can then be installed an run without issues. No code was changed between the two signed APK builds, and project need not be cleaned, all it took to create a "correct" signed APK was to export a signed APK (righ click project->Android Tools->Export signed application package...), so this couldn't be an issue with the code nor the project setup. What I wish to know is:
- Why is this happening
- How do I fix it once and for all
Edit: Please note that the application never encounters the above issue when "unsigned" (aka signed with debug certificate) version is installed and ran.