Adding kapt to use Room causes compile errors - android

I added apply plugin: 'kotlin-kapt' to be able to use Rooms annotation proccessor:
compile "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
However when I build my project I get:
Folder C:\Users\...\app\build\generated\source\kaptKotlin\debug
Folder C:\Users\...\app\build\generated\source\kaptKotlin\release
3rd-party Gradle plug-ins may be the cause
If I get rid of kapt and simply use annotationProcessor instead. The app crashes saying:
java.lang.RuntimeException: cannot find implementation for
com.example..data.database.Appdatabase.
Appdatabase_Impl does not exist
Any ideas on how to use Room

I was facing similar issue.
Go to:
Run -> Edit Configurations -> General
At the bottom, there is window named
Before launch: Gradle-Aware, Active tool window
Remove
Instant App Provision
and keep Gradle-aware Make

I delete two folder app\build\generated\source\kaptKotlin\debug and app\build\generated\source\kaptKotlin\release ("debug" and "release") and add
in gradle:
kapt {
mapDiagnosticLocations = true
}
then the project is sync without problem.

Related

Android studio Error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency

I have facing the following error while building the project. And unable to solve the same after trying it for whole day.
error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency. androidx.room:room-rxjava2:<version>
public abstract java.lang.Object clearAllBillers(#org.jetbrains.annotations.NotNull()
^
below are my dependancies inside the build.gradle
implementation("androidx.room:room-rxjava2:2.3.0")
implementation "androidx.room:room-runtime:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:2.3.0"
I have done trying already existing solutions such as upgrading
classpath 'com.android.tools.build:gradle:7.3.1'
Also tried to do invalidate cache and clean project.
Still not able to solve the issue.
Please help me if you have any idea to get it resolve.
Thanks in advance!!!❤️
Not sure why haven't you received an answer quicker (because this question has an easy solution)
you just need to add
implementation("androidx.room:room-rxjava2:2.4.3")
to your build.gradle (for your app or module)
(source)

error while generating apk in android studio after gradle build is successfull

while generating apk getting this error i have already tried upadting the pugins also as it was recommended
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.
- icepick-processor-3.2.0.jar (frankiesardo:icepick-processor:3.2.0)
- auto-service-1.0-rc2.jar (com.google.auto.service:auto-service:1.0-rc2)
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.
You should explicitly add annotation processors in gradle. Putting the following in your gradle dependencies should fix it:
annotationProcessor 'frankiesardo:icepick-processor:3.2.0'
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc2'

Cannot upgrading gradle Android Studio 3.4., Gradle 5 dependencies break randomly

When I was trying to upgrade my Android Studio to 3.4, the update does not go smoothly rather, some dependencies break. In my case, the RxJava/RxKotlin dependencies are breaking without giving any clue. Even that is happening randomly as I have RxJava/RxKotlin Code in each of my 4 modules but the dependency is failing in only one module.
What I tried :
Invalidate Cache and restart.
Delete /build *module/build/ *module/.gradle/ & .gradle/
Clean Project
Try find answers on the internet and these are the closest but does not solve the problem. (They did not recommend to upgrade to 3.4)
i) Unresolved reference: Observable in Android Studio 3.4
Explains the problem I have but the thread is moving to either not upgrading the Gradle (Which is last option for me) or making sure RxJava that is being used in the project or any of its library is 2.2.8). For that reason I tried explicitly adding RxJava 2.2.8 (I was not previously as I was getting it inside RxKotlin) and wrote a resolutionStrategy to force Android studio to use RxJava 2.2.8 like this in that particular module i.e. domain, but did not solve the issue :
configurations.all {
resolutionStrategy.force 'io.reactivex.rxjava2:rxjava:2.2.8'
}
ii) RxKotlin is not resolved properly after updating Gradle to 3.4.0 which does not yet give any solution. And I am even suspicious if it's the issue with RxJava/RxKotlin or the Gradle plugin itself. Or even if it's the case with RxKotlin or any other libraries too.
Edit: My dependencies in domain module looks like this :
dependencies {
implementation Deps.kotlinStdLib
implementation Deps.rxKotlin
implementation Deps.dagger
implementation Deps.timber
implementation Deps.mobiusCore
implementation Deps.mapboxGeoJSONCore
}
try to add rxkotlin to the dependencies (if not already added):
dependencies {
// rxKotlin ...is likely missing
implementation "io.reactivex.rxjava2:rxkotlin:2.3.0"
// rxJava:
implementation "io.reactivex.rxjava2:rxjava:2.2.0"
// rxAndroid bindings:
implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
}

