将Unity从2021.3.31升级到2022.3.59之后,使用Unity的出包接口,运行到GradleBuild会出现两种报错:
1、
Execution failed for task ':unityLibrary:packageReleaseResources'. > Error while evaluating property 'namespace' of task ':unityLibrary:packageReleaseResources' > Failed to calculate the value of task ':unityLibrary:packageReleaseResources' property 'namespace'. > Failed to calculate the value of property 'namespace'. > Package Name not found in xxx\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\src\main\AndroidManifest.xml, and namespace not specified. Please specify a namespace for the generated R and BuildConfig classes via android.namespace in the module's build.gradle file like so: android { namespace 'com.example.namespace' }, 2、
Execution failed for task ':launcher:mergeDexRelease'. > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate > There was a failure while executing work items > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Type {packagename}.android.BuildConfig is defined multiple times: xxx\Library\Bee\Android\Prj\Mono2x\Gradle\launcher\build\intermediates\project_dex_archive\release\out\billion\cash\free\games\jackpot\casino\slots\android\BuildConfig.dex, xxx\Library\Bee\Android\Prj\Mono2x\Gradle\launcher\build\intermediates\sub_project_dex_archive\release\out\6b9d648f1114bbf97287d57921a7f24786f19cc3d9553f24c70f33c3cdc70167_7.jar:classes.dex
这两个报错的原因是同一个问题,错误2的提示: **BuildConfig
类被多次定义**,是因为多个模块(如 :launcher
和 :unityLibrary
)使用了相同的 namespace
,导致生成的 BuildConfig
类重复,
结合报错得出结论:gradle工程中多个模块中应该有相同的 namespace
,导致生成的BuildConfig
类重复,再根据错误一的提示,去修改指定模块的namespace
即可。