安卓无法合并 dex 错误.请参阅内容



Error:Execution for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: T無法合併 dex

我使用的是 Android Studio 的 3.0.1 版。

我还尝试了"清洁项目"和"重建项目"。

*项目构建分级

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

*模块构建分级

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
ext {
grpcVersion = '1.4.0'
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.backkom.speechtest"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled  true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.3.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
// gRPC
compile "io.grpc:grpc-okhttp:$grpcVersion"
compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
compile "io.grpc:grpc-stub:$grpcVersion"
compile 'javax.annotation:javax.annotation-api:1.2'
protobuf 'com.google.protobuf:protobuf-java:3.3.1'
compile group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '0.1.13'
// OAuth2 for Google API
compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
compile 'com.android.support:multidex:1.0.2'
}

当我做重建项目时,我收到如下错误。

错误:任务":app:transformClassesWithMultidexlistForDebug"的执行失败。 java.io.IOException: Can't write [C:\Users\backkom\AndroidStudioProjects\SpeechTest\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\backkom.gradle\caches\modules-2\files-2.1\com.google.protobuf\protobuf-java\3.3.1\e8964a2667e55d11a4505b329a4c34247663920b\protobuf-java-3.3.1.jar(;;;;**.class)] (Duplicate zip entry [protobuf-java-3.3.1.jar:com/google/protobuf/ExperimentalApi.class]))

检查您是否(直接或传递)使用com.google.protobuf:protobuf-javacom.google.protobuf:protobuf-lite组装APK。后者包括前者的类子集,dexer 在找到第一个重复类时会抱怨。您应该排除两者之一。

  1. 排除protobuf-java,如果您只想严格使用 Protobuf OR 的精简子集
  2. 删除implementation ... protobuf-lite行并让 ProGuard 删除不需要的类

相关内容

最新更新