In my app module's build.gradle, I have added
dependencies {
kapt('com.android.databinding:compiler:3.1.2')
...
}
but I'm still receiving the compiler warning for
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.1.2'.
Everything functions, I just hate having warnings hanging around.
Any help is much appreciated!
I had same warnings until I upgraded to the latest Android Gradle build plugin and Kotlin. Now they are gone. Here is the configuration I use.
project.gradle
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
}
}
module.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
...
dataBinding {
enabled = true
}
}
dependencies {
// no kapt declaration for databinding here
}
Hope it helps.
Add following in you app build.gradle
kapt "com.android.databinding:compiler:$android_plugin_version"
apply plugin: 'kotlin-kapt' // This one at top where plugin belong to
This will do the trick.
$android_plugin_version is version of com.android.tools.build:gradle in application build.gradle
Also, add this to your module build.gradle
android {
/// Existing Code
kapt {
generateStubs = true
}
}
You are missing apply plugin: 'kotlin-kapt' i think.
Related
I'm having a issue implement Hilt on android app...
The error is:
Expected #HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?
Project gradle file
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
//Hilt
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
}
}
Model gradle file
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
dependencies {
def dagger_hilt_android = "2.38.1"
implementation("com.google.dagger:hilt-android:$dagger_hilt_android")
kapt("com.google.dagger:hilt-android-compiler:$dagger_hilt_android")
}
It is an issue with Kotlin-gradle-plugin: 1.5.20 as mentioned here https://github.com/google/dagger/issues/2684. Try upgrading your plugin to 1.5.21, and it will work.
Mohmd.h.bh,
Try applying this plugin in your build.gradle of your Android Gradle
apply plugin: 'com.google.dagger.hilt.android'
android {
// .......
}
I don't think you need to change the version of the kotlin-gradle-plugin
Regards
I create such action before Android Studio bumblebee update and it was working fine.
fragment_button.setOnClickListener{
val action = FeedFragmentDirections.actionFeedFragmentToCountryFragment()
Navigation.findNavController(it).navigate(action)
}
But currently FragmentDirections are not accessible.I don't know where the problem comes from, I guess I can't manage to add navigation.
My build.gradle:
buildscript {
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0")
}
}
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle App
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
android {
dataBinding {
enabled = true
}
dependencies {
def navVersion = '2.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.navigation:navigation-fragment-ktx:$navVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navVersion"
}
I am retracting my previous answer!
After a bit of research, I realized the plugin block in your project-level build.gradle has the purpose of assigning dependencies that can be used by subprojects!
https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
Instead of declaring:
plugins {
...
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
...
}
You want to add id 'androidx.navigation.safeargs.kotlin' to the app-level plugins block so it can be used directly in your project.
Have you tried cleaning and re-building your project?
This may be a similar case to: Safeargs library doesnt generate direction class
If not, given that you are having trouble accessing the FragmentDirections class, it may be due to the default addition of the non-transitive R class property in the Bumblebee update.
In the gradle.properties[app] file you will find:
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
A good summation of the change and solutions to migrating R classes can be found here:
https://blog.blundellapps.co.uk/speed-up-your-build-non-transitive-r-files/
Best of luck!
I solved my problem by cleaning my project and rebuilding and adding.
Thank you very much for your support
Build.gradle
id ("androidx.navigation.safeargs")
build
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
def nav_version = "2.3.0"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.gms.google-services' version '4.3.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
okay so after bumblebee update gradle structure is changed.
but as mentioned above you can still add
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1")
}
}
before the plugins{} in project level gradle.
but the better alternative is to just use
id 'androidx.navigation.safeargs.kotlin' version '2.4.1' apply false
in plugins{} at project level gradle
both of above will cover first step you still need to add
id 'androidx.navigation.safeargs.kotlin'
in plugins{} at app level gradle
**if you had already added these but now they are not resolving or cannot access fragment direction the reason might be because you have update you gradle to 7.1.0 and safe-args-plugin:2.4.0 is not compatible with that so make sure to use safe-args-plugin:2.4.1 or 2.5.0-alpha01 with gradle 7.1.0
When I am using Hilt in android with Room I got this kinda error.
The full log is here:
home/someone/Desktop/Calculator/app/build/tmp/kapt3/stubs/debug/com/hamidjonhamidov/calculator/MyApplication.java:7: error: [Hilt]
public class MyApplication extends android.app.Application {
^
Expected #HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?
[Hilt] Processing did not complete. See error above for details./home/someone/Desktop/Calculator/app/build/tmp/kapt3/stubs/debug/com/hamidjonhamidov/calculator/ui/main/MainActivity.java:7: error: [Hilt]
Anyone knows solution for this?
I had this issue after upgrading Kotlin to 1.5.20.
Adding kapt.use.worker.api=false in gradle.properties worked for me the problem
Checkout dagger issue Support for Kotlin 1.5.20
Fortunately, there is simple solution.
In build.gradle in database scheme, we should use arguments += instead of arguments = .
defaultConfig{
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
Or/And in buld.gradle
You should apply plugin like:
apply plugin 'dagger.hilt.android.plugin'
This solved the problem)
UPDATE
Upgrade Hilt to v28.1.0 and Kotlin to v1.5.21 should fix this issue
OLD ANSWER
If you are on kotlin 1.5.20, answer of Mr-wil will decrease build speed as said in official doc:
To improve the speed of builds that use kapt, you can enable the
Gradle worker API for kapt tasks. Using the worker API lets Gradle run
independent annotation processing tasks from a single project in
parallel, which in some cases significantly decreases the execution
time.
Instead, set:
kapt {
javacOptions {
// These options are normally set automatically via the Hilt Gradle plugin, but we
// set them manually to workaround a bug in the Kotlin 1.5.20
option("-Adagger.fastInit=ENABLED")
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}
}
source
This generic error message can also appear in many circumstances. As a more generic check, ensure that your module's build.gradle file, ensure that you has:
apply plugin: 'dagger.hilt.android.plugin'
at the top.
This was due to a bug in Kotlin 1.5.20. It is fixed in Kotlin 1.5.21.
So all you need to do is to upgrade to the latest version of Kotlin.
I had the same problem and it seems like there is a problem in kotlin-kapt plugin. If you guys have tried out all the above answers and didn't get resolved, please try the below code in your build.gradle(module-level) outside the dependencies{} block
kapt {
javacOptions {
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}
}
in the build.gradle of your Android Gradle modules apply the plugin:
apply plugin: 'com.android.application'
apply plugin: 'dagger.hilt.android.plugin'
android {
// ...
}
see detail here
I'm still facing the same issue in 2022
I have solved the problem by adding
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
to build.gradle project and adding
id 'dagger.hilt.android.plugin'
to plugins in build.gradle app
In my case it solved by declaring plugin:
plugins {
id("dagger.hilt.android.plugin")
}
Check if all these are added.In my case I had missed adding one of the below line.
In project level build.gradle
buildscript {
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:2.44"
}
}
In app level build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
dependencies {
implementation "com.google.dagger:hilt-android:2.44"
implementation "androidx.hilt:hilt-common:1.0.0"
kapt "com.google.dagger:hilt-android-compiler:2.44"
}
-In app level build.gradle---add the following in newer versions
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
In project level build.gradle
buildscript {
ext.kotlin_version = "1.7.21"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Is it possible to use kotlin-allopen gradle plugin for android testing with mockito?
I've tried to add kotlin-allopen plugin to my build.gradle and define the annotation.
buildscript {
ext.kotlin_version = '1.0.6'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-allopen'
apply plugin: 'kotlin-android'
allOpen {
annotation("com.mycompany.OpenForTest")
}
And these for annotation itself
annotation class OpenForTest
It's not working for me. Maybe I miss something?
Yes you can.
Because it's a compiler plugin, you'll get all-open code after compilation.
So it should work with tests.
Don't worry.
Edit: according to the comment area, updating the kotlin plugin version seems work. Currently the newest version is 1.2.41.
First add the dependency in your build.gradle (project) file:
dependencies {
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
After that apply the plugin in your build.gradle (app mobdule) file:
apply plugin: 'kotlin-allopen'
Then specify the list of annotations that will make classes open:
allOpen {
annotation('com.example.myproject.OpenForTesting')
}
And use this annotation for every class which you want to be open
#OpenForTesting
Here is the Kotlin official documentation about All-open: https://kotlinlang.org/docs/reference/compiler-plugins.html
Hope this help
Recently i have updated Android studio from 1.5.1 to 2.0, after updation it asked me to use latest gradle i.e. com.android.tools.build:gradle:2.0.0
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath "com.android.databinding:dataBinder:1.0-rc1"
}
But after updating it is showing error with DataBinding plugin.
apply plugin: 'com.android.databinding' //error on this line
Error message :
Error:(2, 0) Cause: org/apache/commons/lang3/StringUtils
Open File
I have not used any apache library or any deprected apache classes.
UPDATE :
Harshad's answer helped me, so final conclusion is we don't need to add those plugins with gradle 2.0.+
classpath "com.android.databinding:dataBinder:1.0-rc1" remove
apply plugin: 'com.android.databinding' remove
This may be help you.
You can just remove these two lines of code:
apply plugin: 'com.android.databinding'
And this one in buildscript's dependencies:
classpath 'com.android.databinding:dataBinder:1.0-rc1'
Then add the dataBinding section to your build.gradle like this.
buildscript {
...
}
android {
...
dataBinding {
enabled = true
}
...
}
dependencies {
...
}