Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android L: LinkageError crashes application

As part of testing an existing Android app against the L preview, the app is crashing with the following exception:

07-08 10:05:39.024: E/AndroidRuntime(2126): FATAL EXCEPTION: main
07-08 10:05:39.024: E/AndroidRuntime(2126): Process: com.example, PID: 2126
07-08 10:05:39.024: E/AndroidRuntime(2126): java.lang.LinkageError: com.example.BaseActivity
07-08 10:05:39.024: E/AndroidRuntime(2126):     at dalvik.system.DexFile.defineClassNative(Native Method)
07-08 10:05:39.024: E/AndroidRuntime(2126):     at dalvik.system.DexFile.defineClass(DexFile.java:222)
07-08 10:05:39.024: E/AndroidRuntime(2126):     at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
07-08 10:05:39.024: E/AndroidRuntime(2126):     at dalvik.system.DexPathList.findClass(DexPathList.java:321)
07-08 10:05:39.024: E/AndroidRuntime(2126):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)

The app works fine in API levels 14-19, but crashes on start up with this cryptic error on the L preview. The compile/targetSdk version is still set to API 19.

like image 764
swanson Avatar asked Jul 08 '14 14:07

swanson


People also ask

Why application crash in Android studio?

An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java or Kotlin crashes if it throws an unhandled exception, represented by the Throwable class.

What is linkage error Java?

LinkageError indicate that a class has some dependency on another class; however, the latter class has incompatibly changed after the compilation of the former class. It is caused by a conflict between the original classloader from the JVM and the classloader deployed by the plugin framework.

How do I manually crash an app on Android?

throw new RuntimeException("This is a crash"); Make sure to remove the line after testing is done. Another way to crash an Android app is to make a DivideByZero exception. In the onCreate method of your activity, simply write an expression with a number being divided by 0.


1 Answers

The problem was a conflicting method in BaseActivity. I had created a helper method called getDrawable(int drawableId) that had the same signature as a method added to the Activity class in Android L.

This conflict caused the LinkageError. To fix the issue, I simply renamed my helper method so it wouldn't conflict with the new built-in method.

like image 66
swanson Avatar answered Sep 27 '22 18:09

swanson