I am not able to build android project due to error of butterknife dependency.
ERROR
Execution failed for task ':app:javaPreCompileDebug'.
Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'. Failed to transform butterknife-compiler-8.6.0.jar (com.jakewharton:butterknife-compiler:8.6.0) 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/jordan/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.6.0/d3defb48a63aa0591117d0cec09f47a13fffda19/butterknife-compiler-8.6.0.jar. > Failed to transform '/Users/jordan/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.6.0/d3defb48a63aa0591117d0cec09f47a13fffda19/butterknife-compiler-8.6.0.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
Dependency in Gradle Build File in App Level
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0-beta02'
implementation 'com.melnykov:floatingactionbutton:1.3.0'
// implementation 'com.android.support:design:28.0.0'
// implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.jpardogo.materialtabstrip:library:1.0.6'
implementation 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
how should I resolve it ?
Please note that, as per official documentation the Butter Knife tool is now deprecated.
And they have recommended to switch to View Binding.
Hence, I request you to revisit your decision of using Butter Knife.
And in your gradle files, please ensure that below lines are added properly.
Add these changes and then click on File > Invalidate Cache and Restart in Android Studio.
android {
...
// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Dependency
dependencies {
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}
If you are using Kotlin, replace annotationProcessor with kapt.
And to use Butter Knife in a library, please follow the steps provided in section Library Projects inside official documentation