我已经迁移到androidx
,并且经过大量的时间,我无法摆脱下面的错误。我已经集成了multidex
,但仍然出现错误。
这是例外:
失败:构建失败,并出现异常。
出了什么问题
任务':app:transformDexArchiveWithExternalLibsDexMergerForBetaDebug'的执行失败。 java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex
我无法使其正常运行。这是我的build.gradle。有什么想法吗?
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 28
buildToolsVersion '27.0.3'
signingConfigs {
releaseSign {
storeFile file("$rootProject.projectDir/keystore_release.jks")
storePassword 'xxxxxxx'
keyAlias 'xxxxxxx'
keyPassword 'xxxxxxx'
}
}
// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.xxxxxxx.xxxxxxx"
minSdkVersion 19
targetSdkVersion 28
versionCode 10
versionName "1.0.10"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseSign
}
}
flavorDimensions "default"
productFlavors {
beta {
applicationId "com.xxxxxxx.xxxxxxx.beta"
dimension "default"
resValue "string", "app_name", "xxxxxxx Beta"
buildConfigField "String", "BASE_URL", '"http://xxxxxxx.net"'
buildConfigField "Boolean", "IS_BETA", "true"
buildConfigField "String", "TENANT", '"xxxxxxx"'
}
production {
applicationId "com.xxxxxxx.driver"
dimension "default"
resValue "string", "app_name", "Driver"
buildConfigField "String", "BASE_URL", '"http://apxxxxxxx"'
buildConfigField "Boolean", "IS_BETA", "false"
buildConfigField "String", "TENANT", '"xxxxxxx"'
}
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'me.grantland:autofittextview:0.2.1'
implementation 'com.android.volley:volley:1.1.1'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.github.ybq:Android-SpinKit:1.2.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
def work_version = "2.0.1"
implementation "androidx.work:work-runtime:$work_version"
// Optional - RxJava2 support
implementation "androidx.work:work-rxjava2:$work_version"
def futures_version = "1.0.0-beta01"
implementation "androidx.concurrent:concurrent-futures:$futures_version"
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:1)
很难看到问题出在哪里。请尝试以下操作之一:
1-将Google服务更新为最新版本
2-强制使用旧支持库的所有外部库使用相同版本,并在依赖项之前添加:
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.android.support' && details.requested.name != 'multidex') {
details.useVersion "VERSION_HERE" // try 28.0.0
}
}
}
}
dependencies {
...
}
这将使gradle更轻松地将所有支持lib类替换为androidx类
3-不再需要“ buildToolsVersion”,gradle将为您选择正确的版本,您是否需要此特定版本?
4-我停止使用Fabric,因为由于内部依赖性,它在我的应用程序中引起了很多编译问题。如果可能,请尝试将其删除。
答案 1 :(得分:1)
该软件包中不应包含com.android.support
。最好在gradle.properties
文件中启用Jetifier,而不是修复不应该包含的过时的库:
android.enableJetifier=true
android.useAndroidX=true