The given artifact contains a string literal with a package reference 'android.support.v4.content'

问题描述

Android Studio编译时产生一下错误:

The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

build.gradle文件的内容如下:

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.coship.android.tv.basetest"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath = true
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'src/main/定位的目录']
        }
    }
 }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.jakewharton:butterknife:8.6.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
    testImplementation 'junit:junit:4.12'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'org.apache.commons.io:commonsIO:2.5.0'
    implementation 'org.litepal.android:core:1.5.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}


解决方法

经过多次查资料和试验发现,产生这个错误的原因是由于项目引用了AndroidX的依赖包,但是下面这两个依赖的内部是引用之前的 support 包实现的,因此产生矛盾。

implementation 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'

只需要更改以上的依赖到最新版本即可,如将8.6.0改为10.0.0即可。

 



个人网站:分享客(https://sharerdiary.com/)
这个网站经常分享一些免费视频、免费音乐、实用工具和各种福利,感兴趣的朋友可以看看!

您的关注和点赞是我分享的动力,如有帮助请勿吝啬!ヽ( ̄▽ ̄)ノ



 

你可能感兴趣的:(Android疑难杂症,given,artifact,contains,androidx)