How do I make kapt gradle task showing errors in Kotlin code instead of generated Java code? - android

I'm using kapt for hilt and room. Whenever there is an error related to those libraries, kapt show me all errors in the generated Java code. How do I make it to show errors in Kotlin code instead?
This is what it looks like in Android studio.
Just to clarify. It works fine for a valid code. But when there is a mistake (like a missing #Entity annotation on an actual entity class) I want it to point the error in Kotlin code, not in generated Java code.
Here is my project's build.gradle:
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.dagger.hilt.android' version '2.44' apply false
id 'org.jetbrains.kotlin.kapt' version "1.6.10" apply false
}
And the app's build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id 'com.google.dagger.hilt.android'
}
android {
namespace 'org.acanthite.upc'
compileSdk 33
defaultConfig {
applicationId "org.acanthite.upc"
minSdk 22
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
coreLibraryDesugaringEnabled true
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
kapt {
correctErrorTypes = true
}
ext {
compose_ui_version = '1.3.3'
room_version = '2.5.0'
hilt_version = '2.45'
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.1'
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-paging:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'
}
I've tried clearing Android Studio caches, rebuild and sync it a ton of times, lovered rooms version, but still no luck. It's basicaly just a project generated from Compose template. Plus I added room and hilt dependencies that I've added on top of it.

Related

How to update Jetpack Compose version in a project?

I want to update dependencies to latest version of Jetpack Compose. I tried to change version texts in gradle files but build error. Also I can't find what is the latest version of Jetpack Compose.
build.gradle (Project)
buildscript {
ext {
compose_version = '1.2.0'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
build.gradle (Module:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.android'
compileSdk 33
defaultConfig {
applicationId "com.example.android"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha11'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
I tried and searched on internet for two days but always build error.I'm very noob at this jobs, so it didn't work.
Jetpack compose has switched to using a bill of materials (BOM) to combine compatible library versions.
Check out the documentation:
dependencies {
// Import the Compose BOM
implementation platform('androidx.compose:compose-bom:2023.01.00')
// Import other Compose libraries without version numbers
implementation 'androidx.compose.foundation:foundation'
}
You can find the latest BOM version here.
If you are still getting build errors then you most likely need to update your kotlin plugin version.

Animations in Compose not working after dependency updates

After updating Compose to be able to use Modifier.blur, I got errors which were resolved after updating other dependencies. But now two animations I use (AnimateDpAsState and AnimatedVisibility) does not work.
I get the following error while building in release mode and it still builds successfully. No errors on debug mode.
lifecycle-runtime-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
I am pretty sure the problem lies in the gradle files so please take a look.
module build.grade
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id "org.jetbrains.kotlin.kapt"
}
android {
namespace 'com.example.app'
compileSdk 33
defaultConfig {
applicationId "com.example.app"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
// Compose
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0-alpha05"
implementation "androidx.navigation:navigation-compose:2.6.0-alpha04"
implementation "androidx.compose.material:material-icons-extended:1.3.1"
implementation "androidx.hilt:hilt-navigation-compose:1.1.0-alpha01"
//Dagger - Hilt
implementation 'com.google.dagger:hilt-android:2.44.2'
kapt 'com.google.dagger:hilt-android-compiler:2.44.2'
// Room
implementation "androidx.room:room-runtime:2.5.0"
kapt "androidx.room:room-compiler:2.5.0"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:2.5.0"
}
project build.gradle
buildscript {
ext {
compose_ui_version = '1.3.3'
}
}
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
id "org.jetbrains.kotlin.kapt" version "1.8.0" apply false
}
I updated dependencies highlighted by Android Studio and Compose and was expecting it to work as it was with the new versions. No extra dependencies were added nor was the code modified.

Failed to resolve: org.jetbrains.anko:anko:0.10.8 Show in Project Structure dialog Affected Modules

guys.
I'm new to android development and there is a problem.
Somehow I cannot sync jetbrains library anko although I followed what they've written on their github.
Here are the error code and build.gradle.
Please help me.
I want to use anko library.
Error code
Failed to resolve: org.jetbrains.anko:anko:0.10.8
Show in Project Structure dialog
Affected Modules: app
Project gradle
projects/modules.
buildscript{
ext.anko_version = '0.10.8'
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
Module gradle
plugins {
id 'kotlin-kapt'
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.won.kotlinpractice'
compileSdk 32
defaultConfig {
applicationId "com.won.kotlinpractice"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.anko:anko:$anko_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
You are declaring the wrong Anko implementation
Please check this and use required please find details here.
dependencies {
// Anko Commons
implementation "org.jetbrains.anko:anko-commons:$anko_version"
// Anko Layouts
implementation "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
// Coroutine listeners for Anko Layouts
implementation "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"
// Anko SQLite
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
}
Note : Anko is deprecated. Please see this page for more information.

Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1 error in compose

I am using Google map for my app with jetpack compose I implemented these dependencies
//Compose Maps
implementation 'com.google.maps.android:maps-compose:2.5.3'
implementation 'com.google.android.gms:play-services-maps:18.0.2'
in my app.gradle file
and I am getting this error
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
I used everything please answer this question.
my app.gradle file:-
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.mapsincompose"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
//Compose Maps
implementation 'com.google.maps.android:maps-compose:2.5.3'
implementation 'com.google.android.gms:play-services-maps:18.0.2'
}
my project.gradel file:-
buildscript {
ext {
compose_version = '1.1.0-beta01'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The following might help you out:
Obs! Have you followed the implementation of google maps correctly ? This includes created a google cloud account for the API key and implementations of it ?
Update compose to the latest version:
compose_version = "1.3.0-beta02"
Change:
kotlinCompilerExtensionVersion = "1.2.0"
Change the plugin to:
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
You need to make sure you have all dependencies:
a) Add this to you app.gradle file:
id 'com.google.gms.google-services'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
b) In build.gradle Project:
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
Let me know if this resolved your problem!
in ext block of project level gradle file change compose version like this :-
compose_version = '1.1.0-rc03'
and add this to the dependency in the same file like this
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
}
it worked for me and I hope it will work for every one
explanation:- basically here I just change compose version to the latest version and I change kotlin version according to the compose version support here is the full documentation.

Android Studio - How to upgrade jetpack compose?

I am currently using Android studio (2021.2.1 Patch 2). On choosing empty compose activity, the compose version being used is 1.1.0-beta01 .How can I upgrade it to 1.2.0-beta01 as the earlier one gives error while using LazyVerticalGrid? I am beginner to android. Any help would be greatly appreciated.
Here is the app/build.gradle file of the project :
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.courses"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
Toplevel build.gradle file :
buildscript {
ext {
compose_version = '1.1.0-beta01'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried changing compose version in toplevel build.gradle file to 1.2.0-beta01 but the build of the project fails.
Please specify in comments if you need some more information.
Thanks
Without seeing the compilation error message I can only guess at what might be the cause. But I see a couple of things that might give you problems.
The Compose Compiler for 1.2.0-beta01 requires Kotlin Plugin version 1.6.21 See Compose Kotlin Compatibility Map
Additionally, from version 1.2.0 onwards they've introduced independent versioning for Compose Compiler from the rest of the Compose libraries, meaning that kotlinCompilerExtensionVersion needs to point to a different version. As of right now the latest compiler version is 1.3.1 which needs kotlin plugin version 1.7.10.
Try these changes.
ext {
compose_version = '1.3.0-beta02' // or 1.2.1 if you want the latest stable version
}
composeOptions {
kotlinCompilerExtensionVersion "1.3.1"
}
plugins {
// others omitted
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

Categories

Resources