You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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.

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:
    1. Open the Unity Package Manager (Window > Package Manager).
    2. Click the "+" icon in the top-left corner, then select "Add package from git URL".
    3. Paste https://github.com/googleads/unity-jar-resolver.git and click "Add". Wait for the package to import fully.
  • Next, set up the required dependency:
    1. Create an Editor folder inside your Assets directory if it doesn't exist already.
    2. Inside the Editor folder, create a C# script named PlayServicesDependencies.
    3. 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);
          }
      }
      
    4. Save the script and return to Unity. The EDM4U will automatically download and integrate the play-services-games library—you'll see a progress bar in the bottom-right corner while it works.

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:
    1. Go to Edit > Project Settings > Player > Android > Publishing Settings.
    2. Scroll to the "Build" section and check "Custom Main Gradle Template". This generates a mainTemplate.gradle file in Assets/Plugins/Android.
  • Add the dependency to the template:
    1. Open mainTemplate.gradle in a text editor (like VS Code or Notepad++).
    2. Locate the dependencies block (it looks like dependencies { ... }).
    3. Add this line inside the block:
      implementation 'com.google.android.gms:play-services-games:19.0.0'
      
    4. Save the file. Now when you export your Android project from Unity, the gradle build will include the required library.

Final Checks

  • After setting up either method, go to File > Build Settings > Android and 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 18:02:51