第一步,确保jdk,sdk,gradle版本一致
unity 3d的配置
idea配置
第二步,整个unity导出安卓项目到idea
idea配置项目(修改gradl配置)
gradle配置代码
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
插件代码:
plugins {
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
// See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
// See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
// To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
id 'com.android.application' version '8.6.0-alpha07' apply false
id 'com.android.library' version '8.6.0-alpha07' apply false
}
第三步,unityLibrary导入到已有安卓项目
报错:
Caused by: org.gradle.api.resources.MissingResourceException: Could not read script 'D:\IDEA-items\quanji_xitong\shared\keepUnitySymbols.gradle' as it does not exist.
解决方法:
路径代码(需要变为自己的路径):
apply from: 'D:/Unity_3D/Quanji_export-test/shared/keepUnitySymbols.gradle'
导入依赖包:
选择unityLibrary模块:
添加依赖:
implementation(project(":unityLibrary"))
删除Gradle Projects方法
unity结束时摧毁主进程解决方案,添加主进程和unity进程:
主进程中:
android:process=":MainActivity"
unity中:
android:process=":UnityActivity"
第四步,每次修改完unity后更新安卓软件包
将U 3D导出的文件main复制到安卓软件中,如下所示
常见以下错误,重新从原来文件中复制,当前文件缺失.sym文件,解决方案如下:
Execution failed for task ':unityLibrary:buildIl2Cpp'.
> Warning: Could not find file D:\IDEA-items\quanji_xitong\unityLibrary\src\main\jniLibs\arm64-v8a\
libil2cpp.sym.so to copy.