【问题标题】:Error: "Program type already present: androidx.versionedparcelable.CustomVersionedParcelable"错误:“程序类型已存在:androidx.versionedparcelable.CustomVersionedParcelable”
【发布时间】:2019-05-03 08:55:23
【问题描述】:

我遇到以下错误 --> 错误:程序类型已存在:androidx.versionedparcelable.CustomVersionedParcelable

当我点击构建错误时,它会显示:

AGPBI: {"kind":"error","text":"Program type already present: androidx.versionedparcelable.CustomVersionedParcelable","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.

我不明白是什么导致了这个问题,因为我使用的是 Parcelable 库,但从来没有给我造成过这种类型的错误。

这是我项目的 gradle 文件。

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.package.name"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    // Lottie
    implementation 'com.airbnb.android:lottie:2.8.0'
    //Gson
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    //Dagger 2
    implementation 'com.google.dagger:dagger:2.18'
    implementation "com.google.dagger:dagger-android-support:2.18"
    annotationProcessor 'com.google.dagger:dagger-compiler:2.18'
    //Asyncjob
    implementation 'com.arasthel:asyncjob-library:1.0.3'
    //Butterknife
    implementation 'com.jakewharton:butterknife:9.0.0-rc1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
}

这是我在 Android Studio 中的构建面板

有什么想法吗??谢谢!!

更新(2018 年 12 月 1 日)

我想我已经找到了这个问题的答案。我读到所有支持库都将迁移到 androidx 库。

所以我阅读了 Android 开发者文档并解释了如何将所有 android.support. 库迁移到 androidx。

您只需进入 Android Studio 并从菜单栏中进行 Refactor >> Migrate to AndroidX

这是更多信息的链接-->Android Developers Documentation (Migrate to Androidx)

【问题讨论】:

  • 使用Migrate to AndroidX 选项后,重建对我来说已经足够了

标签: android gradle error-handling android-gradle-plugin runtime-error


【解决方案1】:

经过长时间的搜索,只有这个解决方案对我有用。

Android Studio 菜单 -> 构建 -> 重建项目。

来源Here

【讨论】:

  • 这应该是选择的答案!为我工作,我尝试了很多东西〜。谢谢!
【解决方案2】:

问题:

错误:程序类型已存在:

androidx.versionedparcelable.CustomVersionedParcelable

解决方案:将此添加到顶部的 gradle.properties 文件中。

android.useAndroidX=true

android.enableJetifier=true

您的项目将在构建期间顺利迁移到 androidx

【讨论】:

    【解决方案3】:

    将此添加到您的 gradle.properties 文件中

    android.useAndroidX=true
    android.enableJetifier=true
    

    【讨论】:

    • 这几乎是我在更新中解释的解决方案,但我的解决方案是由 Android Studio 自动生成的。顺便说一句,谢谢!
    • 如果我们因为与其他库冲突而不想使用 AndroidX 怎么办?
    • @Mayoul 看到我的回答。
    猜你喜欢
    • 1970-01-01
    • 2019-07-25
    • 2019-09-04
    • 2020-10-13
    • 2019-05-22
    • 2020-03-26
    • 2018-09-07
    • 2020-02-15
    • 1970-01-01
    相关资源
    最近更新 更多