'Unity 2019 - Android - NoClassDefFoundError with custom library and Google Play Service dependencies

I'm working on an App for Android which uses a custom library. This library needs the

implementation 'com.google.android.gms:play-services-ads:17.1.2'

I generate a plugin for unity with Android Studio and build the App. Everything works fine until I start using functions of the custom library. The app crashes with the following error message. What do I have to do to fix this NoClassDefFoundError for the Google Play Service stuff. I'm really stuck.

Process: com.example.app, PID: 10230
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/ads/identifier/AdvertisingIdClient;
    at com.customLib.lib.o.a(SourceFile:36)
    at com.customLib.lib.i0.<init>(SourceFile:81)
    at com.customLib.lib.e0.<init>(SourceFile:10)
    at com.customLib.lib.u.a(SourceFile:17)
    at com.customLib.lib.s$h.a(SourceFile:1)
    at com.customLib.lib.p.run(SourceFile:1)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.os.HandlerThread.run(HandlerThread.java:65)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.identifier.AdvertisingIdClient" on path: DexPathList[[zip file "/data/app/com.example.app-DMDw0weJE1AN-hQFZpfcWA==/base.apk", zip file "/data/app/com.example.app-DMDw0weJE1AN-hQFZpfcWA==/split_config.arm64_v8a.apk"],nativeLibraryDirectories=[/data/app/com.example.app-DMDw0weJE1AN-hQFZpfcWA==/lib/arm64, /data/app/com.example.app-DMDw0weJE1AN-hQFZpfcWA==/base.apk!/lib/arm64-v8a, /data/app/com.example.app-DMDw0weJE1AN-hQFZpfcWA==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.customLib.lib.o.a(SourceFile:36)
    at com.customLib.lib.i0.<init>(SourceFile:81)
    at com.customLib.lib.e0.<init>(SourceFile:10)
    at com.customLib.lib.u.a(SourceFile:17)
    at com.customLib.lib.s$h.a(SourceFile:1)
    at com.customLib.lib.p.run(SourceFile:1)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.os.HandlerThread.run(HandlerThread.java:65)
    Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/com.example.app-DMDw0weJE1AN-hQFZpfcWA==/split_config.arm64_v8a.apk
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:353)
    at dalvik.system.DexFile.<init>(DexFile.java:100)
    at dalvik.system.DexFile.<init>(DexFile.java:74)
    at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
    at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
    at dalvik.system.DexPathList.<init>(DexPathList.java:157)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
    at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
    at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
    at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:678)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:711)
    at android.app.LoadedApk.getResources(LoadedApk.java:944)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:2303)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5943)
    at android.app.ActivityThread.-wrap1(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

I'm working with Unity 2019.4

Thanks a lot for your help! Cheers Stephan



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source