Unity Android Plugin Error: java.lang.NoClassDefFoundError: Failed resolution of JAVA Class

Hello everyone, I’m trying to build an Android plugin following the instructions here: http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html
I was able to compile and integrate my plugin in Unity, and everything works as expected. But now, I’m trying to add external libraries to my plugin (so far I’ve tried Facebook Android SDK, Google Analytics…) and when I try to use any of the classes stored in these libraries I’m getting the following errors:

I/Unity﹕ AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/analytics/GoogleAnalytics;

Seems like I’m missing something here. Could you guys help me?

Thanks,

I’ve been inspecting the resulting jar file and I’ve realized that the classes included in the external libraries classes are not actually included into the compiled package.
Check the following screenshot of my plugin (it should include both my classes + FacebookSDK classes as well but it’s not):


So, probably I’m missing something on my gradle settings:

//indicates that this is a library
apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    sourceSets {
        main {
            //Path to your source code
            java {
                srcDir 'src/main/java'
            }
        }
    }

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }

}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile files('libs/classes.jar')
    compile 'com.facebook.android:facebook-android-sdk:4.4.0'
    compile files('libs/AndroidPlugin.jar')
}
//task to delete the old jar
task deleteOldJar(type: Delete) {
    delete 'release/AndroidPlugin.jar'
}

//task to export contents as jar
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    ///Rename the jar
    rename('classes.jar', 'AppInvite.jar')
}

exportJar.dependsOn(deleteOldJar, build)

What do you guys think? Thanks,

Still trying to solve this…

I’m following the instructions here: using facebook sdk in Android studio - Stack Overflow for Facebook integration. My project is compiled into into a jar, but there’s no Facebook classes inside.

Would you guys help me with this one? I’m really lost at this point…

Thanks in advance.

I tried to follow this tutorial and had NoClassDefFoundError too.
To solve it - don’t include BlankActivity when creating a project. Make it empty and then create your java class which extends UnityPlayerActivity. Works fine for me

Did you ever find a solution for this? I’m having the same issue.

Did you? I actually solved this. Can’t remember exactly how, but if you are still stuck, I would try to remember what I’ve did…

Hi blummersolutions,
Can you help me how you solved this problem? I am also facing a similar issue.

I can’t remember exactly how I solved this, but I’m not including the facebook SDK in the Unity project and instead copy the aar into the Android Studio project, into its libs folder.

This works perfectly for me.

Hope that helps.

Hi, please try larku suggestion (I think that’s what I’ve did actually). And post back if you are still stuck.

I’m struggling with this. We are working towards an Android Studio USB serial plugin for Unity but I cannot drag the packages that I need with me and get this error:


Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/felhr/usbserial/UsbSerialDevice;

The package is imported with maven →

project/build.gradle
allprojects {
repositories {
jcenter()
maven { url “https://jitpack.io” }
}
}

app/build.gradle
dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
testCompile 'junit:junit:4.12’compile 'com.github.felHR85:UsbSerial:4.2’compile 'com.android.support:appcompat-v7:23.3.0’compile files(‘libs/classes.jar’)
compile ‘com.google.android.gms:play-services-appindexing:8.1.0’}

Any ideas?

Got it working!!

This seems kind of obvious after I figured it out but I found a .jar version of the library I was importing, and simply placed it in the Unity folder with the AndroidPlugin.jar.

Then I used the usbserial.jar file in my dependencies like the classes.jar file and avoided maven all together. Happy days!

2 Likes

I found the usbserial.jar from the author’s git repo. However, I included the library into my own library (compiled it). So I wouldn’t need to put usbserial.jar in the
\Assets\Plugins\Android folder (if I do so, it would give me error saying that it’s been already added).

When including it in both locations, use “provided” instead of “compile” in your library gradle.

Hello Everyone,

I am facing the same issue. Currently what i have done is made android project as library and written android plugin which is being called in unity. Noticed below error. can anybody help me i this.
Here is my errors.

06-14 11:59:15.388 14515-14542/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
06-14 12:01:12.761 14515-14542/? I/art: Rejecting re-init on previously-failed class java.lang.Class<com.nexstreaming.app.unitylibrary.AndroidPlugin>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
(Throwable with no stack trace)Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.support.v7.app.AppCompatActivity” on path: DexPathList[[zip file “/data/app/com.ltts.dialog-2/base.apk”],nativeLibraryDirectories=[/data/app/com.ltts.dialog-2/lib/arm, /data/app/com.ltts.dialog-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
(Throwable with no stack trace)
06-14 12:01:12.781 14515-14542/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at java.lang.Class.forName(Class.java:326)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.c(Unknown Source)
at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source)
at android.os.MessageQueue.next(MessageQueue.java:392)
at android.os.Looper.loop(Looper.java:136)
at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.support.v7.app.AppCompatActivity” on path: DexPathList[[zip file “/data/app/com.ltts.dialog-2/base.apk”],nativeLibraryDirectories=[/data/app/com.ltts.dialog-2/lib/arm, /data/app/com.ltts.dialog-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.
06-14 12:01:12.781 14515-14562/? E/mono: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at UnityEngine.AndroidJavaObject.Dispose (Boolean disposing) [0x00000] in :0

I meet the same issue recently.
But the reason not the same. I found the jar file I import need the other jar file。but i not import too,When I import the other files solved this。
too careless -_-!

Actually, that’s the journey where I come from, so yes, it ist. My gradle.properies contain:

android.enableJetifier=true
android.useAndroidX=true

Both in the libraries as well as in the app project. Invoking the AndroidX upgrader in Android Studio doesn’t find any more legacy references as well, so I guess it is fine on that. But thanks for pointing out, sadly that is not the issue.

I was getting this error while integrating Unity Ads with Iron Source. Just in case this helps anyone, adding my fix below.

The original issue I was facing was that Unity wouldn’t let me create Android build with Iron Source despite following their tutorial. It kept failing the build at the last moment, saying there were duplicate classes/JARs. Something similar to this:

> 1 exception was raised by workers```

Someone suggested in another thread that doing the following in Unity will fix the issue, which I did:
```Unity Menu Bar > Assets > External Dependency Manager > Android Resolver > Delete Resolved Libraries```

This allowed me to create the build but then the build kept crashing on Launch with this error:
```AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/ironsource/mediationsdk/sdk/InterstitialListener;```

After wasting an entire day trying to figure this out, I finally found the issues. I had earlier already installed "Unity Advertisement" module via Unity Package Manager, which was conflicting with Iron Source's Unity Ads SDK.

Once I removed Unity Ads from Unity Package Manager, the original build error (i.e. checkReleaseDuplicateClasses) got fixed. In case you're facing similar issues, verify if there are multiple sources of same library (as the error suggests).

The other NoClassDefFound error was being caused because all resolved libraries were getting deleted when I was executing the "Delete Resolved Libraries" step I mentioned above. So do not do that, and in case you already did, rerun the Resolve tool by going to:
```Unity Menu Bar > Assets > External Dependency Manager > Android Resolver > Resolve```
5 Likes

I had this problem with duplicated Firebase libs that didn’t get cleaned up. Your explanation set me on the right track. Thanks.

Thanks bro! It works!