因为谷歌上传要求,需要升级targetsdk33下面一些解办法:
使用版本2019.4.20f1
- 因为31以后sdk缺少dx文件,解决方案是这些文件在文件名称更改为dx.bat.
解决方法如下:
1)进入项目SDK目录下的build-tools\33.0.2 目录,比如:C:\Users\user\AppData\Local\Android\Sdk\build-tools\33.0.2
2)找到一个名为d8.bat的文件,这是Windows批处理文件。
3)复制文件重命名d8.bat为dx.bat。
4)进入项目SDK目录下的build-tools\33.0.2\lib目录,比如:C:\Users\user\AppData\Local\Android\Sdk\build-tools\33.0.2\lib
5)在将d8.jar复制重命名为dx.jar
2.需要在Edit-projectSettings-player-publishingsettings,勾选以下设置:
1).修改生成的两个gardle文件:
Assets/Plugins/Android/mainTemplate.gradle
Assets/Plugins/Android/launcherTemplate.gradle
顶部有下列注释移除:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
添加以下代码:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
// Must be Android Gradle Plugin 3.6.0 or later. For a list of
// compatible Gradle versions refer to:
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
allprojects {
repositories {
google()
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
按需要修改classpath ‘com.android.tools.build:gradle:4.0.1’
3).AndroidManifest.xml文件里需要添加android:exported=“true”,
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
如果Activity,Receiver,Service使用到了标签,则是要显示声明android:exported的值
里面的声明 android:exported 一般改为false 即可 ,但是,如果配置了 LAUNCHER ,就需要把声明改为true
,不然安装时提示解析错误
参考地方:
https://blog.csdn.net/zyl766800/article/details/127693050
https://google-developers.gonglchuangl.net/ar/develop/unity-arf/android-12-build?hl=zh-cn
https://blog.csdn.net/wq6ylg08/article/details/121882199文章来源:https://www.toymoban.com/news/detail-697860.html
补充:如果打aab包,还需要在launcherTemplate.gradle末尾添加如下代码:文章来源地址https://www.toymoban.com/news/detail-697860.html
tasks.whenTaskAdded { task ->
if (task.name.startsWith("bundle")) {
def renameTaskName = "rename${task.name.capitalize()}Aab"
def flavor = task.name.substring("bundle".length()).uncapitalize()
tasks.create(renameTaskName, Copy) {
def path = "${buildDir}/outputs/bundle/${flavor}/"
from(path)
include "launcher-release.aab"
destinationDir file("${buildDir}/outputs/bundle/${flavor}/")
rename "launcher-release.aab", "launcher.aab"
}
task.finalizedBy(renameTaskName)
}
}
//不然会报找不到 “”launcher.aab”或“launcher-release.aab”的错误.
到了这里,关于Unity 升级targetSdkVersion33 解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!