Android APK missing dependencies

Previously, we were using Unity 2021.3.29f1 to make our builds with EDM4U 1.2.176. We use AppLovin MAX Unity SDK for ad mediation. When resolving dependencies with EDM4U, it would put the .aar files into the Assets/Plugins/Android folder.

Since Google has the API 34 requirement, we updated to Unity 2021.3.42f1 and EDM4U 1.2.182. When I tried to resolve our dependencies, I got a popup saying the current preferred method is to let Gradle handle adding the dependencies to the build using various Gradle templates. So I updated the settings to let it do just that.

But when I build an APK now, it seems Gradle doesn’t to add all (or possibly any) of the dependencies to the APK. This causes the AppLovin post Gradle script to throw an error saying the Quality Service Plugin failed to be added to the build and it causes apkanalyzer to spit out an error saying it can’t estimate the build size due to a java.lang.ClassNotFoundException error. And when I load the APK on my test device with logcat running, it hangs because it cannot find the Android classes needed to connect to Google Play Games.

Since Google requires target API 34, downgrading Unity seems out of the question. And unfortunately, reverting to EDM4U 1.2.176 doesn’t seem to fix the issue at all.

I’m not well versed in Gradle, so I’m not sure what my options are to fix this issue. Any help would be much appreciated.

I guess first thing to see what dependencies are added, locate gradle project somewhere in Library/Bee/Android folder and take a look at unityLibrary/build.gradle file.

Here’s what the file shows in Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\build.gradle:

apply plugin: 'com.android.library'


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'androidx.recyclerview:recyclerview:1.2.1' // Assets/MaxSdk/Mediation/Mintegral/Editor/Dependencies.xml:9
    implementation 'com.android.installreferrer:installreferrer:2.1' // Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:10
    implementation 'com.android.support:appcompat-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'com.android.support:cardview-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    // implementation 'com.android.support:customtabs:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'com.android.support:customtabs:28.+' // Assets/MaxSdk/Mediation/InMobi/Editor/Dependencies.xml:7
    implementation 'com.android.support:recyclerview-v7:28.+' // Assets/MaxSdk/Mediation/InMobi/Editor/Dependencies.xml:6
    implementation 'com.android.support:support-v4:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'com.applovin.mediation:bidmachine-adapter:3.0.0.0' // Assets/MaxSdk/Mediation/BidMachine/Editor/Dependencies.xml:8
    implementation 'com.applovin.mediation:chartboost-adapter:9.7.0.1' // Assets/MaxSdk/Mediation/Chartboost/Editor/Dependencies.xml:8
    implementation 'com.applovin.mediation:facebook-adapter:[6.17.0.0]' // Assets/MaxSdk/Mediation/Facebook/Editor/Dependencies.xml:8
    implementation 'com.applovin.mediation:fyber-adapter:8.3.0.0' // Assets/MaxSdk/Mediation/Fyber/Editor/Dependencies.xml:4
    implementation 'com.applovin.mediation:google-adapter:[23.2.0.0]' // Assets/MaxSdk/Mediation/Google/Editor/Dependencies.xml:5
    implementation 'com.applovin.mediation:google-ad-manager-adapter:[23.2.0.0]' // Assets/MaxSdk/Mediation/GoogleAdManager/Editor/Dependencies.xml:5
    implementation 'com.applovin.mediation:inmobi-adapter:10.7.5.0' // Assets/MaxSdk/Mediation/InMobi/Editor/Dependencies.xml:4
    implementation 'com.applovin.mediation:ironsource-adapter:8.2.1.0.0' // Assets/MaxSdk/Mediation/IronSource/Editor/Dependencies.xml:8
    implementation 'com.applovin.mediation:mintegral-adapter:16.8.11.0' // Assets/MaxSdk/Mediation/Mintegral/Editor/Dependencies.xml:8
    implementation 'com.applovin.mediation:unityads-adapter:4.12.2.0' // Assets/MaxSdk/Mediation/UnityAds/Editor/Dependencies.xml:4
    implementation 'com.applovin.mediation:vungle-adapter:7.4.0.0' // Assets/MaxSdk/Mediation/Vungle/Editor/Dependencies.xml:4
    implementation 'com.applovin:applovin-sdk:12.6.0' // Assets/MaxSdk/AppLovin/Editor/Dependencies.xml:4
    implementation 'com.appsflyer:adrevenue:6.9.1' // Assets/AppsFlyer/Editor/AppsFlyerAdRevenueDependencies.xml:4
    implementation 'com.appsflyer:af-android-sdk:6.14.2' // Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:6
    implementation 'com.appsflyer:af-purchaseconnector-unity:2.0.1' // Assets/AppsFlyer/Editor/AppsFlyerPurchaseConnectorDependencies.xml:5
    implementation 'com.appsflyer:purchase-connector:2.0.1' // Assets/AppsFlyer/Editor/AppsFlyerPurchaseConnectorDependencies.xml:6
    implementation 'com.appsflyer:unity-adrevenue-generic-wrapper:6.9.1' // Assets/AppsFlyer/Editor/AppsFlyerAdRevenueDependencies.xml:5
    implementation 'com.appsflyer:unity-wrapper:6.14.5' // Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:8
    implementation 'com.facebook.android:facebook-applinks:[17.0.0,18)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:6
    implementation 'com.facebook.android:facebook-core:[17.0.0,18)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:5
    implementation 'com.facebook.android:facebook-gamingservices:[17.0.0,18)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:9
    implementation 'com.facebook.android:facebook-login:[17.0.0,18)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:7
    implementation 'com.facebook.android:facebook-share:[17.0.0,18)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:8
    implementation 'com.google.android.gms:play-services-base:16.1.0' // Assets/MaxSdk/Mediation/Chartboost/Editor/Dependencies.xml:9
    implementation 'com.google.android.ump:user-messaging-platform:2.+' // Assets/MaxSdk/AppLovin/Editor/Dependencies.xml:5
    implementation 'com.google.games:gpgs-plugin-support:0.11.01' // Assets/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPluginDependencies.xml:11
    implementation 'com.parse.bolts:bolts-android:1.4.0' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:4
    implementation 'com.squareup.picasso:picasso:2.71828' // Assets/MaxSdk/Mediation/InMobi/Editor/Dependencies.xml:5
    implementation 'com.tapjoy:tapjoy-android-unitybridge:14.0.1' // Assets/TapjoySDK/Editor/TJPluginDependencies.xml:10
