程序类型已存在:android.support.v4.os.ResultReceiver$MyResultReceiver
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
我正在重构一个应用程序以使用 androidx。我一直在努力摆脱所有不支持它的库。
我以为我已经删除了所有使用支持库的库,但看起来仍然有一些东西正在导入它。
我现在得到错误:
AGPBI: {"kind":"error","text":"Program type already present:
android.support.v4.os.ResultReceiver$MyResultReceiver","sources":[{}],"tool":"D8"}
java.lang.RuntimeException: java.lang.RuntimeException:
com.android.builder.dexing.DexArchiveMergerException: Error while
merging dex archives:
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/532,
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/0.jar,
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/1.jar,
...
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/530.jar,
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/531.jar
Learn how to resolve the issue at
https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present:
android.support.v4.os.ResultReceiver$MyResultReceiver at
sun.reflect.GeneratedConstructorAccessor377.newInstance(Unknown
Source) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at
java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
at
java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
... at
org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at
org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745) Learn how to resolve the
issue at
https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present:
android.support.v4.os.ResultReceiver$MyResultReceiver at
java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1431)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at
java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Learn how to resolve the issue at
https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present:
android.support.v4.os.ResultReceiver$MyResultReceiver at
com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:129)
at
com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:114)
at
com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101)
at
com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:36)
at
java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
... 4 more at
com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:71)
at
com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:41)
at com.android.tools.r8.D8.run(D8.java:89) at
com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:112)
... 7 more at
com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:83)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:62)
at
com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:62)
... 10 more :app:transformDexArchiveWithDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException:
com.android.builder.dexing.DexArchiveMergerException: Error while
merging dex archives:
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/532,
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/0.jar,
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/1.jar,
...
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/530.jar,
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/531.jar
了解如何解决问题
https://developer.android.com/studio/build/dependencies#duplicate_classes。
程序类型已存在:
android.support.v4.os.ResultReceiver$MyResultReceiver
运行 ./gradlew androidDependencies
我得到:
debugCompileClasspath - Dependencies for compilation
+--- io.realm:realm-android-library:5.1.0@aar
+--- io.realm:realm-android-kotlin-extensions:5.1.0@aar
+--- io.realm:realm-annotations:5.1.0@jar
+--- javax.annotation:jsr250-api:1.0@jar
+--- com.google.dagger:dagger-android:2.16@aar
+--- androidx.preference:preference:1.0.0-alpha1@aar
+--- com.google.android.material:material:1.0.0-alpha1@aar
+--- androidx.appcompat:appcompat:1.0.0-alpha1@aar
+--- androidx.cardview:cardview:1.0.0-alpha1@aar
+--- androidx.recyclerview:recyclerview:1.0.0-alpha1@aar
+--- androidx.gridlayout:gridlayout:1.0.0-alpha1@aar
+--- androidx.legacy:legacy-support-v4:1.0.0-alpha1@aar
+--- androidx.vectordrawable:vectordrawable-animated:1.0.0-alpha1@aar
+--- androidx.vectordrawable:vectordrawable:1.0.0-alpha1@aar
+--- androidx.palette:palette:1.0.0-alpha1@aar
+--- com.firebaseui:firebase-ui-auth:3.1.0@aar
+--- com.google.firebase:firebase-auth:15.0.0@aar
+--- com.google.firebase:firebase-config:15.0.2@aar
+--- com.google.firebase:firebase-database:15.0.1@aar
+--- com.jakewharton.rxbinding2:rxbinding:2.0.0@aar
+--- com.jakewharton.rxrelay2:rxrelay:2.0.0@jar
+--- joda-time:joda-time:2.5@jar
+--- com.jakewharton.timber:timber:4.3.1@aar
+--- com.uncopt:android.justified:1.0@jar
+--- androidx.lifecycle:lifecycle-common-java8:2.0.0-alpha1@jar
+--- androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-reactivestreams:2.0.0-alpha1@aar
+--- com.squareup.retrofit2:adapter-rxjava2:2.2.0@jar
+--- com.squareup.retrofit2:converter-moshi:2.2.0@jar
+--- com.squareup.retrofit2:converter-scalars:2.2.0@jar
+--- com.squareup.retrofit2:retrofit:2.2.0@jar
+--- com.squareup.okhttp3:okhttp-urlconnection:3.4.1@jar
+--- com.squareup.okhttp3:logging-interceptor:3.4.1@jar
+--- com.github.franmontiel:PersistentCookieJar:v1.0.1@aar
+--- com.squareup.okhttp3:okhttp:3.6.0@jar
+--- com.squareup.moshi:moshi-kotlin:1.5.0@jar
+--- com.github.MFlisar:RxBus2:0.1@aar
+--- com.jakewharton:butterknife:8.8.1@aar
+--- com.squareup.leakcanary:leakcanary-android:1.5.1@aar
+--- com.crashlytics.sdk.android:crashlytics:2.6.8@aar
+--- com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC2@aar
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.41@jar
+--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.2.41@jar
+--- com.google.code.findbugs:jsr305:1.3.9@jar
+--- com.getkeepsafe.relinker:relinker:1.2.2@aar
+--- com.google.dagger:dagger:2.16@jar
+--- com.android.support:customtabs:26.1.0@aar
+--- com.android.support:cardview-v7:26.1.0@aar
+--- com.jakewharton:butterknife-annotations:8.8.1@jar
+--- com.android.support:design:26.1.0@aar
+--- com.android.support:appcompat-v7:26.1.0@aar
+--- com.android.support:recyclerview-v7:26.1.0@aar
+--- com.android.support:transition:26.1.0@aar
+--- com.google.firebase:firebase-abt:15.0.1@aar
+--- com.google.firebase:firebase-database-connection:15.0.1@aar
+--- com.google.firebase:firebase-analytics:15.0.2@aar
+--- com.google.firebase:firebase-analytics-impl:15.0.2@aar
+--- com.google.firebase:firebase-iid:15.1.0@aar
+--- com.google.firebase:firebase-common:15.0.1@aar
+--- com.google.android.gms:play-services-phenotype:15.0.1@aar
+--- com.google.firebase:firebase-database-collection:15.0.1@aar
+--- com.google.android.gms:play-services-auth:11.4.2@aar
+--- com.google.android.gms:play-services-ads-identifier:15.0.1@aar
+--- com.google.android.gms:play-services-stats:15.0.1@aar
+--- com.google.firebase:firebase-iid-interop:15.0.0@aar
+--- com.google.android.gms:play-services-auth-api-phone:11.4.2@aar
+--- com.google.android.gms:play-services-auth-base:11.4.2@aar
+--- com.google.android.gms:play-services-flags:15.0.1@aar
+--- com.google.android.gms:play-services-base:15.0.1@aar
+--- com.google.android.gms:play-services-tasks:15.0.1@aar
+--- com.google.android.gms:play-services-basement:15.0.1@aar
+--- com.android.support:support-v4:26.1.0@aar
+--- com.android.support:support-media-compat:26.1.0@aar
+--- com.android.support:support-fragment:26.1.0@aar
+--- com.android.support:support-core-utils:26.1.0@aar
+--- com.android.support:animated-vector-drawable:26.1.0@aar
+--- com.android.support:support-core-ui:26.1.0@aar
+--- com.android.support:support-vector-drawable:26.1.0@aar
+--- com.android.support:support-compat:26.1.0@aar
+--- com.android.support:support-annotations:26.1.0@jar
+--- javax.inject:javax.inject:1@jar
+--- androidx.fragment:fragment:1.0.0-alpha1@aar
+--- androidx.legacy:legacy-support-core-ui:1.0.0-alpha1@aar
+--- androidx.legacy:legacy-support-core-utils:1.0.0-alpha1@aar
+--- androidx.media:media:1.0.0-alpha1@aar
+--- androidx.transition:transition:1.0.0-alpha1@aar
+--- androidx.loader:loader:1.0.0-alpha1@aar
+--- androidx.viewpager:viewpager:1.0.0-alpha1@aar
+--- androidx.coordinatorlayout:coordinatorlayout:1.0.0-alpha1@aar
+--- androidx.drawerlayout:drawerlayout:1.0.0-alpha1@aar
+--- androidx.slidingpanelayout:slidingpanelayout:1.0.0-alpha1@aar
+--- androidx.customview:customview:1.0.0-alpha1@aar
+--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0-alpha1@aar
+--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0-alpha1@aar
+--- androidx.core:core:1.0.0-alpha1@aar
+--- androidx.collection:collection:1.0.0-alpha1@jar
+--- androidx.cursoradapter:cursoradapter:1.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-process:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-service:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-runtime:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-livedata:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-livedata-core:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-common:2.0.0-alpha1@jar
+--- androidx.arch.core:core-runtime:2.0.0-alpha1@aar
+--- androidx.arch.core:core-common:2.0.0-alpha1@jar
+--- androidx.lifecycle:lifecycle-viewmodel:2.0.0-alpha1@aar
+--- androidx.documentfile:documentfile:1.0.0-alpha1@aar
+--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0-alpha1@aar
+--- androidx.print:print:1.0.0-alpha1@aar
+--- androidx.interpolator:interpolator:1.0.0-alpha1@aar
+--- androidx.annotation:annotation:1.0.0-alpha1@jar
+--- com.android.support.constraint:constraint-layout:1.1.0-beta1@aar
+--- com.github.akarnokd:rxjava2-extensions:0.15.2@jar
+--- io.reactivex.rxjava2:rxandroid:2.0.1@aar
+--- io.reactivex.rxjava2:rxjava:2.0.6@jar
+--- org.reactivestreams:reactive-streams:1.0.0@jar
+--- com.squareup.moshi:moshi:1.5.0@jar
+--- org.jetbrains.kotlin:kotlin-reflect:1.1.1@jar
+--- org.jetbrains.kotlin:kotlin-stdlib:1.2.41@jar
+--- com.squareup.leakcanary:leakcanary-analyzer:1.5.1@jar
+--- com.crashlytics.sdk.android:beta:1.2.5@aar
+--- com.crashlytics.sdk.android:crashlytics-core:2.3.17@aar
+--- com.crashlytics.sdk.android:answers:1.3.13@aar
+--- io.fabric.sdk.android:fabric:1.3.17@aar
+--- com.google.android.gms:play-services-measurement-base:15.0.2@aar
+--- com.android.support.constraint:constraint-layout-solver:1.1.0-beta1@jar
+--- com.google.android.gms:play-services-auth-license:11.4.2@aar
+--- com.squareup.haha:haha:2.0.3@jar
+--- com.squareup.leakcanary:leakcanary-watcher:1.5.1@jar
+--- com.google.android.gms:play-services-auth-api-phone-license:11.4.2@aar
+--- com.google.android.gms:play-services-auth-base-license:11.4.2@aar
+--- com.squareup.okio:okio:1.13.0@jar
+--- org.jetbrains:annotations:13.0@jar
+--- android.arch.lifecycle:runtime:1.0.0@aar
+--- android.arch.lifecycle:common:1.0.0@jar
\--- android.arch.core:common:1.0.0@jar
问题是:除了检查 build.gradle
:
之外,有没有办法让我知道哪个依赖项正在导入支持库
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
google()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.25.4'
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
android {
def versionMajor = 0
def versionMinor = 1
def versionPatch = 0
compileSdkVersion 'android-P'
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
defaultConfig {
applicationId "org.appid"
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
versionCode versionMajor * 10000
+ versionMinor * 100
+ versionPatch
minSdkVersion 19
targetSdkVersion 27
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
}
buildTypes {
release {
debuggable false
minifyEnabled true
zipAlignEnabled true
renderscriptDebuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
javaCompileOptions.annotationProcessorOptions.arguments['butterknife.debuggable'] = 'false'
resValue "string", "app_version", "${defaultConfig.versionName}"
}
debug {
versionNameSuffix "_dev"
resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix}"
debuggable true
signingConfig signingConfigs.debug
minifyEnabled false
}
}
}
def jsr250_api = '1.0'
def androidxVersion = '1.0.0-alpha1'
def lifecycle_runtime = '2.0.0-alpha1'
def daggerVer = '2.16'
def rxbinding = '2.0.0'
def rxbus2 = '0.1'
def retrofit2 = '2.2.0'
def okhttp3 = '3.4.1'
def firebase = '15.0.0'
def firebase_database = '15.0.1'
def firebaseConfig = '15.0.2'
def firebase_ui_auth = '3.1.0'
def butter_knife = '8.8.1'
def leak_canary = '1.5.1'
def persistent_cookie_jar = 'v1.0.1'
def joda_time = '2.5'
def timber = '4.3.1'
def justified_text_view = '1.0'
def crashlytics = '2.6.8@aar'
def hamcrestVersion = '1.3'
def espresso_core = '3.1.0-alpha1'
def mockitoKotlinVersion = '1.5.0'
def mockitoKotlinInlineVersion = '2.13.0' // to allow testing final classes
def junit = '4.12'
dependencies {
kapt "com.google.dagger:dagger-android-processor:$daggerVer"
implementation "com.google.dagger:dagger-android:$daggerVer"
kapt "com.google.dagger:dagger-compiler:$daggerVer"
implementation "androidx.appcompat:appcompat:$androidxVersion"
implementation "androidx.cardview:cardview:$androidxVersion"
implementation "androidx.recyclerview:recyclerview:$androidxVersion"
implementation "androidx.gridlayout:gridlayout:$androidxVersion"
implementation "androidx.preference:preference:$androidxVersion"
implementation "androidx.vectordrawable:vectordrawable:$androidxVersion"
implementation "androidx.palette:palette:$androidxVersion"
implementation "com.google.android.material:material:$androidxVersion"
implementation "com.google.firebase:firebase-auth:$firebase"
implementation "com.google.firebase:firebase-config:$firebaseConfig"
implementation "com.google.firebase:firebase-database:$firebase_database"
implementation "com.firebaseui:firebase-ui-auth:$firebase_ui_auth"
implementation "com.jakewharton.rxbinding2:rxbinding:$rxbinding"
implementation "com.jakewharton.rxrelay2:rxrelay:$rxbinding"
implementation "joda-time:joda-time:$joda_time"
implementation "com.jakewharton.timber:timber:$timber"
implementation "com.uncopt:android.justified:$justified_text_view"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_runtime"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_runtime"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_runtime"
testImplementation "androidx.arch.core:core-testing:$lifecycle_runtime"
//To use LiveData with ReactiveStreams API
implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_runtime"
implementation "com.squareup.retrofit2:retrofit:$retrofit2"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit2"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit2"
implementation "com.squareup.retrofit2:converter-scalars:$retrofit2"
implementation "com.squareup.okhttp3:okhttp:$okhttp3"
implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttp3"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3"
implementation "com.github.franmontiel:PersistentCookieJar:$persistent_cookie_jar"
implementation 'com.squareup.moshi:moshi-kotlin:1.5.0'
implementation "com.github.MFlisar:RxBus2:$rxbus2"
kapt "com.jakewharton:butterknife-compiler:$butter_knife"
implementation "com.jakewharton:butterknife:$butter_knife"
implementation "com.squareup.leakcanary:leakcanary-android:$leak_canary"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary"
compileOnly "javax.annotation:jsr250-api:$jsr250_api"
implementation("com.crashlytics.sdk.android:crashlytics:$crashlytics") {
transitive = true
}
implementation 'com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation "junit:junit:$junit"
testImplementation "com.nhaarman:mockito-kotlin:$mockitoKotlinVersion"
testImplementation "org.mockito:mockito-inline:$mockitoKotlinInlineVersion"
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
testImplementation "org.hamcrest:hamcrest-integration:$hamcrestVersion"
androidTestImplementation("androidx.test.espresso:espresso-core:$espresso_core", {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
androidExtensions {
experimental = true
}
apply plugin: 'com.google.gms.google-services'
android.packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/rxjava.properties'
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
您可以使用 ./gradlew tasks --all
找出您有哪些任务。其中会有类似yourproject:dependencies
的东西,你可以运行得到这样的依赖树:
./gradlew yourproject:dependencies
我在添加时遇到了同样的问题,
dataBinding {
enabled = true
}
在 app.gradle 模块中。
我的 gradle 依赖项如下:
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-alpha3'
当我改成,
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
我可以在 运行 项目时摆脱错误。
我有非常相似的问题,在我的情况下,解决方案是添加 gradle.properties
这两行:
android.useAndroidX=true
android.enableJetifier=true
希望对您有所帮助。
只需增加对 AndroidX 库的依赖。
示例:app/build.gradle:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
至:
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
比重新重建,显示很多错误。只需注释掉这些旧库即可。重新导入 androidx 库包。
示例如下:
玛格 AndroidX:https://developer.android.com/jetpack/androidx/migrate
希望能解决你的问题
尝试从 Android Studio 中的以下路径 MIGRATE 到 ANDROIDX:
(Refactor>Migrate to AndroidX...)
我认为问题是由于依赖项冲突造成的。就我而言,当我删除 androidx 依赖项时,问题就消失了。
发件人:
dependencies {
implementation "androidx.work:work-runtime:2.1.0"
}
收件人:
dependencies {
implementation "android.arch.work:work-runtime:1.0.1"
}
如果你太依赖androidx,这可能是不可能的。
我正在重构一个应用程序以使用 androidx。我一直在努力摆脱所有不支持它的库。 我以为我已经删除了所有使用支持库的库,但看起来仍然有一些东西正在导入它。 我现在得到错误:
AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver","sources":[{}],"tool":"D8"} java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/532, /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/0.jar, /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/1.jar,
...
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/530.jar, /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/531.jar Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver at sun.reflect.GeneratedConstructorAccessor377.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593) at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677) ... at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:745) Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1431) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:129) at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:114) at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101) at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:36) at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424) ... 4 more at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:71) at com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:41) at com.android.tools.r8.D8.run(D8.java:89) at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:112) ... 7 more at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:83) at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:62) at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:62) ... 10 more :app:transformDexArchiveWithDexMergerForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/532, /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/0.jar, /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/1.jar,
...
/Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/530.jar, /Users/name/myproject/app/build/intermediates/transforms/dexBuilder/debug/531.jar 了解如何解决问题 https://developer.android.com/studio/build/dependencies#duplicate_classes。 程序类型已存在: android.support.v4.os.ResultReceiver$MyResultReceiver
运行 ./gradlew androidDependencies
我得到:
debugCompileClasspath - Dependencies for compilation
+--- io.realm:realm-android-library:5.1.0@aar
+--- io.realm:realm-android-kotlin-extensions:5.1.0@aar
+--- io.realm:realm-annotations:5.1.0@jar
+--- javax.annotation:jsr250-api:1.0@jar
+--- com.google.dagger:dagger-android:2.16@aar
+--- androidx.preference:preference:1.0.0-alpha1@aar
+--- com.google.android.material:material:1.0.0-alpha1@aar
+--- androidx.appcompat:appcompat:1.0.0-alpha1@aar
+--- androidx.cardview:cardview:1.0.0-alpha1@aar
+--- androidx.recyclerview:recyclerview:1.0.0-alpha1@aar
+--- androidx.gridlayout:gridlayout:1.0.0-alpha1@aar
+--- androidx.legacy:legacy-support-v4:1.0.0-alpha1@aar
+--- androidx.vectordrawable:vectordrawable-animated:1.0.0-alpha1@aar
+--- androidx.vectordrawable:vectordrawable:1.0.0-alpha1@aar
+--- androidx.palette:palette:1.0.0-alpha1@aar
+--- com.firebaseui:firebase-ui-auth:3.1.0@aar
+--- com.google.firebase:firebase-auth:15.0.0@aar
+--- com.google.firebase:firebase-config:15.0.2@aar
+--- com.google.firebase:firebase-database:15.0.1@aar
+--- com.jakewharton.rxbinding2:rxbinding:2.0.0@aar
+--- com.jakewharton.rxrelay2:rxrelay:2.0.0@jar
+--- joda-time:joda-time:2.5@jar
+--- com.jakewharton.timber:timber:4.3.1@aar
+--- com.uncopt:android.justified:1.0@jar
+--- androidx.lifecycle:lifecycle-common-java8:2.0.0-alpha1@jar
+--- androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-reactivestreams:2.0.0-alpha1@aar
+--- com.squareup.retrofit2:adapter-rxjava2:2.2.0@jar
+--- com.squareup.retrofit2:converter-moshi:2.2.0@jar
+--- com.squareup.retrofit2:converter-scalars:2.2.0@jar
+--- com.squareup.retrofit2:retrofit:2.2.0@jar
+--- com.squareup.okhttp3:okhttp-urlconnection:3.4.1@jar
+--- com.squareup.okhttp3:logging-interceptor:3.4.1@jar
+--- com.github.franmontiel:PersistentCookieJar:v1.0.1@aar
+--- com.squareup.okhttp3:okhttp:3.6.0@jar
+--- com.squareup.moshi:moshi-kotlin:1.5.0@jar
+--- com.github.MFlisar:RxBus2:0.1@aar
+--- com.jakewharton:butterknife:8.8.1@aar
+--- com.squareup.leakcanary:leakcanary-android:1.5.1@aar
+--- com.crashlytics.sdk.android:crashlytics:2.6.8@aar
+--- com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC2@aar
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.41@jar
+--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.2.41@jar
+--- com.google.code.findbugs:jsr305:1.3.9@jar
+--- com.getkeepsafe.relinker:relinker:1.2.2@aar
+--- com.google.dagger:dagger:2.16@jar
+--- com.android.support:customtabs:26.1.0@aar
+--- com.android.support:cardview-v7:26.1.0@aar
+--- com.jakewharton:butterknife-annotations:8.8.1@jar
+--- com.android.support:design:26.1.0@aar
+--- com.android.support:appcompat-v7:26.1.0@aar
+--- com.android.support:recyclerview-v7:26.1.0@aar
+--- com.android.support:transition:26.1.0@aar
+--- com.google.firebase:firebase-abt:15.0.1@aar
+--- com.google.firebase:firebase-database-connection:15.0.1@aar
+--- com.google.firebase:firebase-analytics:15.0.2@aar
+--- com.google.firebase:firebase-analytics-impl:15.0.2@aar
+--- com.google.firebase:firebase-iid:15.1.0@aar
+--- com.google.firebase:firebase-common:15.0.1@aar
+--- com.google.android.gms:play-services-phenotype:15.0.1@aar
+--- com.google.firebase:firebase-database-collection:15.0.1@aar
+--- com.google.android.gms:play-services-auth:11.4.2@aar
+--- com.google.android.gms:play-services-ads-identifier:15.0.1@aar
+--- com.google.android.gms:play-services-stats:15.0.1@aar
+--- com.google.firebase:firebase-iid-interop:15.0.0@aar
+--- com.google.android.gms:play-services-auth-api-phone:11.4.2@aar
+--- com.google.android.gms:play-services-auth-base:11.4.2@aar
+--- com.google.android.gms:play-services-flags:15.0.1@aar
+--- com.google.android.gms:play-services-base:15.0.1@aar
+--- com.google.android.gms:play-services-tasks:15.0.1@aar
+--- com.google.android.gms:play-services-basement:15.0.1@aar
+--- com.android.support:support-v4:26.1.0@aar
+--- com.android.support:support-media-compat:26.1.0@aar
+--- com.android.support:support-fragment:26.1.0@aar
+--- com.android.support:support-core-utils:26.1.0@aar
+--- com.android.support:animated-vector-drawable:26.1.0@aar
+--- com.android.support:support-core-ui:26.1.0@aar
+--- com.android.support:support-vector-drawable:26.1.0@aar
+--- com.android.support:support-compat:26.1.0@aar
+--- com.android.support:support-annotations:26.1.0@jar
+--- javax.inject:javax.inject:1@jar
+--- androidx.fragment:fragment:1.0.0-alpha1@aar
+--- androidx.legacy:legacy-support-core-ui:1.0.0-alpha1@aar
+--- androidx.legacy:legacy-support-core-utils:1.0.0-alpha1@aar
+--- androidx.media:media:1.0.0-alpha1@aar
+--- androidx.transition:transition:1.0.0-alpha1@aar
+--- androidx.loader:loader:1.0.0-alpha1@aar
+--- androidx.viewpager:viewpager:1.0.0-alpha1@aar
+--- androidx.coordinatorlayout:coordinatorlayout:1.0.0-alpha1@aar
+--- androidx.drawerlayout:drawerlayout:1.0.0-alpha1@aar
+--- androidx.slidingpanelayout:slidingpanelayout:1.0.0-alpha1@aar
+--- androidx.customview:customview:1.0.0-alpha1@aar
+--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0-alpha1@aar
+--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0-alpha1@aar
+--- androidx.core:core:1.0.0-alpha1@aar
+--- androidx.collection:collection:1.0.0-alpha1@jar
+--- androidx.cursoradapter:cursoradapter:1.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-process:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-service:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-runtime:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-livedata:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-livedata-core:2.0.0-alpha1@aar
+--- androidx.lifecycle:lifecycle-common:2.0.0-alpha1@jar
+--- androidx.arch.core:core-runtime:2.0.0-alpha1@aar
+--- androidx.arch.core:core-common:2.0.0-alpha1@jar
+--- androidx.lifecycle:lifecycle-viewmodel:2.0.0-alpha1@aar
+--- androidx.documentfile:documentfile:1.0.0-alpha1@aar
+--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0-alpha1@aar
+--- androidx.print:print:1.0.0-alpha1@aar
+--- androidx.interpolator:interpolator:1.0.0-alpha1@aar
+--- androidx.annotation:annotation:1.0.0-alpha1@jar
+--- com.android.support.constraint:constraint-layout:1.1.0-beta1@aar
+--- com.github.akarnokd:rxjava2-extensions:0.15.2@jar
+--- io.reactivex.rxjava2:rxandroid:2.0.1@aar
+--- io.reactivex.rxjava2:rxjava:2.0.6@jar
+--- org.reactivestreams:reactive-streams:1.0.0@jar
+--- com.squareup.moshi:moshi:1.5.0@jar
+--- org.jetbrains.kotlin:kotlin-reflect:1.1.1@jar
+--- org.jetbrains.kotlin:kotlin-stdlib:1.2.41@jar
+--- com.squareup.leakcanary:leakcanary-analyzer:1.5.1@jar
+--- com.crashlytics.sdk.android:beta:1.2.5@aar
+--- com.crashlytics.sdk.android:crashlytics-core:2.3.17@aar
+--- com.crashlytics.sdk.android:answers:1.3.13@aar
+--- io.fabric.sdk.android:fabric:1.3.17@aar
+--- com.google.android.gms:play-services-measurement-base:15.0.2@aar
+--- com.android.support.constraint:constraint-layout-solver:1.1.0-beta1@jar
+--- com.google.android.gms:play-services-auth-license:11.4.2@aar
+--- com.squareup.haha:haha:2.0.3@jar
+--- com.squareup.leakcanary:leakcanary-watcher:1.5.1@jar
+--- com.google.android.gms:play-services-auth-api-phone-license:11.4.2@aar
+--- com.google.android.gms:play-services-auth-base-license:11.4.2@aar
+--- com.squareup.okio:okio:1.13.0@jar
+--- org.jetbrains:annotations:13.0@jar
+--- android.arch.lifecycle:runtime:1.0.0@aar
+--- android.arch.lifecycle:common:1.0.0@jar
\--- android.arch.core:common:1.0.0@jar
问题是:除了检查 build.gradle
:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
google()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.25.4'
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
android {
def versionMajor = 0
def versionMinor = 1
def versionPatch = 0
compileSdkVersion 'android-P'
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
defaultConfig {
applicationId "org.appid"
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
versionCode versionMajor * 10000
+ versionMinor * 100
+ versionPatch
minSdkVersion 19
targetSdkVersion 27
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
}
buildTypes {
release {
debuggable false
minifyEnabled true
zipAlignEnabled true
renderscriptDebuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
javaCompileOptions.annotationProcessorOptions.arguments['butterknife.debuggable'] = 'false'
resValue "string", "app_version", "${defaultConfig.versionName}"
}
debug {
versionNameSuffix "_dev"
resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix}"
debuggable true
signingConfig signingConfigs.debug
minifyEnabled false
}
}
}
def jsr250_api = '1.0'
def androidxVersion = '1.0.0-alpha1'
def lifecycle_runtime = '2.0.0-alpha1'
def daggerVer = '2.16'
def rxbinding = '2.0.0'
def rxbus2 = '0.1'
def retrofit2 = '2.2.0'
def okhttp3 = '3.4.1'
def firebase = '15.0.0'
def firebase_database = '15.0.1'
def firebaseConfig = '15.0.2'
def firebase_ui_auth = '3.1.0'
def butter_knife = '8.8.1'
def leak_canary = '1.5.1'
def persistent_cookie_jar = 'v1.0.1'
def joda_time = '2.5'
def timber = '4.3.1'
def justified_text_view = '1.0'
def crashlytics = '2.6.8@aar'
def hamcrestVersion = '1.3'
def espresso_core = '3.1.0-alpha1'
def mockitoKotlinVersion = '1.5.0'
def mockitoKotlinInlineVersion = '2.13.0' // to allow testing final classes
def junit = '4.12'
dependencies {
kapt "com.google.dagger:dagger-android-processor:$daggerVer"
implementation "com.google.dagger:dagger-android:$daggerVer"
kapt "com.google.dagger:dagger-compiler:$daggerVer"
implementation "androidx.appcompat:appcompat:$androidxVersion"
implementation "androidx.cardview:cardview:$androidxVersion"
implementation "androidx.recyclerview:recyclerview:$androidxVersion"
implementation "androidx.gridlayout:gridlayout:$androidxVersion"
implementation "androidx.preference:preference:$androidxVersion"
implementation "androidx.vectordrawable:vectordrawable:$androidxVersion"
implementation "androidx.palette:palette:$androidxVersion"
implementation "com.google.android.material:material:$androidxVersion"
implementation "com.google.firebase:firebase-auth:$firebase"
implementation "com.google.firebase:firebase-config:$firebaseConfig"
implementation "com.google.firebase:firebase-database:$firebase_database"
implementation "com.firebaseui:firebase-ui-auth:$firebase_ui_auth"
implementation "com.jakewharton.rxbinding2:rxbinding:$rxbinding"
implementation "com.jakewharton.rxrelay2:rxrelay:$rxbinding"
implementation "joda-time:joda-time:$joda_time"
implementation "com.jakewharton.timber:timber:$timber"
implementation "com.uncopt:android.justified:$justified_text_view"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_runtime"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_runtime"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_runtime"
testImplementation "androidx.arch.core:core-testing:$lifecycle_runtime"
//To use LiveData with ReactiveStreams API
implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_runtime"
implementation "com.squareup.retrofit2:retrofit:$retrofit2"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit2"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit2"
implementation "com.squareup.retrofit2:converter-scalars:$retrofit2"
implementation "com.squareup.okhttp3:okhttp:$okhttp3"
implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttp3"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3"
implementation "com.github.franmontiel:PersistentCookieJar:$persistent_cookie_jar"
implementation 'com.squareup.moshi:moshi-kotlin:1.5.0'
implementation "com.github.MFlisar:RxBus2:$rxbus2"
kapt "com.jakewharton:butterknife-compiler:$butter_knife"
implementation "com.jakewharton:butterknife:$butter_knife"
implementation "com.squareup.leakcanary:leakcanary-android:$leak_canary"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary"
compileOnly "javax.annotation:jsr250-api:$jsr250_api"
implementation("com.crashlytics.sdk.android:crashlytics:$crashlytics") {
transitive = true
}
implementation 'com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation "junit:junit:$junit"
testImplementation "com.nhaarman:mockito-kotlin:$mockitoKotlinVersion"
testImplementation "org.mockito:mockito-inline:$mockitoKotlinInlineVersion"
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
testImplementation "org.hamcrest:hamcrest-integration:$hamcrestVersion"
androidTestImplementation("androidx.test.espresso:espresso-core:$espresso_core", {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
androidExtensions {
experimental = true
}
apply plugin: 'com.google.gms.google-services'
android.packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/rxjava.properties'
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
您可以使用 ./gradlew tasks --all
找出您有哪些任务。其中会有类似yourproject:dependencies
的东西,你可以运行得到这样的依赖树:
./gradlew yourproject:dependencies
我在添加时遇到了同样的问题,
dataBinding {
enabled = true
}
在 app.gradle 模块中。 我的 gradle 依赖项如下:
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-alpha3'
当我改成,
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
我可以在 运行 项目时摆脱错误。
我有非常相似的问题,在我的情况下,解决方案是添加 gradle.properties
这两行:
android.useAndroidX=true
android.enableJetifier=true
希望对您有所帮助。
只需增加对 AndroidX 库的依赖。
示例:app/build.gradle:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
至:
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
比重新重建,显示很多错误。只需注释掉这些旧库即可。重新导入 androidx 库包。
示例如下:
玛格 AndroidX:https://developer.android.com/jetpack/androidx/migrate
希望能解决你的问题
尝试从 Android Studio 中的以下路径 MIGRATE 到 ANDROIDX:
(Refactor>Migrate to AndroidX...)
我认为问题是由于依赖项冲突造成的。就我而言,当我删除 androidx 依赖项时,问题就消失了。
发件人:
dependencies {
implementation "androidx.work:work-runtime:2.1.0"
}
收件人:
dependencies {
implementation "android.arch.work:work-runtime:1.0.1"
}
如果你太依赖androidx,这可能是不可能的。