How to get rid of Incremental annotation processing requested warning? - android

I have just started using android development and trying to use Room library. Since yesterday I am facing this warning message
w: [kapt] Incremental annotation processing requested, but support is
disabled because the following processors are not incremental:
androidx.lifecycle.LifecycleProcessor (NON_INCREMENTAL),
androidx.room.RoomProcessor (NON_INCREMENTAL).
I have tried to research and fix but unable to avoid this error here is my grale.build file. please suggest/advice what I am doing wrong.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "ps.room.bookkeeper"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":"$projectDir/schemas".toString()]
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// life cycle dependencies
def lifecycle_version = "2.0.0"
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
kapt "android.arch.lifecycle:compiler:$lifecycle_version"
//Room dependencies
//def room_version = "2.1.0"
implementation 'android.arch.persistence.room:runtime:2.1.0'
kapt 'android.arch.persistence.room:compiler:2.1.0'
//annotationProcessor 'android.arch.persistence.room:compiler:2.1.0'
// implementation "android.arch.lifecycle:extensions:$room_version"
// kapt "android.arch.persistence.room:compiler:$room_version"
// androidTestImplementation "android.arch.persistence.room:testing:$room_version"
//implementation 'androidx.room:room-runtime:2.1.0'
//annotationProcessor 'androidx.room:room-compiler:2.1.0'
}

Just add this line to you gradle.properties:
kapt.incremental.apt=true

The real problem is that incremental processing makes things faster, but if any of the annotation processors are non incremental, none of them will be actually processed in that way.
What's the purpose of incremental processing?
From version 1.3.30+, incremental processing allowed modules not to be entirely processed again each time a change occurs, giving the build process a better performance:
The main areas of focus for this release have been around
Kotlin/Native, KAPT performance, as well as improvements for IntelliJ
IDEA.
From Kotlin documentation:
Annotation processors (see JSR 269) are supported in Kotlin with the
kapt compiler plugin. In a nutshell, you can use libraries such as
Dagger or Data Binding in your Kotlin projects.
How to fix Room Incremental Processing?
Room incremental annotation processor is disabled by default. This is a known issue and it's described here. They intend to fix it on version 2.2.0. You can just wait for the update or you can enable that to get rid of the warning by setting:
in gradle.properties file:
kapt.incremental.apt=true
(optional steps)
to allow databinding to be incremental:
android.databinding.incremental=true
for faster builds:
kapt.use.worker.api=true
if only a few changes are made, the build time greatly decreases:
kapt.include.compile.classpath=false
(back to the subject)
in your project build.gradle, add the necessary dependencies (Groovy):
dependencies {
...
implementation "androidx.room:room-runtime:2.2.0-rc01"
annotationProcessor "androidx.room:room-compiler:2.2.0-rc01"
}
and
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental":"true"]
}
}
}
}
Kotlin DSL version:
dependencies {
...
implementation("androidx.room:room-runtime:2.2.0-rc01")
kapt("androidx.room:room-compiler:2.2.0-rc01")
}
and
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = mapOf("room.incremental" to "true")
}
}
}
}
October 9, 2019
androidx.room:room-*:2.2.0 is released.
Gradle Incremental Annotation Processor: Room is now a Gradle
isolating annotation processor and incrementability can be enabled via
the processor option room.incremental.
Latest update:
For the newest Kotlin DSL versions, please use
javaCompileOptions {
annotationProcessorOptions {
arguments["room.incremental"] = "true"
}
}

There is a bug in kotlin-gradle-plugin version of 1.3.50 as #Necrontyr mentioned. Just downgrade the kotlin_version in build.gradle(Project) to 1.3.41.

From Room documentation:
"Room has the following annotation processor options...room.incremental: Enables Gradle incremental annotation proccesor."
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"true"]
}
}
}
}
Be sure to update the room version to 2.2.x or higher.

Enable Kapt Incremental annotation processing requeste
Use Kotlin 1.3.31 or newer Kotlin 1.3.30 released
In your android kotlin project gradle.properties file
# Enable Kapt Incremental annotation processing requeste
kapt.incremental.apt=true
# Enable android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC)
android.databinding.incremental=true
# Decrease gradle builds time
kapt.use.worker.api=true
# turn off AP discovery in compile path, and therefore turn on Compile Avoidance
kapt.include.compile.classpath=false
# Enable In Logcat to determine Kapt
kapt.verbose=true

