Reputation: 648
I have an Android project which has to include a Unity project as well. Without importing the Unity project, I can successfully generated the release build APK (signed APK). But after including Unity project, I am facing this issue:
4 subsequent errors are:
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
Steps I've taken to include the unity project into Android project:
By native android app level gradle is:
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
}
}
Unity Project gradle file:
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
}
}
}
This question is a duplicate of this question, but there is no answer to the original question and I don't have enough reputation to comment and ask about the issue. The only difference is, after reading this question, I removed Firebase from Unity project and tried to generate signed APK, that didn't help either, same error.
Please help me with this issue. Thanks in advance!
Upvotes: 0
Views: 585
Reputation: 648
I managed to solve this issue by removing the androidx.* libraries from the libs directory of the exported unity project.
androidx.* libraries were already being included in the native android project. While including the Unity project as library, the library also had all these androidx.* libraries and these were causing this issue.
As it turned out, while exporting a Unity project as native Android project, Unity by default includes these androidx.* libraries. They are only needed if we want to build an APK out of that project. But for building a library out of it, these androidx.* libraries are not required.
Upvotes: 1