当前位置: 首页 > news >正文

Unity打包APK报错 using a newer Android Gradle plugin to use compileSdk = 35

Unity打包APK报错 using a newer Android Gradle plugin to use compileSdk = 35

在这里插入图片描述
三个报错信息如下
第一个

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

第二个

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
ERROR:D:\A_Unity\2022.3.26f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-35\android.jar: D8: java.lang.NullPointerException

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:desugarReleaseFileDependencies'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexFileDependenciesTask$DexFileDependenciesWorkerAction
   > Error while dexing.

* 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

第三个

stderr[
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
ERROR:D:\A_Unity\2022.3.26f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-35\android.jar: D8: java.lang.NullPointerException

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:desugarReleaseFileDependencies'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexFileDependenciesTask$DexFileDependenciesWorkerAction
   > Error while dexing.

* 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
]
stdout[
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

错误原因:这个问题报错的原因是,我使用的 Unity2022.3.26,与之对应的 Android Gradle plugin 也就是 Gradle 版本是 7.1.2,这是Unity 官方给的对应关系
打包 APK 时配置Player Settings-> Android -> OthersSettings -> Identification -> Target API Level -> API Level 35

经测试 API Level 设置为 34/33/32 等低版本都是可以正常打包的

解决方案一
Unity 官方回答:这个问题影响Unity版本2021.3和2022.3 LTS。
目前,由于谷歌构建工具中AAPT2和SDK 35之间的兼容性错误,无法在Unity 2021.3和2022.3上构建SDK 35。我们已经向b谷歌报告了这个问题
我们正在Unity内提供修复,但与此同时,请遵循以下解决方案:
在 Unity 项目内 打开 gradleTemplate.properties ,这个文件 生成方式 Player Settings → Publish Settings → Check “Custom Gradle Properties Template” 在 Plugins/Android 文件夹下生成 gradleTemplate.properties 用文本编辑器打开,然后在最后添加一行 android.aapt2FromMavenOverride=<PATH_TO_YOUR_SDK>/build-tools/35.0.0/aapt2.exe
完整路径以Unity2022.3.26f1 为例安装路径 android.aapt2FromMavenOverride=2022.3.26f1/Editor\Data/PlaybackEngines/AndroidPlayer/SDK/build-tools/35.0.0/aapt2.exe
但是这个解决方案,我自己测试是无效的

解决方案二
错误原因中已经说了 API Level 设置低于 35 的都是可以正常打包的,那么如果不是必须要求设置 为 35 那么就降低版本,再打包

解决方案三
升级 Unity 版本,经过测试 Unity6 打包 APK 设置 API Level 35 打包正常

http://www.dtcms.com/a/38094.html

相关文章:

  • 系统基础与管理(2025更新中)
  • 大语言模型中的梯度值:深入理解与应用
  • android s下make otapackage编译失败
  • Linux:互斥
  • 算法与数据结构(格雷编码)
  • Node.js 中 fs 模块的高级用法
  • 基于 Spring Boot 的高校网上缴费综合务系统设计与实现
  • C# 封装
  • WIFI的SSID超长,隐藏,重复 (2.4G和5G差异)
  • DeepSeek 提示词:基础结构
  • java给钉钉邮箱发送邮件
  • stm32仿真 74hc238流水灯 数码管动态数字显示
  • 快速入门——前端数据模拟MockJS
  • java后端开发day19--学生管理系统升级
  • TypeError: the JSON object must be str, bytes or bytearray, not dict
  • LLM全栈框架完整分类清单(预训练+微调+工具链)
  • VMware中的linux常用指令
  • STM32 缺一不可的最基础的初始化部分
  • CSS—引入方式、选择器、复合选择器、文字控制属性、CSS特性
  • smolagents学习笔记系列(六)Secure code execution
  • Redis 面试题
  • RT-Thread+STM32L475VET6——TF 卡文件系统
  • 创建型模式 - 原型模式 (Prototype Pattern)
  • 【Leetcode】两数之和
  • 【Blender】三、材质篇--01,Blender材质基础 原理化BSDF
  • Go红队开发—基础语法入门
  • 如何在 Ubuntu 上安装和使用 Podman ?
  • 【STL】4.<list>
  • kotlin 知识点 七 泛型的高级特性
  • Java 入门第一课 InteliJ IDEA 的快捷操作