Here is a list of things you can do to fix this and significantly decrease your build times while you're at it.
In your build.gradle (module) file:
android {
...
defaultConfig {
...
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
arg("room.incremental", "true")
arg("room.expandProjection", "true")
}
}
}
...
}
In your gradle.properties file:
kapt.incremental.apt=true // enabled by default on 1.3.50+
kapt.use.worker.api=true // faster builds
kapt.include.compile.classpath=false // near instant builds when there are few changes
android.databinding.incremental=true
android.lifecycleProcessor.incremental=true
//add your specific library if it supports incremental kapt

A lot of the other answers here cover up the error or disable incremental processing instead of actually making it work the way you want.
You can enable incremental processing for your specific library in the gradle.properties file. Just add these settings, or whichever one matches the library that throws the error:
android.databinding.incremental=true
android.lifecycleProcessor.incremental=true

If it's complaining that "Incremental annotation processing requested, but support is disabled because the following processors are not incremental", then setting "kapt.incremental.apt" to "true" (mentioned in a different answer) in gradle.properties is counter-intuitive. You need to set it to "false". That did it for me.

What you really should do is to implement these lines of code in your buildConfig tag in your build.gradle, module app:
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.schemaLocation" : "$projectDir/schemas".toString(),
"room.incremental" : "true",
"room.expandProjection": "true"]
}
}

I'm using AndroidX, but It guess it's the same for android.arch.lifecycle. For me it simply helped replacing this:
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
... with this:
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
So if you're using android.arch.lifecycle it might have the same effect replacing this:
kapt "android.arch.lifecycle:compiler:$lifecycle_version"
... with this:
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
Be aware that this only works if you're using Java 8 and that you also should remove OnLifecycleEvent annotations for LifecycleObserver classes and let those observers implement DefaultLifecycleObserver instead.
Changing to this method is also recommended in the build.gradle depencies shown here.

Above answers can be useful, but what helped me is reducing the kotlin_version in build.gradle(Project) to 1.3.41 and building the project. This will allow you to see if there is any issue with your entity model.
Mine was, I forgot to annotate #PrimaryKey. Your may be something different. Kotlin 1.3.41 allows to to see those issues. Fix those issues and revert back your kotlin_version to the previous one.

Starting from version 1.3.30, kapt supports incremental annotation processing as an experimental feature. Yet, starting from version 1.3.50, incremental annotation processing is enabled by default.
So, you must add kapt.incremental.apt=true line to your gradle.properties file to enable incremental annotation processing if your kapt version is greater than or equal to 1.3.30 and lower than 1.3.50. Otherwise; you don't have to set kapt.incremental.apt to true to enable it. Although, you can set it to false to disable it if you like.
Besides all of that; incremental annotation processing requires incremental compilation to be enabled as well. So, you must add kotlin.incremental=true line to your gradle.properties file to be able to benefit from incremental annotation processing feature.
Note that incremental annotation processing option of Room is ON by default starting from version 2.3.0-alpha02. It means you don't have to set room.incremental argument to true if your version of the library is greater than or equal to this. To learn more, see issue #112110217.
Also note that if you're using Android Gradle Plugin 3.6.x or newer, incremental annotation processing option is ON by default for Data Binding. So, you don't have to add android.databinding.incremental=true line to your gradle.properties file. To learn more, see issue #110061530.

This can also be caused by character problems such as "İ" on the databinding side when the system language is a non-English language. In such a case, using the computer system language in English will solve the problem.

