Search code examples
javaandroidin-app-billingandroid-billing

Obscure bug java.lang.NoClassDefFoundError when app starts


After adding one lib I had the same error as Unable to execute dex: method ID not in [0, 0xffff]: 65536

I did use Android Studio 0.8.14, updated it to 1.0 RC2 (latest on 2 december 2014), added multiDexEnabled = true, all right, project building good. In this app i have billing. I am run my app on device (tried on emulator and real device, result the same) and i see this exception:

java.lang.NoClassDefFoundError: <mypackagename>.util.IabHelper$1
            at <mypackagename>.util.IabHelper.startSetup(IabHelper.java:210)
            at <mypackagename>.ParentActivity.onCreate(ParentActivity.java:159)
            at <mypackagename>.SplashScreenActivity.onCreate(SplashScreenActivity.java:60)
            at android.app.Activity.performCreate(Activity.java:4494)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1940)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2001)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1163)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4444)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
            at dalvik.system.NativeStart.main(Native Method)

IabHelper - is class provided by Google for easy implementing in-app building. This is 210 string of this class:

mServiceConn = new ServiceConnection() {

    @Override
    public void onServiceDisconnected(ComponentName name) {
        ...
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        ...
    }
};

When i am used Android studio 0.8.14 this worked great, this problem appeared only after update. I cannot downgrade because i will get "execute dex" error. Any ideas how to fix this? I am really confused...

Update: i am tried to remove billing functional, on start app throws NoClassDefFoundError to any class declared in project... maybe i am missed something when migrate to new gradle tool version?


Solution

  • Finally i found... "crutch" (i am just don't know what word to use in this definition)

    This post http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/ really helped me: i am downloaded android studio 0.8.14, added com.android.support:multidex dependency to build file and followed "The cure" instructions of last post.

    PS: yes, it works, but it's not really solution for this problem, i think. In general i am still don't know what exactly problem was there.