// Android Resolver Dependencies End
    implementation(name: 'applovin-max-unity-plugin', ext:'aar')
    implementation(name: 'common', ext:'aar')
    implementation(name: 'facebook-android-wrapper-17.0.1', ext:'aar')
    implementation(name: 'billing-5.2.1', ext:'aar')
    implementation project('mobilenotifications.androidlib')
    implementation project('GooglePlayGamesManifest.androidlib')

	implementation 'com.google.android.play:asset-delivery:2.1.0'
}

// Android Resolver Exclusions Start
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}
// Android Resolver Exclusions End
android {
    namespace "com.unity3d.player"
    ndkPath "C:/Program Files/Unity/Hub/Editor/2021.3.42f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK"
    compileSdkVersion 34
    buildToolsVersion '32.0.0'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 34
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        versionCode 20075058
        versionName '2.7.5058'
        consumerProguardFiles 'proguard-unity.txt'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
        doNotStrip '*/arm64-v8a/*.so'
        jniLibs {
            useLegacyPackaging true
        }
    }
}




configurations.implementation {
    exclude(group : "com.android.support")
	exclude(group : "com.google.android.gms")
}

Seems like dependencies are there, so what class is missing?

By the way, is this added by you

configurations.implementation {
    exclude(group : "com.android.support")
	exclude(group : "com.google.android.gms")
}

?

I know that some AppLovin libraries are missing based on the build error in Unity.

When the game first opens, it tries to connect to Google Play Games, but I get this error:

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.PlayGames

I can’t progress beyond that, so I don’t know what other libraries might be missing yet unless I remove the login requirement.