for me this is happen when my entity with primay key and #NonNull annotation, but type field still using nullable (?). so, just remove this ?, the problem is gone
data class TvEntity(
#PrimaryKey
#NonNull
#ColumnInfo(name = "tvId")
var tvId: String?,

Related

Can Not Perform Copy-Paste in Android Studio

I have faced two main problems in Android Studio. First of all I can not perform copy-paste and cut-paste (ctrl+c - ctrl+v - ctrl+x) abilities in some classes. To fix that problem, I click "invalide caches/restarts", but it breaks down again immediately.
Second problem is (I think it is related to the first problem) compiler does not recognize already defined methods and attributes. Auto suggestion etc. does not work.
The steps I've taken to try to fix the problem are;
File -> invalide caches/restarts,
File -> Power Save Mode -> Disable,
Close all opened tabs and fresh restart,
File -> Sync Project with Gradle Files,
File -> Sync with File System,
Delete JDK and reinstall,
Delete Android Studio and reinstall,
Delete already downloaded SDK files and ".Android" folder,
Disable and delete all plugins.
Checked copy-paste keymap in File -> Settings -> Keymap
Pulled the project from bitbucket to different 2 computers
Created new project, copy whole project classes with NotePad++ to
new Project
Try to convert all Java codes to Kotlin, cannot convert
Here is my system specifications; Windows 10 Home Single Language (TR), version 1909. 16 GB ram. Android Studio 3.5.3 and Gradle Version 3.5.3
I have read all post about the same problem but there is no luck (The posts are only about MAC and Linux platform).
UPDATE 1.0 ->
I have discovered that some classes cannot do the operations described above, but some classes can.
I realized that, There are no icons for classes that cannot do the operations I have described above. (Sometimes magically appears "J" icons and when I clicked another class, this J icon disappears immediately.) I think gradle or file system of Android Studio does not recognize these files as classes.
UPDATE 2.0 ->
I have noticed that when I clicked the Structure section of DuoFragment (Which has 500+ lines codes and one of the uncompiled class) cannot load anything. Is DuoFragment size is bigger to process?
Also when I checked the Build section, some processes cannot run (I do not know if this is normal or not);
Task :app:compileDebugAidl NO-SOURCE,
Task :app:compileDebugRenderscript NO-SOURCE,
Task :app:processDebugJavaRes NO-SOURCE
UPDATE 3.0 ->
Here are my Gradle files.
Project Level Gradle file :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level Gradle file.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.lotusif.dump2"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.core:core:1.1.0'
// material widgets
implementation 'com.google.android.material:material:1.2.0-alpha03'
// progress bar with text
implementation "com.github.skydoves:progressview:1.0.3"
// sequence progress
implementation 'com.github.transferwise:sequence-layout:1.0.11'
// flash bar
implementation 'com.andrognito.flashbar:flashbar:1.0.2'
// toggle - switch button
implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'
// Custom Toast message
implementation 'com.github.GrenderG:Toasty:1.4.2'
// liquid effect bar
implementation 'com.mikhaellopez:circularfillableloaders:1.3.2'
// bubble tab bar
implementation 'com.fxn769:bubbletabbar:1.0.3'
//glide image library
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
// scaling layout
implementation 'com.github.iammert:ScalingLayout:1.2.1'
// lottie animation
implementation 'com.airbnb.android:lottie:3.3.1'
//Gson
implementation 'com.google.code.gson:gson:2.8.6'
//RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.daimajia.easing:library:2.1#aar'
implementation 'com.daimajia.androidanimations:library:2.3#aar'
//retrofit
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
}
UPDATE 1.0 Images
UPDATE 2.0 Images
UPDATE --> There is a bug in Kotlin libraries with Windows 10 Single Language Turkish. (Maybe some of other Single Language Windows distributions have same issue, I haven't known yet.) Kotlin's some libraries cannot work on Turkish operating system. I solved this problem with installing Windows 10 Pro English.
Other developers who use Windows 10 Single Language Turkish faces same problem with different angles. (Example1 and Example2)
OLD ANSWER
TL;DR -> Problem is about third party libraries that are written with Kotlin. I have converted my Java project to Kotlin and all problematic third party libraries work well. Problem is about Java - Kotlin conflict.
I would like to share how I solved the problem for those who will face such problems later.
I did all the steps I mentioned above one by one but I could not find any solution and I decided to examine my third party libraries.
First of all, I disabled all third party libraries and looked at the status of my classes that did not recognize already defined methods and attributes. After disabling third party libraries and making Rebuild Project and Sync Gradle, the Auto Suggestion feature of those corrupted classes started working again.Then, uncovering which third-party libraries were problematic, I activated those third-party libraries one by one. I found which third party libraries broke my project.
There were 4 third party libraries that broke my project : StickySwitch, ProgressView, SequenceLayout and Flashbar. When I removed those libraries, everything worked right. After removed the libraries, my Gradle file was as below.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.lotusif.dump2"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.core:core:1.1.0'
// material widgets
implementation 'com.google.android.material:material:1.2.0-alpha03'
// progress bar with text BUGGY!
// implementation "com.github.skydoves:progressview:1.0.3"
// sequence progress BUGGY !
// implementation 'com.github.transferwise:sequence-layout:1.0.11'
// flash bar BUGGY !
// implementation 'com.andrognito.flashbar:flashbar:1.0.2'
// toggle - switch button BUGGY !
// implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'
// Custom Toast message
implementation 'com.github.GrenderG:Toasty:1.4.2'
// liquid effect bar
implementation 'com.mikhaellopez:circularfillableloaders:1.3.2'
// bubble tab bar
implementation 'com.fxn769:bubbletabbar:1.0.3'
// android chart library
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
//glide image library
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
// scaling layout
implementation 'com.github.iammert:ScalingLayout:1.2.1'
// lottie animation
implementation 'com.airbnb.android:lottie:3.3.1'
//Gson
implementation 'com.google.code.gson:gson:2.8.6'
//RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.daimajia.easing:library:2.1#aar'
implementation 'com.daimajia.androidanimations:library:2.3#aar'
//retrofit
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
}
So, what was the common feature of those libraries that corrupt my project? My project was written with Java but that libraries were written with Kotlin. One second, cannot I use Kotlin libraries in my Java project? Yes, I can. I have to add android.useAndroidX=true and android.enableJetifier=true in my gradle.properties, that is it. But what if I have already added those lines in my gradle.properties and it has not worked?
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
I have not understood why kotlin libraries cannot work with my Java project. As you can see in my Gradle file, I am using apply plugin: 'kotlin-android' and apply plugin: 'kotlin-android-extensions' for Kotlin support.
How I have rescued my project? There were 2 available options as I knew. While first method was that to removed those 4 third party libraries and could not use them, second one that to convert all Java classes to Kotlin classes (I tried it before but it did not work until disabled all third party libraries). I chose to convert all Java classes to Kotlin classes. Thus, I was able to use 4 third party libraries which were mentioned above.
It took me 30 days to solve this problem. Now, I am working on Kotlin language. As a result, my project is running without any problem.

