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

Unity 游戏提升 Android TargetVersion 相关记录

原因:googleplay 要求。

要构建指定 TargetVersion 的App,
必须使用所需版本的 JDK、Android SDK、Android NDK、Gradle。

只将Unity PlayerSettings/Android/OtherSettings 中,TargetAPILevel 修改为目标版本,然后构建 是不行的!

一般而言,如果 googleplay 有提升要求,Unity会跟进,出对应的 Unity小版本。

直接更换 Unity小版本是成本最小的办法。

但注意,官方可能并不是及时的。可能得半个月左右才会稳定。要是着急必然要趟一些坑。

若要自己在老Unity的基础上替换新的 JDK、Android SDK、Android NDK、Gradle,成本可能是不小的。

----------------------------------------------------------------------------------------------------

这里只记录更换Unity版本的过程。

应注意:

若项目中存在由老版本生成的任何 template.gradle、Manifest、ProguardFile 等文件,则可能需要重新生成/修改。

由于目标gradle版本的差异,这些文件的结构甚至会产生很大变化。
请务必对比这几个新老文件,按需合并,以确保:
其中的数据结构、内容值,与最终所需相符。

最好是由新版本的Unity重新生成,再补充之前需要的内容。

最后,应观察一下导出的安卓工程中的三个gradle 中的 内容是否与所需相符。

尤其注意compileSdkVersion、buildToolsVersion、JavaVersion。

对比 Unity2021.3.4f1c1 和 Unity2021.3.41f1c1生成的部分模板的差异如下:

1、根目录的build.gradle:

2、unityLibrary 中的 build.gradle:

打包报错:

1、* What went wrong:

A problem occurred configuring root project 'XXXXXX'.

> Could not resolve all files for configuration ':classpath'.

   > Could not resolve com.android.tools.build:gradle:7.4.2.

     Required by:

         project : > com.android.application:com.android.application.gradle.plugin:7.4.2

         project : > com.android.library:com.android.library.gradle.plugin:7.4.2

      > No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5.1' but:

          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares a library, packaged as a jar, and its dependencies declared externally:

              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8

              - Other compatible attribute:

                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:

              - Incompatible because this component declares documentation and the consumer needed a library

              - Other compatible attributes:

                  - Doesn't say anything about its target Java version (required compatibility with Java 8)

                  - Doesn't say anything about its elements (required them packaged as a jar)

                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:

              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

              - Other compatible attribute:

                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:

              - Incompatible because this component declares documentation and the consumer needed a library

              - Other compatible attributes:

                  - Doesn't say anything about its target Java version (required compatibility with Java 8)

                  - Doesn't say anything about its elements (required them packaged as a jar)

                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

* 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 6s

原因:gradle 执行时读取的 JAVA_HOME 中的 JAVA 版本不是需要的 11,而是 8。

在检查确定 build.gradle 中的 JavaVersion 无误后,最终确定是 Jenkins 环境变量未修改。

当然,最好直接将 JAVA_HOME 配到系统环境变量中。

2、* What went wrong:

Execution failed for task ':launcher:checkDebugAarMetadata'.

> Could not resolve all files for configuration ':launcher:debugRuntimeClasspath'.

   > Could not find com.bytedance.applog:RangersAppLog-Lite-cn:6.14.3.

     Required by:

         project :launcher > project :unityLibrary

   > Could not find com.google.firebase:firebase-analytics-unity:11.6.0.

     Required by:

         project :launcher > project :unityLibrary

   > Could not find com.google.firebase:firebase-app-unity:11.6.0.

     Required by:

         project :launcher > project :unityLibrary

   > Could not find com.google.firebase:firebase-crashlytics-unity:11.6.0.

     Required by:

         project :launcher > project :unityLibrary

原因:gradle 7 之后将仓库声明调整至 setting.gradle 中,
而 Unity 2021.3.41f1c1 中没有将 setting.gradle 暴露出来,EDM4U 还是将 仓库声明生成到了 unityLibray 项目的 build.gradle 中。

https://github.com/googlesamples/unity-jar-resolver/issues/699

解决:提升Unity 版本到 Unity 2021.3.42f1c1,并且更新EDM4U。

另:因Unity版本提升,HybridCLR 也需提升。

3、WARNING: The option setting 'android.enableR8=true' is deprecated.

It will be removed in version 5.0 of the Android Gradle plugin.

You will no longer be able to disable R8

