Butterknife: Android X support

Created on 15 May 2018  Â·  17Comments  Â·  Source: JakeWharton/butterknife

I've recently attempted to upgrade a project which uses Butterknife v8.8.1 to make use of the new Android X libraries by using the jetifier tool in Android Studio.

The project fails to compile as the generated _ViewBinding classes reference the old android.support.annotation. annotations which no longer exist.
There may also be additional issues I'm not aware of.

I was just wondering if there was a plan to migrate over to reference the new androidx package names in the generated code.

I'm not familiar with the Butterknife code, but let me know if there's anything I could contribute to the project to facilitate adding support.

Thank you for your time

Most helpful comment

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

All 17 comments

I got my app compiling by adding my own copies of the old package "android.support.annotation"s for @CallSuper and @UiThread.

@Retention(CLASS) @Target({METHOD,CONSTRUCTOR,TYPE,PARAMETER}) public @interface UiThread { }

@Retention(CLASS) @Target({METHOD}) public @interface CallSuper { }

Its a start, but then I hit further problems caused by this new jetifier process with other libraries. Guess we just have to be patient to wait for all these third party libraries to update.

I'll take a crack at this.

Merged

I'm sorry to say the error still persists.

Can you paste the stack trace? Are you building against a JAR cut from master?

It's from the import statement for the annotations which is found in the auto generated viewbinding files.

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

Um, in terms of production code how safe is this on a scale of 1-10 where 1="wtf are you doing this shouldn't be in the same room as a production app"

repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

This isn't working for me

Ok, now it works, just be sure to put it inside the repositories inside allprojects and not the one inside buildscript

Is it safe to use 9.0.0-SNAPSHOT version in production code?

In case like me you are confused about the gradle settings, you can find the complete solution to this as a stack overflow answer: https://stackoverflow.com/a/52308912/10224384

Please publish releases instead of snapshots or please leave a note. Shall I update README?

Hello
i get error when use androidX

`* What went wrong:
Could not resolve all files for configuration ':View:debugAnnotationProcessorClasspath'.

Failed to transform file 'butterknife-compiler-8.8.1.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
Failed to transform 'C:\Users\sadegh-Pc.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife-compiler\8.8.1\b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac\butterknife-compiler-8.8.1.jar' using Jetifier. Reason: 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.)
`

how to fix it?

@siavash-sajjad try butterknife 9+ first. then you'll need to add android.jetifier.blacklist=butterknife-compiler to gradle.properties to exclude butterknife compiler from being jetified

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

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

It works for me, thanks~

Was this page helpful?
0 / 5 - 0 ratings