【问题标题】:AndroidX - Program type already present: androidx.annotation.BoolResAndroidX - 程序类型已经存在:androidx.annotation.BoolRes
【发布时间】:2019-09-30 18:55:55
【问题描述】:

我今天尝试使用 Android Studio 中的“重构 -> 迁移到 AndroidX”选项将我当前的项目迁移到 AndroidX,每当我尝试编译我的应用程序时,我都会收到一个

程序类型已经存在:androidx.annotation.BoolRes

AGPBI: {"kind":"error","text":"程序类型已经存在:androidx.annotation.BoolRes","sources":[{}],"tool":"D8"} :app:transformDexArchiveWithExternalLibsDexMergerForDebug 失败 :app:buildInfoGeneratorDebug FAILURE:构建失败并出现异常。 * 什么地方出了错: 任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败。

我使用./gradlew app:dependencies 来获取我的依赖项列表,但似乎很多库都在使用新的androidx.annotation:annotation:1.0.0 依赖项。

//Android
implementation "androidx.constraintlayout:constraintlayout:$constraintLayout"
implementation "androidx.cardview:cardview:$androidX"
implementation "androidx.recyclerview:recyclerview:$androidX"
implementation "androidx.annotation:annotation:1.0.0"

//Material
implementation "com.google.android.material:material:$material"

// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle"

//Room
implementation "androidx.room:room-runtime:$room"
annotationProcessor "androidx.room:room-compiler:$room"

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    问题似乎与我的build.gradle文件中的renderscript api有关:

    defaultConfig {
        applicationId "xxx"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        renderscriptTargetApi 28
        renderscriptSupportModeEnabled true
    }
    

    从块中删除renderscriptSupportModeEnabledrenderscriptTargetApi 似乎可以解决问题。

    【讨论】:

      【解决方案2】:

      在迁移期间我不会发生这种情况。但是我在调​​试模式下运行应用程序,并且不停止调试,在不调试的情况下运行应用程序(单击 android studio 中的运行应用程序按钮)。

      我需要清理项目(构建->清理项目)来解决这个问题。

      【讨论】:

        【解决方案3】:
        implementation "androidx.annotation:annotation:1.0.0"
        

        我认为问题出在这个依赖上,尝试升级并检查问题是否解决。如果可行,你可以试试这个:-

        androidx.annotation:annotation:1.0.0-alpha3
        

        如果它没有尝试升级依赖。

        【讨论】:

        【解决方案4】:

        只需禁用 renderscriptSupportModeEnabled 即可编译代码。 默认情况下它是禁用的,因此您可以从 build.gradle 文件中删除以下行。

        renderscriptSupportModeEnabled = true
        

        注意:如果您提供支持 API 级别

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-01-27
          • 2018-09-23
          • 2019-02-22
          • 1970-01-01
          • 2018-10-21
          • 1970-01-01
          • 2018-10-03
          • 2019-04-10
          相关资源
          最近更新 更多