【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

### 解决 Unity Android 打包错误 当遇到 UnityAndroid 平台上打包时出现问题的情况,通常可以从多个方面排查和解决问题。 #### Gradle 版本配置 确保 `build.gradle` 文件中使用的 Gradle 插件版本是最新的,并且与项目的其他依赖项兼容。对于特定的插件版本设置,可以参照以下代码片段来调整: ```groovy plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false id 'org.jetbrains.kotlin.android' version '1.8.0' apply false } ``` 这有助于减少由于不同组件之间的不匹配引起的构建失败[^1]。 #### 检查项目结构 确认项目的目录结构合理,特别是涉及到跨平台开发时(如使用 UnityAndroid SDK)。合理的项目布局能够帮助避免许多潜在的问题。例如,在集成 Android SDK 到 Unity 工程时,应该注意保持清晰的模块划分[^2]。 #### 处理图形资源限制 针对可能出现的图形处理问题,比如顶点数量超出上限,可以通过修改渲染参数来进行优化。具体来说,如果发现索引值溢出或无法正确表示大量顶点,则应考虑更改索引格式为更大的数据类型,如 UInt32: ```csharp create.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; ``` 这样做能有效扩展支持的最大顶点数至65,535以上[^4]。 通过上述措施,大多数常见的 Unity 安卓打包错误都可以得到有效的缓解甚至完全解决。当然,实际操作过程中还需要根据具体的报错信息进一步分析原因并采取相应的对策。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值