Annotation processors must be explicitly declared now. - butterknife-7.0.1.jar (butterknife-7.0.1.jar)

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 (butterknife-7.0.1.jar)
- 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.
I have given in build.gradle
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
and also given dependencies annotationProcessor com.google.dagger:dagger-compiler:2.0
Can any one please help me to solve this?

Error:Execution failed for task ':app:kaptDebugKotlin'

I'm new to using Kotlin and trying to set it up with Dagger2, I've seen some few examples but none of them seem to work for me.
I keep getting this
Error:Execution failed for task ':app:kaptDebugKotlin'.
Internal compiler error. See log for more details
I have my build.gradle (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.exampleapp"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
kapt {
generateStubs = true
}
dexOptions {
javaMaxHeapSize "2048M"
}
}
ext {
supportLibVer = '25.0.0'
daggerVer = '2.8'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Support lib
compile "com.android.support:appcompat-v7:${supportLibVer}"
kapt "com.google.dagger:dagger-compiler:${daggerVer}"
compile "com.google.dagger:dagger:${daggerVer}"
provided "javax.annotation:jsr250-api:${javaxVer}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
mavenCentral()
}
Run your application with ./gradlew clean build command to see what's exactly wrong with your code. Just paste it into the Terminal in Android Studio.
If you are using the Room database and getting a KAPT error, just check your
Database declarations
Data Access Object declarations
Data class fields
It's a problem arising due to improper usage of annotations of Room.
For more information use your build logs.
I faced this problem for a while. What helped me a lot was reading the build tab because it gave the reasons the library was failing.
Here is the tab
I had many problems,
1. I haven't added the new entity I created into the #Database annotation
2. I haven't added the #Dao annotation in my interface
3. I haven't updated some variables names that was wrote in a #Query annotation
So I had to kill problem by problem, finally it could run later.
In Addition, I was cleaning my project and rebuilding to ensure code doesn't get stuck. Also close and open Android Studio.
Futhermore, you can check this answer to help you find the error enable more log on error
In my case I replaced this
implementation 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.27'
by
implementation 'com.google.dagger:dagger:2.27'
annotationProcessor "com.google.dagger:dagger-compiler:2.27"
and solved the problem
I faced this problem for a while. My mistake was using private access specifier with #Inject field.
If you are using Dagger then check for #Inject private fields or to know the exact cause add this as Command-line options:
--stacktrace --info --scan
On Mac, go to Android Studio > Preferences > Build, Execution, Deployment > Compiler
On Windows, go to File > Settings > Build, Execution, Deployment > Compiler
In my case, I forgot to add the room db entities to the database
#Database(version = 1,
entities = [DummyEntity::class]
)
Issue can be connected with Room and Kotlin 1.4.10.
Try to change android.arch.persistence to androidx.room for Room dependencies:
Use
kapt "androidx.room:room-compiler:$roomVersion"
instead of
kapt "android.arch.persistence.room:compiler:$roomVersion"
If You are using Hilt and Field Injection Then Remove Private From Field Injected Object this worked For me
#Inject
private lateinit var helper: Helper
to
#Inject
lateinit var helper: Helper
Worked for me:
I also had the same problem and solved it by adding this to gradle.properties
org.gradle.java.home=<go to project structure, copy JDK location and past here>
This ensures that gradlew uses the same JDK as Android Studio
The issue is probably related to the use of Room. I used the command Łukasz Kobyliński suggested in his comment
./gradlew clean build
and in my case I had to add a converter for Date type.
You can find the converter in the official docs: https://developer.android.com/training/data-storage/room/referencing-data#type-converters
I have solved this problem. In my case, there were irrelevant dagger
dependencies
that the IDE did not notify me about:
implementation 'com.google.dagger:dagger:2.35.1'
kapt 'com.google.dagger:dagger-compiler:2.28'
After updating them, the problem disappeared and it became possible to use the
latest version of Kotlin!
implementation 'com.google.dagger:dagger:2.37'
kapt 'com.google.dagger:dagger-compiler:2.37'
Just Replace kept Keyword to annotationProcessor and everything works fine.
my mistake was using suspend when then function returns LiveData.Room's coroutines integration brings ability to return suspend values but when the value itself is asnyc, there is no reason to use it.
i changed :
#Delete
suspend fun Delete(premiumPackageDBEntity: PremiumPackageDBEntity)
#Query("SELECT * FROM available_premium_package ")
suspend fun GetAll(): LiveData<List<PremiumPackageDBEntity>>
to :
#Delete
suspend fun Delete(premiumPackageDBEntity: PremiumPackageDBEntity)
#Query("SELECT * FROM available_premium_package ")
fun GetAll(): LiveData<List<PremiumPackageDBEntity>>
and the problem solved.
In my case, I forgot to add newly created entities into "entities" section of #Database declaration using Room library.
--stacktrace --info --scan commandline options are a great help to find the exact cause.
I just faced a similar bug. If you're using an old dependency for Room, update and rebuild your project.
I faced similar problem when setting up dagger2. It was finally resolved when I changed this line:
kapt "com.google.dagger:dagger-compiler:${daggerVer}"
to this
annotationProcessor "com.google.dagger:dagger-compiler:${daggerVer}"
For me I deleted these folders.
.gradle
.idea
Close android studio , delete the folders and reopen the project
//implementation "androidx.room:room-runtime:2.4.2"
kapt "androidx.room:room-compiler:2.2.1"
//kapt "android.arch.persistence.room:compiler:2.4.2"
implementation "androidx.room:room-ktx:2.2.1"
//annotationProcessor "androidx.room:room-compiler:2.4.2"
I didn't use the ones I used. My problem was solved when I used these two. We get a kaptDebug error because there is no match with the Room. My problem was related to the implement.
if all that tasks are not work, just run your app. You will see error log clearly.
First change
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
to
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Now you have to tweak your project Gradle file and update the version of Kotlin being used which should be something like below:
ext {
kotlin_version = '1.3.10'
gradleVersion = '3.1.0'
}
I got the same error and solved it simply by following these steps
1- open File menu -> then choose Project Structure or press Ctrl+Alt+Shift+s
2- open Modules from the left
3- In Source Compatibility press the drop down menu and choose Java 8 or 1.8
4- In Target Compatibility press the drop down menu and choose Java 8 or 1.8
5- press ok then sync and rebuild your project or run it
In my case build.gradle
replaced
id 'kotlin-android-extensions' to
id 'kotlin-parcelize'
as it said on build
added
buildFeatures {
viewBinding true
}
also had a few syntax mistakes like forgetting : at Dao
#Query("SELECT * FROM table_satis WHERE satisId ==:satisID")
In my case I'm using ViewBinding instead of DataBinding. And when I got the same problem I solved it with adding plugin apply plugin: 'kotlin-parcelize' to gradle.
try add to gradle.properties:
kapt.use.worker.api=false
kapt.incremental.apt=false
I wrote accidentally #EntryPoint instead of #AndroidEntryPoint. Changing that error was fixed.
I faced a similar problem. It was resolved when I changed this line:
ext.kotlin_version = "1.5.10"
to
ext.kotlin_version = "1.4.10"
In some of the Cases if the id of the View is incorrect it always shows this error.Recheck if the id of the view is correct.
In my case, i just updated the recently added dependencies(a newer version was available), and it worked for me.
In my case, I was using
kapt "com.github.bumptech.glide:compiler:$version_glide"
without applying the implementation.
implementation "com.github.bumptech.glide:glide:$version_glide"
You should check all kapt dependencies in the build.gradle (Module), not just glide
What worked for me was to add all of these dependencies:
room_version = '2.4.3'
// Room
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"

Setting Explict Annotation Processor

I am attempting to add a maven repository to my Android Studio project.
When I do a Gradle project sync everything is fine. However, whenever I try to build my apk, I get this 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.
- classindex-3.3.jar
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.
The link included (https://developer.android.com/r/tools/annotation-processor-error-message.html) in the error 404s so its of no help.
I have enabled annotation processing in the android studio settings, and added includeCompileClasspath = true to my Annotation Processor options. I have also tried adding classindex, classindex-3.3 and classindex-3.3.jar to Processor FQ Name, but that did not help either.
these are the lines I have added to the default build.gradle under dependecies:
dependencies {
...
compile group: 'com.skadistats', name: 'clarity', version:'2.1.1'
compile group: 'org.atteo.classindex', name: 'classindex', version:'3.3'
}
Originally I just had the "clarity" one added, because that is the one I care about, but I added the "classindex" entry in the hopes that it would fix it. Removing "clarity" and keeping "classindex" gives me the exact same error.
I'm not all too familiar with gradle/maven so any help would be appreciated.
To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.
For example:
annotationProcessor 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
This link describes it in detail: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#annotationProcessor_config
Relevant snippet included for completeness.
Use the annotation processor dependency configuration
In previous versions of the Android plugin for Gradle, dependencies on
the compile classpath were automatically added to the processor
classpath. That is, you could add an annotation processor to the
compile classpath and it would work as expected. However, this causes
a significant impact to performance by adding a large number of
unnecessary dependencies to the processor.
When using the new plugin, annotation processors must be added to the
processor classpath using the annotationProcessor dependency
configuration, as shown below:
dependencies {
...
annotationProcessor 'com.google.dagger:dagger-compiler:' }
The plugin assumes a dependency is an annotation processor if its JAR
file contains the following file: META-
INF/services/javax.annotation.processing.Processor. If the plugin
detects annotation processors on the compile classpath, your build
fails and you get an error message that lists each annotation
processor on the compile classpath. To fix the error, simply change
the configuration of those dependencies to use annotationProcessor. If
a dependency includes components that also need to be on the compile
classpath, declare that dependency a second time and use the compile
dependency configuration.
I was with a similar error. I follow the instructions on the Google link and it works.
try to add the follow instructions to your app gradle file:
defaultConfig {
applicationId "com.yourdomain.yourapp"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = false
}
}
}
Attention to -> includeCompileClasspath false
Add this code to your gradle app
defaultConfig{
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
I found the solution here https://github.com/JakeWharton/butterknife/issues/908
Simply update your butter knife with Annotation processor
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
i hope it's help you
Add this in defaultConfig
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
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'
}
If you have dependencies on the compile classpath that include annotation processors you don't need, you can disable the error check by adding the following to your build.gradle file. Keep in mind, the annotation processors you add to the compile classpath are still not added to the processor classpath.
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
}
If you are experiencing issues migrating to the new dependency resolution strategy, you can restore behavior to that of Android plugin 2.3.0 by setting includeCompileClasspath true. However, restoring behavior to version 2.3.0 is not recommended, and the option to do so will be removed in a future update.
See here https://developer.android.com/r/tools/annotation-processor-error-message.html for more details
If nothing works from above answers add following step as well, specially for new update of Android Studio 3.0.1:
Android Studio 3.0.1:
Add this to your app.gradle file in dependencies:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
In previous versions of the plugin, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.
When using the Android plugin 3.0.0, you must add annotation processors to the processor classpath using the annotationProcessor dependency configuration, as shown below:
dependencies {
...
annotationProcessor 'com.google.dagger:dagger-compiler:<version-number>'
implementation 'com.google.dagger:dagger-compiler:<version-number>'
}

