Butterknife fails with Gradle plugin 3.0 - android

I was using Butterknife in my project and after updating Android Studio and Gradle plugin to version 3.1.2, I can not continue using Butterknife.
Has anyone faced this problem and resolved it?
I have considered eliminating Butterknife and using Android Data Binding, is it a good option?

Just Add this dependency in your app.gradle file .its work fine with Android studio 3.1.2 .may be you have some other problem with gradle.
New Approach
In app.gradle
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
In project.gradle
classpath 'com.android.tools.build:gradle:3.1.2'
If you use these plugin in app.gradle then Remove these lines.
Old Approach
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
project.gradle
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'

I think,there is some other problem please use this dependency.
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

Related

How to setup lombok annotationProcessing in modern gradle 4.6 environment?

This is my setup:
AndroidStudio Lombok Plugin is installed
Enable Annotation Processing is checked in AndroidStudio Settings
Gradle wrapper is using version 4.6
I am using kotlin version 1.2.71
I am using com.android.tools.build:gradle:3.2.1
I tried "Invalidate cache / Restart AndroidStudio" after each change
Lombok dependencies are defined like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
dependencies {
compileOnly "org.projectlombok:lombok:1.18.2"
kapt "org.projectlombok:lombok:1.18.2"
}
When I build the app, I get the followin error:
Annotation processors must be explicitly declared now.
The following dependencies on the compile classpath are found to
contain annotation processor.
Please add them to the annotationProcessor configuration.
- lombok-1.18.2.jar (org.projectlombok:lombok:1.18.2)
I also tried this dependency setup:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
dependencies {
compileOnly "org.projectlombok:lombok:1.18.2"
annotationProcessor "org.projectlombok:lombok:1.18.2"
}
But then I get "cannot find symbol"-errors all over the place, because no getters/setters are generated by lombok.
Annotation processors must be explicitly declared now. The following
dependencies on the compile classpath are found to contain annotation
processor.
Please add them to the annotationProcessor configuration.
- lombok-1.18.2.jar (org.projectlombok:lombok:1.18.2)
Try adding it as annotationProcessor:
annotationProcessor 'org.projectlombok:lombok:1.18.2'
However, read this: Is it possible to use Lombok with Kotlin?
Lombok does not run on your source code, but on the AST. Anyway, it is
an annotation processor that is run at compile-time by the Java
compiler. The Kotlin compiler does not use these annotation
processors. See also the answer
https://stackoverflow.com/a/35530223/2621917 straight from the horse’s
mouth.

Warning "Kotlin plugin version is not the same as library version" (but it is!)

