FATAL EXCEPTION: main java.lang.NoClassDefFoundError: org.andengine.engine.options.SoundOptions

1.1k views Asked by At

I had an existing andengine project in eclipse which I migrated to Android Studio. The gradle shows no errors and I am able to successfully build the apk. But whenever I open/run the apk on my phone it crashes at the start with the mentioned error. I have tried a lot of random things by reading here and there but haven't been able to understand the issue.

Below is the detailed error I am getting from the logcat. There is line I can notice is FATAL EXCEPTION: main java.lang.NoClassDefFoundError: org.andengine.engine.options.SoundOptions

So somehow andengine is not finding the SoundOptions and some other classes at runtime.

This is my code of onCreateEngineOptions where it is showing the crash. Do let me know if you need anything else from my side.

@Override
    public EngineOptions onCreateEngineOptions() {
        abc();
        prefs = this.getSharedPreferences(
                "MY_PACKAGE", Context.MODE_PRIVATE);
        camera = new FollowCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        EngineOptions engineOption = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), camera);
        engineOption.getAudioOptions().setNeedsMusic(true);
        engineOption.getAudioOptions().setNeedsSound(true);
        engineOption.getRenderOptions().getConfigChooserOptions().setRequestedMultiSampling(true);
        engineOption.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
        engineOption.getTouchOptions().setNeedsMultiTouch(true);
        return engineOption;
    }

Here is my build.gradle(module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        applicationId "MY_PACKAGE"
        minSdkVersion 9
        targetSdkVersion 22
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }
    productFlavors {
    }
}
repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile project(':BaseGameUtils')
    compile project(':facebook')
    compile project(':AndEngine')
    compile project(':andEnginePhysicsBox2D')
}

Logs :

06-18 16:22:03.761  14042-14042/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
06-18 16:22:03.771  14042-14042/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
06-18 16:22:05.453    4974-4974/? E/dalvikvm﹕ Could not find class 'android.app.Notification$Action$Builder', referenced from method b.a
06-18 16:22:05.623    4974-4974/? E/dalvikvm﹕ Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method b.a
06-18 16:22:06.033    4974-4974/? E/dalvikvm﹕ Could not find class 'android.app.Notification$Action$Builder', referenced from method b.a
06-18 16:22:06.133    4974-4974/? E/dalvikvm﹕ Could not find class 'android.transition.Transition', referenced from method b.a
06-18 16:22:06.133    4974-4974/? E/dalvikvm﹕ Could not find class 'android.transition.Transition', referenced from method b.a
06-18 16:22:06.143    4974-4974/? E/dalvikvm﹕ Could not find class 'android.transition.Transition', referenced from method b.a
06-18 16:22:06.334    4974-4974/? E/dalvikvm﹕ Could not find class 'android.app.RemoteInput[]', referenced from method b.a
06-18 16:22:06.394    4974-4974/? E/dalvikvm﹕ Could not find class 'android.transition.Transition', referenced from method b.b
06-18 16:22:14.932    5041-5148/MY_PACKAGE E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
06-18 16:22:14.962    5041-5148/MY_PACKAGE E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
06-18 16:22:15.022    5041-5148/MY_PACKAGE E/dalvikvm﹕ Could not find class 'com.google.android.gms.ads.identifier.AdvertisingIdClient$zza', referenced from method com.google.android.gms.ads.identifier.AdvertisingIdClient.zzaJ
06-18 16:22:15.052    5041-5148/MY_PACKAGE E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
06-18 16:22:15.282    5041-5041/MY_PACKAGE E/dalvikvm﹕ Could not find class 'org.andengine.engine.handler.UpdateHandlerList', referenced from method org.andengine.engine.camera.Camera.allocateUpdateHandlers
06-18 16:22:15.613    5041-5041/MY_PACKAGE E/dalvikvm﹕ Could not find class 'org.andengine.engine.options.SoundOptions', referenced from method org.andengine.engine.options.AudioOptions.<init>
06-18 16:22:15.793    5041-5041/MY_PACKAGE E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: org.andengine.engine.options.SoundOptions
            at org.andengine.engine.options.AudioOptions.<init>(AudioOptions.java:18)
            at org.andengine.engine.options.EngineOptions.<init>(EngineOptions.java:32)
            at MY_PACKAGE.GameActivity.onCreateEngineOptions(GameActivity.java:209)
            at org.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:82)
            at MY_PACKAGE.GameActivity.onCreate(GameActivity.java:289)
            at android.app.Activity.performCreate(Activity.java:4538)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
            at android.app.ActivityThread.access$600(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:156)
            at android.app.ActivityThread.main(ActivityThread.java:4987)
            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:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
06-18 16:22:15.843    1601-5647/? E/EmbeddedLogger﹕ App crashed! Process: MY_PACKAGE
06-18 16:22:15.843    1601-5647/? E/EmbeddedLogger﹕ App crashed! Package: MY_PACKAGE v1 (1.0)
06-18 16:22:15.843    1601-5647/? E/EmbeddedLogger﹕ Application Label: MY_APP_LABEL
2

There are 2 answers

5
Abhishek V On BEST ANSWER

Has your project reached 65k+ methods (dex limit)? You seem to have enabled multidex in build.gradle. But doing so is not enough to support the multidex, you need to extend MultidexApplication in your Application class.

public class YourApplication extends MultiDexApplication {

.

.

Also you need to specify dependency on multidex lib in build.gradle

compile 'com.android.support:multidex:1.0.0'

Have you done this?

For more info you can refer this doc https://developer.android.com/tools/building/multidex.html

3
webo80 On

The problem may be coming from the multiDex function. Disable it, and try to reduce the amount of methods on your project. Google Play Services have got a lot of them, you can try using that library with more granularity (e.g. splitting into smaller modules, and use only the ones you really need). Il will took you about 30 secs, following this guide