【Unity】Android打包gradle报错

打包gradle报错:

错误详情1:
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details

> Configure project :
Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'BintrayJCenter' was added by build file 'build.gradle'
Build was configured to prefer settings repositories over project repositories but repository 'flatDir' was added by build file 'build.gradle'

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

FAILURE: Build failed with an exception.

* Where:
Build file '*\Library\Bee\Android\Prj\IL2CPP\Gradle\launcher\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':launcher'.
> Failed to apply plugin 'com.android.internal.version-check'.
   > Cannot parse project property android.enableR8='' of type 'class java.lang.String' as boolean. Expected 'true' or 'false'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
错误原因1:

Gradle的配置和Unity的版本不一致。

更改Unity默认路径下的Gradle发现不管用,生成的*\*Library\Bee\Android\Prj\IL2CPP\Gradle里面的文件还是旧版的设置。
然后发现是因为项目使用了Build模板,在Project Settings > Player > Publishing Settings > Build里面设置。根据Unity默认路径下*\Unity\Hub\Editor\2022.3.17f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates中的文件更改项目\Assets\Plugins\Android文件夹中的*.gradle*.properties文件,并且按照链接settingsTemplate.gradle添加以下内容:

maven { url "https://jitpack.io" }
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }

修改如下:

pluginManagement {
    repositories {
        **ARTIFACTORYREPOSITORY**

maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
        gradlePluginPortal()
        google()
        mavenCentral()
maven { url "https://jitpack.io" }//这一条写在上面会报错,所以放在最下面
    }
}

include ':launcher', ':unityLibrary'
**INCLUDES**

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        **ARTIFACTORYREPOSITORY**
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
        google()
        mavenCentral()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
maven { url "https://jitpack.io" }
		
    }
}

修改后报错换了。

错误详情2:
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 35

This Android Gradle plugin (7.1.2) was tested up to compileSdk = 32

This warning can be suppressed by adding
android.suppressUnsupportedCompileSdk=35
to this project's gradle.properties

The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdk = 35
错误原因2:

当前使用的 Android Gradle 插件版本(7.1.2)只支持到 compileSdk = 32,但正在使用 compileSdk = 35。
提高了AGP的版本为7.3.3,还是不行┭┮﹏┭┮

  • 解决方案1:官方回复,但是我没有使用这种方式解决,因为不需要sdk35。
  • 解决方案2:在ProjectSetting > Player > OtherSettings > Target API Level修改成Android 14.0 API Level 34而不是Highest

还遇到过以下类似的问题,未解决但是后来修改了其他的就不报错了。记录以下解决方案:

Q1

How to fix CommandInvokationFailure: Gradle build failed ?

解决 Unity 打包 APK 时出现 Gradle Build Failed 的问题

Build completed with a result of ‘Failed’. Building Player failed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值