- androidx:android.support.xxx 包过于混乱,官方整理后产物,
- support-v4:4在这里指的是Android API版本号,库中提供的API会向下兼容到Android 1.6系统。
- support-v7:7同理,库中提供的API会向下兼容到Android 2.1系统。
为项目添加butterknife功能的时候,因为使用了androidx 碰到问题异常报错如下:
Execution failed for task ':app:javaPreCompileDebug'.
> Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'.
> Failed to transform butterknife-compiler-8.8.1.jar (com.jakewharton:butterknife-compiler:8.8.1) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /Users/mahui/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar.
> Failed to transform '/Users/mahui/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar' using Jetifier. Reason: AmbiguousStringJetifierException, message: 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.. (Run with --stacktrace for more details.)
This is a known exception, and Jetifier won't be able to jetify this library.
Suggestions:
- If you believe this library doesn't need to be jetified (e.g., if it already supports AndroidX, or if it doesn't use support libraries/AndroidX at all), add android.jetifier.blacklist = {comma-separated list of regular expressions (or simply names) of the libraries that you don't want to be jetified} to the gradle.properties file.
- If you believe this library needs to be jetified (e.g., if it uses old support libraries and breaks your app if it isn't jetified), contact the library's authors to update this library to support AndroidX and use the supported version once it is released.
If you need further help, please leave a comment at https://issuetracker.google.com/issues/140747218.
报错原因是没有:android.support.v4.content.
为解决这个问题:butterknife 也对应升级。
最新butterknife版本已升级到:10.2.3
处理方式:
1:添加:android.support.v4.content包依赖
implementation 'com.android.support:support-v4:28.4.1'
2:添加
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
3:更新butterknife
implementation "com.jakewharton:butterknife:10.2.3"
annotationProcessor "com.jakewharton:butterknife-compiler:10.2.3"