No, I did not add that. And it’s not in any of my Gradle template files, either. I’m guessing that’s the reason why our Google Play login breaks. Perhaps there’s a setting I activated in EDM4U that causes that section to get added?

I wrote a IPostGenerateGradleAndroidProject script to brute force remove the configurations.implementation section just to see if that would help any and it did. I now get a build that does include com.android.support and com.google.android.gms and allows me to load into the game.

I still get the two build error messages stating:

Error [AppLovin MAX] Failed to add AppLovin Quality Service plugin. Quality Service Plugin Added?: False, Quality Service Repo added?: False, Quality Service dependency added?: False

and

System.Exception: apkanalyzer failed to estimate the apk size. Output:
Error: Could not find or load main class Files\Unity\Hub\Editor\2021.3.42f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6.0\bin\\..
Caused by: java.lang.ClassNotFoundException: Files\Unity\Hub\Editor\2021/3/42f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6/0\bin\\//

The AppLovin SDK does initialize, but it can’t seem to load any of the ad libraries, so I suspect those are still missing from the APK.

My last response disappeared somehow…sorry if this winds up a double post.

I wrote a IPostGenerateGradleAndroidProject script that removed the configurations.implementation section from the build.gradle file to see if that helped any. It seems to have allowed the classes from com.android.support and com.google.android.gms to be added to the APK. I was able to at least load into our game after it attempted to log in to Google Play Store.

The build does still show these two error messages after an APK is generated in Unity:

#1

Error [AppLovin MAX] Failed to add AppLovin Quality Service plugin. Quality Service Plugin Added?: False, Quality Service Repo added?: False, Quality Service dependency added?: False

#2

System.Exception: apkanalyzer failed to estimate the apk size. Output:
Error: Could not find or load main class Files\Unity\Hub\Editor\2021.3.42f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6.0\bin\\..
Caused by: java.lang.ClassNotFoundException: Files\Unity\Hub\Editor\2021/3/42f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6/0\bin\\//

When loading the game up, the AppLovin SDK does initialize, but none of the ad libraries we use are loading. Logcat has a huge section of error messages like this:

k <init> cannot load Chartboost
k <init> cannot load AppLovin
k <init> cannot load AdMob
k <init> cannot load Fyber

I suspect that means those dependencies are missing from the APK.

AppLovin issued an update over the weekend. That fixed the AppLovin Quality Service plugin error.

But the apkanalyzer error still remains and the generated APK is still missing the ad libraries. If the error actually specified which Java class wasn’t found, it might’ve been a good clue.

I’ve messed with settings, tried updating and downgrading plugins, removing and re-adding ad libraries, but sadly I don’t seem to be making any progress with this at the moment.

I went on a deep dive and removed just about every plugin we had, even most of the Unity packages for things like notifications and in-app purchases to see what, if any, were modifying the gradle file to remove Android libraries.

But the configurations.implementation still exists.

Here’s the updated unityLibrary/build.gradle

apply plugin: 'com.android.library'


dependencies {
    //id 'com.applovin.quality' version '+' apply false // NOTE: Requires version 4.8.3+ for Gradle version 7.2+
    implementation fileTree(dir: 'libs', include: ['*.jar'])

}

android {
    namespace "com.unity3d.player"
    ndkPath "C:/Program Files/Unity/Hub/Editor/2022.3.41f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK"
    compileSdkVersion 34
    buildToolsVersion '32.0.0'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 34
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        versionCode 20075058
        versionName '2.7.5058'
        consumerProguardFiles 'proguard-unity.txt'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
        doNotStrip '*/arm64-v8a/*.so'
        jniLibs {
            useLegacyPackaging true
        }
    }
}




configurations.implementation {
    exclude(group : "com.android.support")
	exclude(group : "com.google.android.gms")
}

Whoops, nevermind…we found the culprit of the configurations.implementation addition.

It was a build script in our project for, added after reading this post:

Fixed the issue. I had to remove the old post-gradle build code and completely regenerate my gradle template files.