I have an Android studio project in which I have added a Java library module, which I call core. My three Gradle build files look like this.
project/build.gradle
buildscript {
ext.kotlin_version = '1.2.40'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
core/build.gradle
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
...
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android { ... }
dependencies {
implementation project(':core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation 'junit:junit:4.12'
}
The problem I have is that, in core/build.gradle, the kotlin-stdlib-jdk7 line is giving me the warning Plugin version (1.2.40) is not the same as library version (jdk7-1.2.40). I have tried changing it to:
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.40"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
But the warning is still there. The build still runs successfully, and I know I can surpress the warning without any problems and ignore it, but I really want to know why this is happening and how I can get rid of it. I am using Android Studio 3.0.1. Does anyone know of a solution to this?
Starting from Kotlin 1.4 dependency on the standard library added by default:
You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.
The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.
For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script.
Link to Kotlin Gradle plugin documentation.
This is a bug in the Kotlin plugin. I've filed an issue in the Kotlin issue tracker. You can simply ignore the message.
EDIT: JetBrains marked the issue as a duplicate of KT-23744 "Kotlin library and Gradle plugin versions are different" inspection false positive for non-JVM dependencies".
Solution, in my case, I got rid of the line
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
in the app level Gradle and the warning disappear
As the Kotlin page says :
" You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.
The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.
For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script."
You might be facing this after upgrading kotlin version, Actually, older versions are still in your caches, In this case, you need to do the following steps
Invalidate cache
Clean project
Sync project with gradle files
Now your warning will be gone.
[build.gradle(Module)]
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.10'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10'
...
}
My project automatically added
(implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10')
to the project build file. After moving the implementation to the module file, and removing
(implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.10')
the warning went away.
The 'stdlib' needs to match the 'stdlib-jdk' in the module file.
I faced the same issue while using Firebase with Kotlin.
I had to upgrade all the dependencies with their latest version available.
Note: have your kotlin-reflect and kotlin-stdlib versions same.
after many days i have solve the issue
Update the kotlin_version to '1.4.32'
In my case, I set the version number for all modules the same as gradle of app as latest version, and problem resolved.

"Execution failed for task: ':app:javaPreCompileDebug' " in Android Studio 3.0.1

I get the following errors when trying to execute my project:
Error:Execution failed for task ':app:javaPreCompileDebug'.
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain
annotation processor. Please add them to the annotationProcessor
configuration.
- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1) Alternatively, set
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath
= true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See
https://developer.android.com/r/tools/annotation-processor-error-message.html
for more details.
Please don't mark this question as duplicate as other question regrading this, here, is for lombok, which I'm not using.
As the error says, you need to use annotationProcessor in your app build.gradle. Afaik, you need to upgrade the ButterKnife library to version 8.8.1. You need to use something like this:
dependencies {
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
Please check Android studio 3.0 butterknife error issue for the details.
Going through the following process makes my problem solved.
In the build.gradle(module app)
apply the plugin:
apply plugin: 'com.jakewharton.butterknife'
Add the following lines in the dependencies section:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
implementation 'com.jakewharton:butterknife:8.7.0'
In the build.gradle(Project:projectName), add the classPath in the dependencies like this :
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
It will fix this issue.
In case if not then add maven:
maven {
url 'https://maven.google.com'
}
Adding these two line in app/build.gradle
dependencies {
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
It worked for me

ButterKnife and AnnotationProcessor

Based on ButterKnife lib, I upgrade to new version 8.5.1. I used
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
But it warns me in my Android Studio 2.3. And ButterKnife doesn't work(cannot bind view).
Warning:Using incompatible plugins for the annotation processing:
android-apt. This may result in an unexpected behavior.
I change annotationProcessor to apt (I had plugin apply plugin: 'com.neenbedankt.android-apt' in my gradle) and it works as old version without warning (I used apt for old version 8.4.0)
compile 'com.jakewharton:butterknife:8.5.1'
apt 'com.jakewharton:butterknife-compiler:8.5.1'
I think Android Studio 2.3 is incomatible with Annottaion processing. I searched and found to enable Annotation Processors in Android Studio 2.2 but cannot find in Android Studio 2.3
Settings > Build, Execution, Deployment > Compiler > Annotation
Processors
Anyone can explain this problem? Thanks!
kindly
//apply plugin: 'com.neenbedankt.android-apt' <--remove this
apply plugin: 'com.jakewharton.butterknife' <-- add this
dependencies {
//classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' <-- remove this
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1' <-- add this
}
then in app dependencies
//Butterknife
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
Simple and easy. Just add these lines to your build.gradle
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
An annotation processor was included in the Gradle version 2.2, so there is no reason to provide an extra one.
Check my updated answer here.

Android Studio Warning: Using incompatible plugins for the annotation processing

After update Android Studio to 2.3 version I have warning:
Warning:Using incompatible plugins for the annotation processing:
android-apt. This may result in an unexpected behavior.
Any solutions? My app stopped working...
Your app level gradle dependencies should include (as per butterknife website instructions):
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
You can remove the line :
apply plugin: 'com.neenbedankt.android-apt'
Annotation Processing became available in Android Gradle plugin (2.2 and later) so there is now no need to use the above plugin anymore if using this version of gradle or greater.
If you'd like to know how to turn annotation processing off and on and AS the setting is in :
Settings > Build, Execution, Deployment > Compiler > Annotation Processors
In my project I use, among other things, Butter Knife and Immutables. After adding Immutables I got the following warning
Warning:Using incompatible plugins for the annotation processing:
android-apt. This may result in an unexpected behavior.
and ButterKnife stopped working.
My configuration was as follows:
build.gradle (Project: MyApplication)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
build.gradle (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
...
dependencies {
...
// Butter Knife
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
// Immutables
apt 'org.immutables:value:2.4.4'
provided 'org.immutables:value:2.4.4'
provided 'org.immutables:builder:2.4.4'
provided 'org.immutables:gson:2.4.4'
}
After changing
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
to
apt 'com.jakewharton:butterknife-compiler:8.5.1'
warning disappeared and everything works as it should.
UPDATE
As Mark said, an annotation processor was included in the Gradle version 2.2 , so there is no reason to provide an extra one.
So:
1) Remove the class path for the apt from the build.gradle (Project: MyApplication)
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
2) Remove the plug in from the build.gradle (Module: app)
apply plugin: 'android-apt'
3) Change the dependencies from apt to the new annotationProcessor
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
annotationProcessor 'org.immutables:value:2.4.4'
To add to #Milan's answer, if you used the hotchemi permissiondispatcher library in your app level gradle file then you should replace it as follows:
Replace
apt 'com.github.hotchemi:permissionsdispatcher-processor:2.4.0'
with
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.4.0'
At Project Gradle buildscript --> dependencies block, remove the second classpath line :
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
And at app Gradle dependencies block, change these lines, use api and annotationProcessor :
api 'com.google.dagger:dagger:2.19'
annotationProcessor 'com.google.dagger:dagger-compiler:2.19'
Also, remove this one:
//apply plugin: 'com.neenbedankt.android-apt'

Categories

Resources