Android Architecture Components: Gradle sync error for dependency version

I'm trying to add ViewModel and LiveData to a Kotlin app. I have the following dependencies added to my module's build.gradle:
implementation "android.arch.lifecycle:extensions:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
testImplementation "android.arch.core:core-testing:1.1.1"
I'm given the following error:
Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.1.1) classpath. You should manually set the same version via DependencyResolution
Removing the first line (extensions) fixes the issue, indicating that the error is coming from there, but I can't figure out why.
As #RedBassett mentions Support libraries depends on this lightweight import (runtime library) as explained at android developers documentation.
This is, android.arch.lifecycle:runtime:1.0.0 is spreading up in the dependency tree as a result of an internal api (transitive) import so in my case I only had to include extensions library as "api" instead of "implementation" so that it will override its version to the highest (1.1.1).
In conclusion, change
implementation "android.arch.lifecycle:extensions:1.1.1"
to
api "android.arch.lifecycle:extensions:1.1.1"
In your main build.gradle file
allprojects {
...
configurations {
all {
resolutionStrategy {
force "android.arch.lifecycle:runtime:1.1.1"
}
}
}
}
This will enforce version 1.1.1
Apparently support-v4 was causing the conflict. In the case of this question, the Gradle dependency task wasn't working correctly, but for anyone else who runs into this issue:
./gradlew :app:dependencies will show the sub-dependencies used by your dependencies. Search the output of this command (changing app for your module name) for the dependency causing the conflict.
#RedBassett is right. However I was still having some problem excluding android.arch.lifecycle related sub dependencies.
In my case the conflict was caused in com.android.support:appcompat-v7:27.1.1.
This is how my gradle dependency looks like after excluding it.
implementation ('com.android.support:appcompat-v7:27.1.1') {
exclude group: 'android.arch.lifecycle'
}
api "android.arch.lifecycle:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
Also, you will have to add this exclude in every imported module.
I searched for all dependencies with ./gradlew :app:dependencies as #RedBassett mentioned. I noticed the incompatible version of android.arch.core:runtime that Gradle was complaining about was stemming from my version of com.android.support:appcompat-v7, so I just updated that version to the latest and everything worked.

Kotlin build cannot get classes created by SquidDatabase

In my project I use SquidDatabase almost everywhere to access the database.
I want to transform my project to Kotlin but when I build there are lots of "Unresolved reference: DepartmentInfo" errors.
That DepartmentInfo class was created by SquidDatabase while building so I think this problem is caused by Kotlin building before other libraries.
I failed to find any way to change Kotlin to the end of buildlist.
How can I solve this problem?
I posted this issue on Github and got reply from developers.
The solotion is here:
build.gradle of your app
//If using kotlin language,please add this
apply plugin: 'kotlin-kapt'
......
dependencies {
compile 'com.yahoo.squidb:squidb:3.2.3'
compile 'com.yahoo.squidb:squidb-annotations:3.2.3'
compile 'com.yahoo.squidb:squidb-android:3.2.3' // For Android projects only
//annotationProcessor 'com.yahoo.squidb:squidb-processor:3.2.3'
// If using the android-apt plugin, this becomes
// apt 'com.yahoo.squidb:squidb-processor:3.2.3'
// If using kotlin language, this becomes
kapt 'com.yahoo.squidb:squidb-processor:3.2.3'
}
It may cause errors if you use DataBinding for Andriod,and the solution is to add one more kapt in your dependencies:
kapt 'com.android.databinding:compiler:$gradle_version'

Categories

Resources