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

android.support.v4.content 切换到 androidx

编译报错:

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.

原本:

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

替换成:

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

如下例子:

子Module添加butterknife依赖:

implementation 'com.jakewharton:butterknife:10.2.1'

主Module添加butterknife注解处理器依赖: 

annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'

project的gradle文件

dependencies {
        classpath "com.android.tools.build:gradle:4.0.0"
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1'
 
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }