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'
Related
Error while adding MoshiPack Library in Kotlin latest version 1.3.70 to gradle.build application
Moshi pack
implementation 'com.daveanthonythomas.moshipack:moshipack:1.0.1'
Error Message
Duplicate class kotlin.reflect.KClasses found in modules jetified-kotlin-reflect-1.1.1.jar (org.jetbrains.kotlin:kotlin-reflect:1.1.1) and jetified-kotlin-stdlib-1.3.70.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.70)
Any suggestions how to solve this issue or any other library I can use in Kotlin so I can use Message Pack.
Thanks in advance
Try to add this to your dependencies:
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
and make sure you specified your Android NDK location under File>Project Structure...>SDK Location
Starting Kotlin 1.3.70 some basic useful members on KClass included in Kotlin standard library (they were in a kotlin-reflect before).
See "Working with KClass" in https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/
In your case MoshiPack adds a kotlin-reflect library that conflicts with standard library.
You should exclude transitive dependency to resolve the conflict.
If you use KotlinDSL, in build.gradle.kts:
implementation ("com.daveanthonythomas.moshipack:moshipack:1.0.1") {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
}
If you use Groovy, in build.gradle:
implementation ('com.daveanthonythomas.moshipack:moshipack:1.0.1') {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
}
I tried this and it worked
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.10"
i think the only way to solve it , to go back to kotlin version 1.3.61 , so remove 1.3.70 and use 1.3.61
So I finally figured it out and here's how :-
So the main problem is you have injected 2 dependency of same class. Here he used 2 dependency for Kotlin which conflict in runtime to fix that you have to check which dependency is duplicated. (It is most case scenario. It can be with any other dependency i.e. Hilt)
Go to File > Project structure > Dependencies
Check which dependency are repeating. In this case it will have (androidx.core:core:1.8.0) and (androidx.core:core:+)
as you can see there are 2 dependency with same classes version 1.8.0 will have all the class which core:+ will have and this is causing a error.
Now delete (androidx.core:core:+) and hit Apply and sync project.
Now you should be good to go. here is structure after changing dependency.
Note:- This method will show all the android dependency which you might be not included but you will see all the dependency which any app has. Please remove the dependency who are you familiar with do not remove any dependency without any proper knowledge.
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"
}
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.
I'm trying to integrate Dagger 2 to be used in unit tests. Unfortunately whenever I run my test I get java.lang.NoClassDefFoundError: javax/inject/Provider.
I have the javax dependency added in Gradle like this:
depdencencies {
...
provided 'javax.annotation:jsr250-api:1.0'
}
What I tried:
Changing provided to compile. Adding both compile and testCompile with this dependency. I also tried testProvided but there is no such thing so it didn't work either.
Apparently the problem is that by using provided this dependency is available only compile time. Unfortunately nothing else worked so I am open to any suggestions. If more information is needed, please ask. Thanks!
I use in AndroidStudio 2.2.3 dagger2 for unit testing with app/build.gradle
....
apt 'com.google.dagger:dagger-compiler:2.11'
compile 'com.google.dagger:dagger:2.11'
provided 'javax.annotation:jsr250-api:1.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
....
I'm trying to use Butterknife with some Kotlin code and also Java code. I know that before M12, there was bad or no support for annotation processing that ButterKnife required. So I have kept my activities in Java. It was working at least in Java with Butterknife 6.x and preM12 Kotlin.
I'm trying now butterknife 7.x with M13 and M14. It should have even annotation processing support, but it's not working for me. bind() function doesn't bind anything in my adapter which is written in Java nor in activity written in Kotlin.
I'm using this in build.gradle (tried latest version on Github):
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
provided files('libs/butterknife-annotations.jar')
kapt files('libs/butterknife-compiler-8.0.0-SNAPSHOT.jar')
compile 'com.jakewharton:butterknife:8.0.0-SNAPSHOT#aar'
}
This doesn't compile. I tried also 'com.neenbedankt.android-apt' which does compile but binding is not working.
I know that there is probably not support in butterknife for that yet. But is there any hack to get it working?
It does work with the current version of Kotlin (1.0.0-beta-3595), I suggest you to take a look at the android-butterknife project which can be found inside the JetBrains's kotlin-examples repo. In short all you need to do is:
Add the following to your app/build.gradle file:
kapt {
generateStubs = true
}
Put the following line inside the dependencies block of the same build.gradle file (assuming you already added compile 'com.jakewharton:butterknife:7.0.1' to your dependencies):
kapt 'com.jakewharton:butterknife:7.0.1'
And that should be it.
Butterknife is supported. Use kapt: [1], [2].
Note that Butterknife does not support private Java fields, so you can use the lateinit modifier to make it public.
Also, if you use kapt,
apply plugin: 'com.neenbedankt.android-apt'
line is not needed anymore.