Search code examples
androidandroid-5.0-lollipop

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.


Solution

  • 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.