如何在Unity项目中添加com.google.android.gms:play-services-games库?
How to Add
com.google.android.gms:play-services-games to Unity for Applovin Ads Got it, let's walk through this step by step—since you're working directly in Unity without Android Studio, we've got two reliable ways to get that required Google Play Services library integrated.
Method 1: Use Google's External Dependency Manager (EDM4U) (Recommended)
This tool handles Android dependency resolution automatically, so you don't have to mess with manual gradle edits.
- First, install EDM4U in your Unity project:
- Open the Unity Package Manager (Window > Package Manager).
- Click the "+" icon in the top-left corner, then select "Add package from git URL".
- Paste
https://github.com/googleads/unity-jar-resolver.gitand click "Add". Wait for the package to import fully.
- Next, set up the required dependency:
- Create an
Editorfolder inside yourAssetsdirectory if it doesn't exist already. - Inside the
Editorfolder, create a C# script namedPlayServicesDependencies. - Open the script and replace its content with this code:
using Google.JarResolver; using UnityEditor; [InitializeOnLoad] public static class PlayServicesDependencies { static PlayServicesDependencies() { PlayServicesResolver.ResolveDependencies( new Dependency[] { new Dependency("com.google.android.gms", "play-services-games", "19.0.0") }, handleResolverEvents: true); } } - Save the script and return to Unity. The EDM4U will automatically download and integrate the
play-services-gameslibrary—you'll see a progress bar in the bottom-right corner while it works.
- Create an
Method 2: Manually Edit Unity's Gradle Template
If you prefer not to use EDM4U, you can manually modify the gradle template Unity generates for Android builds.
- Enable the custom gradle template:
- Go to
Edit > Project Settings > Player > Android > Publishing Settings. - Scroll to the "Build" section and check "Custom Main Gradle Template". This generates a
mainTemplate.gradlefile inAssets/Plugins/Android.
- Go to
- Add the dependency to the template:
- Open
mainTemplate.gradlein a text editor (like VS Code or Notepad++). - Locate the
dependenciesblock (it looks likedependencies { ... }). - Add this line inside the block:
implementation 'com.google.android.gms:play-services-games:19.0.0' - Save the file. Now when you export your Android project from Unity, the gradle build will include the required library.
- Open
Final Checks
- After setting up either method, go to
File > Build Settings > Androidand click "Refresh" to ensure Unity picks up the new dependencies. - Test your build to confirm Applovin Ads runs correctly. If you hit issues, double-check that the library version (19.0.0 in the examples) is compatible with your Applovin SDK version—you can adjust the version number if needed, but 19.0.0 is a stable, widely compatible choice.
内容的提问来源于stack exchange,提问作者mando
相关产品推荐
相关产品推荐

