X
Let's get in touch

Weird Runtime Error after upgrading Android Development Tools to version 22

If you upgraded ADT to version 22 you probably experienced a weird runtime exception when trying to run/debug existing Android projects that reference Android library projects or that contains external libraries in the classpath. Most of our existing applications crashed immediately with weird logcat message which said the main activity can not be instantiated?!

The logcat message looked like this:

6-13 09:55:27.380: E/AndroidRuntime(6742): FATAL EXCEPTION: main
06-13 09:55:27.380: E/AndroidRuntime(6742): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{io.hungr/io.hungr.activity.RestaurantsActivity}: java.lang.ClassNotFoundException: Didn't find class "io.hungr.activity.RestaurantsActivity" on path: /data/app/io.hungr-1.apk
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.os.Handler.dispatchMessage(Handler.java:99)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.os.Looper.loop(Looper.java:137)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-13 09:55:27.380: E/AndroidRuntime(6742): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 09:55:27.380: E/AndroidRuntime(6742): at java.lang.reflect.Method.invoke(Method.java:511)
06-13 09:55:27.380: E/AndroidRuntime(6742): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-13 09:55:27.380: E/AndroidRuntime(6742): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-13 09:55:27.380: E/AndroidRuntime(6742): at dalvik.system.NativeStart.main(Native Method)
06-13 09:55:27.380: E/AndroidRuntime(6742): Caused by: java.lang.ClassNotFoundException: Didn't find class "io.hungr.activity.RestaurantsActivity" on path: /data/app/io.hungr-1.apk
06-13 09:55:27.380: E/AndroidRuntime(6742): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
06-13 09:55:27.380: E/AndroidRuntime(6742): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-13 09:55:27.380: E/AndroidRuntime(6742): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
06-13 09:55:27.380: E/AndroidRuntime(6742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
06-13 09:55:27.380: E/AndroidRuntime(6742): ... 11 more

Weird message, considering this is the main activity of the application, which is declared in the manifest file and there were no changes in the codebase after the ADT upgrade.

After few hours of googling I found out that there are some changes in the way ADT handles private libraries included in an application (the libraries located in libs folder of the application). At first I thought that ADT introduced new classpath container named “Android Private Libraries” but afterwords realized that it is the same container used in version 21 (com.android.ide.eclipse.adt.LIBRARIES) just with a different display name. In previous versions of ADT the same container was displayed under the name “Android Dependencies”.  After the upgrade to ADT v22, Java build path editor shows two android-related classpath containers:

  • Android Private Libraries (com.android.ide.eclipse.adt.LIBRARIES) – As I mentioned before Android Private Libraries is a container that will automatically include all .jar files from /libs folder into the project’s classpath.
  • Android Dependencies (com.android.ide.eclipse.adt.DEPENDENCIES) – This container is responsible for including all .jar files generated from all referenced Android library projects.

In previous versions of ADT both the .jar files from /libs folder and .jar files from referenced Android library projects were included in the same container (com.android.ide.eclipse.adt.LIBRARIES). This is the only change that I can spot in the project configuration after updating to ADT 22 and can not explain why this change causes application crash. But something in build process obviously changed… I can only guess that changes are somehow related to migration to new gradle-based build system.

To make the long story short, a simple change in classpath configuration fixed the problem and that was to mark  “Android Private Libraries” container to be exported. Also, if your project references other Android library projects which reference private libraries, you should edit each project’s classpath the same way.

Leave your comment

We use cookies to help us optimize the website experience. Okay

Learn more about our privacy policy.