AndroidX - Program type already present: androidx.annotation.BoolRes

佐手、 提交于 2020-01-16 04:45:08

问题


I tried to migrate my current project today to AndroidX using the "Refactor - > Migrate to AndroidX" option in Android Studio and whenever I try to compile my application, I receive a

Program type already present: androidx.annotation.BoolRes

AGPBI: {"kind":"error","text":"Program type already present: androidx.annotation.BoolRes","sources":[{}],"tool":"D8"} :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED :app:buildInfoGeneratorDebug FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

I used ./gradlew app:dependencies to fetch my list of dependencies, but it seems a lot of libraries are using the new androidx.annotation:annotation:1.0.0 dependency.

//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"

回答1:


The problem seems to be related to the renderscript api in my build.gradle file:

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
}

Removing the renderscriptSupportModeEnabled and renderscriptTargetApi from the block seems to fix the issue.




回答2:


It doesn't happen to me during migration. But I run the app in debug mode and without stopping the debug, run the app without debug (Clicked the run app button in android studio).

I need to Clean the project (Build->Clean Project) to resolve this.




回答3:


implementation "androidx.annotation:annotation:1.0.0"

I think the problem is with this dependency, try to upgrade and check whether the problem is solved or not. You can try this if it works:-

androidx.annotation:annotation:1.0.0-alpha3

If it doesn't try to upgrade the dependency.




回答4:


Just disable renderscriptSupportModeEnabled and you will get your code compiled. It is disabled by default so you can just remove the below line from your build.gradle file.

renderscriptSupportModeEnabled = true

Note: Above flag will be required if you gives support API level < 19.



来源:https://stackoverflow.com/questions/52533779/androidx-program-type-already-present-androidx-annotation-boolres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!