【发布时间】:2020-07-06 04:36:41
【问题描述】:
将 .aar 文件添加到应用程序 gradle 后出现指定异常:程序类型已存在:android_serialport_api.SerialPort
当我尝试构建 Debug APK 时,它正在工作,但是当我尝试构建 Signed APK 时,它给出了指定的异常
下面是我的 app-gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "XX.XX.XX"
minSdkVersion 22
targetSdkVersion 28
versionCode 27
versionName "6.6"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
useProguard true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations {
all*.exclude group: 'com.squareup.okhttp3';
all*.exclude group: 'com.squareup.okio';
}
}
repositories {
maven { url "jitpack.io" }
maven { name 'glide-snapshot'; url 'oss.sonatype.org/content/repositories/snapshots' }
mavenCentral()
}
dependencies {
implementation files('libs/apache-httpcomponents-httpclient.jar')
implementation files('libs/apache-httpcomponents-httpcore.jar')
implementation files('libs/commons-codec-1.11.jar')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.journeyapps:zxing-android-embedded:3.5.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-location:11.0.4'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
implementation 'com.jakewharton.timber:timber:4.5.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'me.dm7.barcodescanner:zxing:1.8.4'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.github.antonKozyriatskyi:CircularProgressIndicator:1.3.0'
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
//implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.54'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
/*implementation(name: 'merchantsdk', ext: 'aar')*/
/*implementation(name: 'merchantsdk', ext: 'aar'){
exclude module: 'SerialPort'
}*/
/*implementation(name: 'ezetapandroidsdk', ext: 'aar')*/
implementation project(':merchantsdk')
implementation project(':ezetapandroidsdk')
testImplementation 'junit:junit:4.12'
implementation files('libs/org.apache.commons.io.jar')
}
apply plugin: 'com.google.gms.google-services'
下面是项目的gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url "https://jcenter.bintray.com"}
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://jitpack.io'
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
以下是例外情况
> Task :app:transformClassesAndResourcesWithR8ForRelease FAILED
AGPBI: {"kind":"error","text":"Program type already present: android_serialport_api.a","sources":[{}],"tool":"R8"}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete
调试 apk 工作正常,但是当我尝试构建签名 APK 时出现上述异常。 请帮助我。在此先感谢。
【问题讨论】:
-
问题是有2个或更多的包使用
android_serialport_api.SerialPort。merchantsdk来自哪里? -
感谢您的回复 HB,它是我们项目的第三方 SDK,如何检查包的重复性?