У меня есть Android проект, который также должен включать проект Unity. Не импортируя проект Unity, я могу успешно сгенерировать сборку релиза APK (подписанный APK). Но после включения проекта Unity я столкнулся с этой проблемой:

4 следующие ошибки:
Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry
Error: Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry
Шаги I ' Для включения проекта Unity в проект Android:
- Экспорт проекта Unity
- Создание экспортированного проекта в виде библиотеки
- Включение файла .aar в собственном android проекте
По родному android градир уровня приложения:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "application.package.name"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
externalNativeBuild {
cmake {
// arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
cppFlags "-std=c++11", "-frtti", "-fexceptions"
}
}
ndk {
abiFilters 'armeabi-v7a'/*, 'arm64-v8a'*/
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
// ndkBuild {
// path 'src/main/jni/Android.mk'
// }
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
noCompress "tflite"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
configurations {
compile.exclude group: 'androidx.annotation', module: 'annotation'
// added after getting com.android.tools.r8.errors.CompilationError: Program type already present: androidx.annotation.AnimRes
}
repositories {
maven {
url 'https://google.bintray.com/tensorflow'
}
flatDir {
dirs 'libs'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'tensorflow-lite', ext: 'aar')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation "android.arch.core:runtime:1.1.1"
implementation "android.arch.core:common:1.1.1"
implementation project(':openCVLibrary341')
// compile 'org.tensorflow:tensorflow-lite:+'
implementation project(':macelibrary')
testImplementation 'junit:junit:4.12'
implementation(project(':unity')){
exclude group: 'androidx.arch.core' // added after reading the below linked question
}
}
Файл Gradle проекта Unity:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
android {
compileSdkVersion 29
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
ndk {
abiFilters 'armeabi-v7a'
}
versionCode 1
versionName '0.1'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb']
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
/*buildTypes {
debug {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.debug
jniDebuggable true
}
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.debug
}
}*/
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
}
buildTypes {
release {
multiDexEnabled = true
}
}
}
Этот вопрос является дубликатом этого вопроса , но на исходный вопрос нет ответа, и у меня недостаточно репутации, чтобы комментировать и спрашивать о проблеме. Разница лишь в том, что после прочтения этого вопроса я удалил Firebase из проекта Unity и попытался сгенерировать подписанный APK, который тоже не помог, та же ошибка.
Пожалуйста, помогите мне с этой проблемой. Заранее спасибо!