Unity 接入Admob SDK 打Apk 过程中遇到的问题

最近项目接入google Admod ,接入的过程比较顺利按照官网给的教程一步一步来就行,但是打包过程遇到了一些问题,记录如下:

Unity 版本:2023.3.4  Admob 版本:Version 9.1.0

第一个问题:

* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class _COROUTINE.ArtificialStackFrames found in modules jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.7.1.jar) and jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1)
  Duplicate class _COROUTINE.CoroutineDebuggingKt found in modules jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.7.1.jar) and jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1)
  Duplicate class _COROUTINE._BOUNDARY found in modules jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.7.1.jar) and jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1)
  Duplicate class _COROUTINE._CREATION found in modules jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.7.1.jar) and jetified-kotlinx-coroutines-core-jvm-1.7.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1)
  Duplicate class android.support.customtabs.ICustomTabsCallback found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsCallback$Default found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsCallback$Stub found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsCallback$Stub$Proxy found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsService found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsService$Default found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsService$Stub found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.ICustomTabsService$Stub$Proxy found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.IPostMessageService found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.IPostMessageService$Default found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.IPostMessageService$Stub found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.IPostMessageService$Stub$Proxy found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityCallback found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityCallback$Default found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityCallback$Stub found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityCallback$Stub$Proxy found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityService found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityService$Default found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityService$Stub found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.customtabs.trusted.ITrustedWebActivityService$Stub$Proxy found in modules browser-1.4.0-runtime.jar (androidx.browser:browser:1.4.0) and jetified-androidx.browser.browser-1.4.0-runtime.jar (:androidx.browser.browser-1.4.0:)
  Duplicate class android.support.v4.app.RemoteActionCompatParcelizer found in modules core-1.8.0-runtime.jar (androidx.core:core:1.8.0) and jetified-androidx.core.core-1.8.0-runtime.jar (:androidx.core.core-1.8.0:)
  Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.8.0-runtime.jar (androidx.core:core:1.8.0) and jetified-androidx.core.core-1.8.0-runtime.jar (:androidx.core.core-1.8.0:)
  Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.8.0-runtime.jar (androidx.core:core:1.8.0) and jetified-androidx.core.core-1.8.0-runtime.jar (:androidx.core.core-1.8.0:)
  Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.8.0-runtime.jar (androidx.core:core:1.8.0) and jetified-androidx.core.core-1.8.0-runtime.jar (:androidx.core.core-1.8.0:)
  Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.8.0-runtime.jar (androidx.core:core:1.8.0) and jetified-androidx.core.core-1.8.0-runtime.jar (:androidx.core.core-1.8.0:)
  Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.8.0-runtime.jar (androidx.core:core:1.8.0) and jetified-androidx.core.core-1.8.0-runtime.jar (:androidx.core.core-1.8.0:)
  Duplicate class androidx.activity.Cancellable found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.ComponentActivity found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.ComponentActivity$1 found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.ComponentActivity$2 found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.ComponentActivity$3 found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.ComponentActivity$NonConfigurationInstances found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.ImmLeaksCleaner found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.OnBackPressedCallback found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.OnBackPressedDispatcher found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.OnBackPressedDispatcher$LifecycleOnBackPressedCancellable found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.OnBackPressedDispatcher$OnBackPressedCancellable found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.activity.OnBackPressedDispatcherOwner found in modules jetified-activity-1.0.0-runtime.jar (androidx.activity:activity:1.0.0) and jetified-androidx.activity.activity-1.0.0-runtime.jar (:androidx.activity.activity-1.0.0:)
  Duplicate class androidx.annotation.OptIn found in modules jetified-androidx.annotation.annotation-experimental-1.1.0-runtime.jar (:androidx.annotation.annotation-experimental-1.1.0:) and jetified-annotation-experimental-1.1.0-runtime.jar (androidx.annotation:annotation-experimental:1.1.0)
  Duplicate class androidx.annotation.RequiresOptIn found in modules jetified-androidx.annotation.annotation-experimental-1.1.0-runtime.jar (:androidx.annotation.annotation-experimental-1.1.0:) and jetified-annotation-experimental-1.1.0-runtime.jar (androidx.annotation:annotation-experimental:1.1.0)
  Duplicate class androidx.annotation.RequiresOptIn$Level found in modules jetified-androidx.annotation.annotation-experimental-1.1.0-runtime.jar (:androidx.annotation.annotation-experimental-1.1.0:) and jetified-annotation-experimental-1.1.0-runtime.jar (androidx.annotation:annotation-experimental:1.1.0)
  Duplicate class androidx.annotation.experimental.Experimental found in modules jetified-androidx.annotation.annotation-experimental-1.1.0-runtime.jar (:androidx.annotation.annotation-experimental-1.1.0:) and jetified-annotation-experimental-1.1.0-runtime.jar (androidx.annotation:annotation-experimental:1.1.0)
  Duplicate class androidx.annotation.experimental.Experimental$Level found in modules jetified-androidx.annotation.annotation-experimental-1.1.0-runtime.jar (:androidx.annotation.annotation-experimental-1.1.0:) and jetified-annotation-experimental-1.1.0-runtime.jar (androidx.annotation:annotation-experimental:1.1.0)
  Duplicate class androidx.annotation.experimental.UseExperimental found in modules jetified-androidx.annotation.annotation-experimental-1.1.0-runtime.jar (:androidx.annotation.annotation-experimental-1.1.0:) and jetified-annotation-experimental-1.1.0-runtime.jar (androidx.annotation:annotation-experimental:1.1.0)
  Duplicate class androidx.appcompat.app.ActionBar found in modules appcompat-1.2.0-runtime.jar (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.2.0-runtime.jar (:androidx.appcompat.appcompat-1.2.0:)
  Duplicate class androidx.appcompat.app.ActionBar$DisplayOptions found in modules appcompat-1.2.0-runtime.jar (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.2.0-runtime.jar (:androidx.appcompat.appcompat-1.2.0:)
  Duplicate class androidx.appcompat.app.ActionBar$LayoutParams found in modules appcompat-1.2.0-runtime.jar (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.2.0-runtime.jar (:androidx.appcompat.appcompat-1.2.0:)
  Duplicate class androidx.appcompat.app.ActionBar$NavigationMode found in modules appcompat-1.2.0-runtime.jar (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.2.0-runtime.jar (:androidx.appcompat.appcompat-1.2.0:)
  Duplicate class androidx.appcompat.app.ActionBar$OnMenuVisibilityListener found in modules appcompat-1.2.0-runtime.jar (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.2.0-runtime.jar (:androidx.appcompat.appcompat-1.2.0:)
  Duplicate class androidx.appcompat.app.ActionBar$OnNavigationListener found in modules appcompat-1.2.0-runtime.jar (androidx.appcompat:appcompat:1.2.0) and jetified-androidx.appcompat.appcompat-1.2.0-runtime.jar (:<message truncated>
看着很多,其实主要是多个jar包问题,问题出在导入admob的过程中把jar包依赖自动下载到了Plugins/Android 目录下了,正常情况下这个目录如果只有admob的话应该是这样

处理方法:把其他的jar包删除就可以了。

Execution failed for task ':launcher:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:11: AAPT: error: attribute layout_constraintBottom_toBottomOf (aka com.*.*:layout_constraintBottom_toBottomOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:11: AAPT: error: attribute layout_constraintEnd_toEndOf (aka com.*.*:layout_constraintEnd_toEndOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:11: AAPT: error: attribute layout_constraintStart_toStartOf (aka com.*.*:layout_constraintStart_toStartOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:11: AAPT: error: attribute layout_constraintTop_toTopOf (aka com.*.*:layout_constraintTop_toTopOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:23: AAPT: error: attribute layout_constraintBottom_toTopOf (aka com.*.*:layout_constraintBottom_toTopOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:23: AAPT: error: attribute layout_constraintEnd_toEndOf (aka com.*.*:layout_constraintEnd_toEndOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:23: AAPT: error: attribute layout_constraintStart_toStartOf (aka com.*.*:layout_constraintStart_toStartOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:23: AAPT: error: attribute layout_constraintTop_toTopOf (aka com.*.*:layout_constraintTop_toTopOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:35: AAPT: error: attribute layout_constraintBottom_toTopOf (aka com.*.*:layout_constraintBottom_toTopOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:35: AAPT: error: attribute layout_constraintEnd_toEndOf (aka com.*.*:layout_constraintEnd_toEndOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:35: AAPT: error: attribute layout_constraintStart_toStartOf (aka com.*.*:layout_constraintStart_toStartOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:35: AAPT: error: attribute layout_constraintTop_toBottomOf (aka com.*.*:layout_constraintTop_toBottomOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:45: AAPT: error: attribute layout_constraintBottom_toBottomOf (aka com.*.*:layout_constraintBottom_toBottomOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:45: AAPT: error: attribute layout_constraintEnd_toEndOf (aka com.*.*:layout_constraintEnd_toEndOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:45: AAPT: error: attribute layout_constraintStart_toStartOf (aka com.*.*:layout_constraintStart_toStartOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:45: AAPT: error: attribute layout_constraintTop_toTopOf (aka com.*.*:layout_constraintTop_toTopOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:55: AAPT: error: attribute layout_constraintBottom_toBottomOf (aka com.*.*:layout_constraintBottom_toBottomOf) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:55: AAPT: error: attribute layout_constraintDimensionRatio (aka com.*.*:layout_constraintDimensionRatio) not found.
         
     C:\Users\DELL\.gradle\caches\transforms-3\246f528239708f672a9905dd9b6fadde\transformed\jetified-googlemobileads-unity\res\layout\gnt_medium_template_view.xml:55: AAPT: error: attribute layout_constraintEnd_toStartOf (aka com.*.*:layout_constraintEnd_toStartOf) not found.
         这个问题的原因是gradleTemplate.properties 没有设置android.useAndroidX=true,正常情况下gradleTemplate.properties内容为

点击Assets > External Dependency Manager > Android Resolver > Resolve 应该就能解决自动生成,如果没有,点击Force Resolve

还有就是打Apk过程中长时间的等待Building Gradle project... 如果超过20分钟可能就build失败了,大概问题是gradle 版本不对,我之前用的版本是6.1.1,报错,改为gradle-6.8 之后正常

最好引入Admob 打包的过程中开vpn,因为有些依赖需要翻墙,或者挂其他代理也行,网上教程比较多,可以查询下

遇到问题国外网站会有更多的解决方法,我百度了很久很多都不对症

  • 19
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值