unity导入admob后打安卓Android包卡在gradle

这个问题比较玄学,经常会卡在以下情况:

1.Building Gradle Project...

2.Calling IPostGenerateGradleAndroidProject callbacks

等等各种都是卡在和gradle有关的地方。尝试了各种操作,个人觉得应该是以下几个方法奏效,从而可以成功打包。

0.Admob版本:Google Mobile Ads Unity Plugin v9.1.0

0.Unity版本:2021.3.23f1

1.当你按照Admob指南Resolve后,找到Assets\Plugins\Android\mainTemplate.gradle文件,找到下面的部分,将maven的url换成阿里云的,其他地方不用改。

([rootProject] + (rootProject.subprojects as List)).each { project ->

    project.repositories {

        def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")

        maven {

            url "http://maven.aliyun.com/nexus/content/groups/public/"

        }

        maven {

            url "http://maven.aliyun.com/nexus/content/groups/public/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7, Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12, Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7

        }

        mavenLocal()

        mavenCentral()

    }

}

2.为了保险起见,我在_UnityEditor\2021.3.23f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\baseProjectTemplate.gradle中也进行了类似的设置(如果你没导入Admob,就只改这里)

allprojects {
    buildscript {
        repositories {**ARTIFACTORYREPOSITORY**
			maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
            google()
            jcenter()
        }

        dependencies {
            // If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
            // See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
            // See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
            // To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
            classpath 'com.android.tools.build:gradle:4.0.1'
            **BUILD_SCRIPT_DEPS**
        }
    }

    repositories {**ARTIFACTORYREPOSITORY**
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

3.设置一下Android Resolver,在Unity中,菜单栏点击Assets>External Dependency Manager>Android Resolver>Settings,禁用Enable Auto Resolution和Enable Resolution On Build(为了防止打包的时候它自动Resolve然后会把我们在mainTemplate.gradle配置的地址又替换成谷歌的)

4.删除掉C:\Users\Administrator\.gradle\caches目录

5.重启Unity

6.一般来说可以正常打包了。我的玄学情况是,虽然偶尔还是会卡住,但在卡住的时候开启上网工具似乎就不会再卡住,如果你已经开启了上网工具,就在卡住的时候关闭它,然后就正常了。

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值