程序类型已经存在:androidx.arch.core.internal.SafeIterableMap $ Entry生成签名的APK [英] Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry while generating signed APK
问题描述
我有一个Android项目,该项目也必须包含一个Unity项目.在不导入Unity项目的情况下,我可以成功生成发布版本APK(带符号的APK).但是在包含Unity项目之后,我面临着这个问题:
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个后续错误是:
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
我已采取步骤将unity项目纳入Android项目:
Steps I've taken to include the unity project into Android project:
- 导出Unity项目
- 将导出的项目构建为库
- 将.aar文件包含在本地android项目中
通过本机android应用级别,gradle是:
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文件:
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
}
}
}
该问题是该问题的重复项 ,但原始问题没有答案,而且我没有足够的声誉来评论和询问该问题.唯一的区别是,在阅读完此问题后,我从Unity项目中删除了Firebase,并尝试生成签名的APK,但同样没有帮助,同样的错误.
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!
推荐答案
解决方案:
我设法通过从导出的unity项目的 libs 目录中删除androidx.*库来解决此问题.
Solution:
I managed to solve this issue by removing the androidx.* libraries from the libs directory of the exported unity project.
androidx.*库已经包含在本机android项目中.在将Unity项目作为库包含进来时,该库还包含所有这些androidx.*库,这些都是导致此问题的原因.
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.
事实证明,在将Unity项目导出为本地Android项目时,Unity默认包含这些androidx.*库.仅当我们要从该项目中构建APK时才需要它们.但是,要从中构建库,就不需要这些androidx.*库.
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.
这篇关于程序类型已经存在:androidx.arch.core.internal.SafeIterableMap $ Entry生成签名的APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!