apt dependency scope in Android gradle - what is it used for?

What is the apt dependency scope in android gradle files i see sometimes ?
An example looks like this?
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "org.ligboy.test.card.module1"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
final DAGGER_VERSION = '2.0.2'
dependencies {
compile "com.google.dagger:dagger:${DAGGER_VERSION}"
apt "com.google.dagger:dagger-compiler:${DAGGER_VERSION}"//what is this scope
provided 'org.glassfish:javax.annotation:10.0-b28'
}
and in the top level build.gradle file it has this global dependency:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
Notice in the dependencies section there is a apt scope ? i only know of compile, package and provided scope. compile
includes the dependency at compile time and in your package, provided says only include the library at compile time and discard it at
package time so its not included in final build. and Package is the reverse, it includes the dependency in the package and not at compile time.
But what is apt dependency scope which we obviously need the com.neenbedankt.android-apt for it to work so i know its android based.
update:
why cant i use provided dependency scope instead of apt scope ? How do they differ ?
i created a tutorial on dagger dependency scopes for those who need more info.
From the android-apt project page:
The android-apt plugin assists in working with annotation processors in combination with Android Studio. It has two purposes:
Allow to configure a compile time only annotation processor as a dependency, not including the artifact in the final APK or library
Set up the source paths so that code that is generated from the annotation processor is correctly picked up by Android Studio.
You are using Dagger, which uses annotation processing to generate code. The annotation processing code shouldn't be included in the final APK, and you want the generated code to be visible to Android Studio. android-apt enables this behavior.
This sounds very similar to the provided scope, but apt differs from provided in a few key ways. The first difference is that code generated by an apt dependency is available to the IDE, whereas code generated by a provided dependency is not.
Another important difference is that the code in a library using the provided scope is on the IDE classpath (i.e. you can import the classes and attempt to use them), whereas code in an apt dependency is not. With provided, your code will crash at runtime if you don't actually provide the referenced dependencies with a compile scoped counterpart.
You can find a discussion about apt vs provided on this android-apt issue.
In the case of Dagger, there should be no reason to include the annotation processor and code generator in any of your code (which the provided scope would allow). Thus the apt scope is more appropriate.
Update for October 2016:
You probably don't need apt and the android-apt plugin anymore. Version 2.2 of the Android Gradle plugin has an annotationProcessor configuration that you should be using instead.
See more at What's next for android-apt?
Just to add how to change this in Studio 2.2 +
dependencies {
compile 'com.google.dagger:dagger:2.4'
annotationProcessor "com.google.dagger:dagger-compiler:2.4"
}
Add this in apps gradle module. No need to change any other thing.
Happy coding :)

Categories

Resources