Build-tool 32.0.0 is missing DX at /Applications/Unity/Hub/Editor/2021.3.4f1c1/PlaybackEngines/AndroidPlayer/SDK/build-tools/32.0.0/dx

File /Users/edy/.android/repositories.cfg could not be loaded.

Build-tool 32.0.0 is missing DX at /Applications/Unity/Hub/Editor/2021.3.4f1c1/PlaybackEngines/AndroidPlayer/SDK/build-tools/32.0.0/dx

FAILURE: Build failed with an exception.

* What went wrong:

Could not determine the dependencies of task ':launcher:compileDebugJavaWithJavac'.

> Installed Build Tools revision 32.0.0 is corrupted. Remove and install again using the SDK Manager.

在尝试使用 32.0.0 代替 30.0.2 目录,并将 launcherTemplate 和 mainTemplate 的 buildToolsVersion =》32.0.0 时报错。

原因:Build Tool 31 以后从SDK内删除了dx工具,使用d8工具来替代dx工具。

解决:把build-tools\30.0.0目录下的dx和lib/dx.jar文件,复制到build-tools\32.0.0目录。

提升 Unity版本,涉及改动:

  1. 安装目标版本Unity,同时安装构建 Android和iOS所需模块。
  2. 使用此Unity打开老的Unity项目,查看内容变化,确保无报错。
  3. 提升开发人员Unity版本,(需提交的ProjectSettings变化、资源meta信息变化)
  4. 确认 gradle-plugin版本是否变化,若变化,是否致使 gradle版本变化。
  5. 配置打包脚本中指定版本的 unity 和 gradle。
  6. 重打资源、重打包

如何查看gradle版本是否变化?

查看根目录中的 build.gradle 中的 classpath。

由上方注释地址,查看Unity文档(注意切换到指定Unity版本的文档)

https://docs.unity3d.com/Manual/android-gradle-overview.html

https://docs.unity3d.com/2021.3/Documentation/Manual/android-gradle-overview.html

根据当前要提升的目标Unity版本:
unity 版本:2021.3.41f1c1

gradle-plugin版本:7.4.2

对应的 gradle 版本:7.5.1

在打包机(Mac)上安装指定版本Gradle:

选择对应Gradle版本:Gradle | Releases

按照安装文档:https://docs.gradle.org/7.5.1/userguide/installation.html

环境:需要java 8+

下载 gradle-7.5.1-bin.zip
❯ cd /Users/edy/Downloads //进入下载目录
❯ sudo mkdir /opt/gradle //创建目标目录
❯ sudo unzip -d /opt/gradle gradle-7.5.1-bin.zip //解压到目标目录
❯ ls /opt/gradle/gradle-7.5.1 //验证解压成功

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

相关文章:

  • Docker小游戏 | 使用Docker部署人生重开模拟器
  • MySQL的三大范式:
  • 机器学习--决策树
  • Rust 语法基础教程
  • sqli-labs通关笔记-第52关 GET数值型order by堆叠注入(手工注入+脚本注入两种方法)
  • Ubuntu 25.04 安装并使用 MySQL 8.4.5 的步骤
  • 使用 npm-run-all2 简化你的 npm 脚本工作流
  • Linux中的restore
  • PHP域名授权系统网站源码/授权管理工单系统/精美UI/附教程
  • 集成电路学习:什么是Haar Cascade Classifier Haar级联分类器
  • Vue 3.5+ Teleport defer 属性详解:解决组件渲染顺序问题的终极方案
  • JavaScript 实用工具方法小全
  • 在STM32F103上进行FreeRTOS移植和配置(源码移植)
  • 【总结型】c语言中的位运算
  • 给AI装上“稳压器”:批归一化如何加速深度学习
  • [Linux] Cockpit管理服务器 软件包管理
  • VScode 使用遇到的问题
  • linux docker neo4j 导出 (windows 导入)
  • Winsows系统去除右键文件显示的快捷列表
  • 微服务架构实战指南:从单体应用到云原生的蜕变之路
  • 头文件包含和前置声明
  • python---包
  • libcurl 中 curl_multi 的演进:从双路并进到 epoll 革命
  • 8.16打卡 DAY43 复习日
  • 0301-solidity进阶-区块链-web3
  • 布隆过滤器的原理及使用
  • Kotlin-基础语法练习一
  • Maven私服配置模版
  • Qt 关于QString和std::string数据截断的问题- 遇到\0或者0x00如何处理?
  • 小白学投资理财 第一天