Configure Kotlin for Android Studio Electric Eel 2022.1.1 - android

When I updated to Electric Eel 2022.1.1, every time I create a new Kotlin file, it gives me the notification warning Configure Kotlin Configure 'Name.app' module in 'Name' project asKotlin (Android with Gradle) module.
I have only been working with Kotlin, not Java. I only started getting this warning after the update.
After I click the link to configure as Kotlin (Android with Gradle) module and select All modules containing Kotlin files: Name.app and set the Kotlin compiler to 1.8.0, it still gives me another warning when I make a new file.
Do I need to worry about this warning or can I just ignore it?
Here is my build.gradle (:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.name'
compileSdk 33
defaultConfig {
applicationId "com.example.name"
minSdk 23
targetSdk 33
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'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.7.0-alpha01'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.core:core-ktx:1.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
and here is the top-level 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.8.0' apply false
}

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.

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

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.

Kotlin 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

Seems this has been asked a few times, but the questions with solutions are seemingly outdated.
Here are my build.gradle files... any idea what I'm meant to be changing? (Complete Kotlin novice here, in case that wasn't obvious)
Build.gradle (Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.testapp"
minSdk 24
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'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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.5.30' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any help would be greatly appreciated

meow bottom navigation bar is not recogonised by android studio even after entering dependencies?

it giving me error <meow.meowbottomnavigation.MeowBottomNavigation
/>
in red, saying missing class even after entering these dependecies.
build.gradel(project)
buildscript {
repositories {
jcenter()
}
}
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
build.gradel(app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.meowbotm"
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 '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 'com.etebarian:meow-bottom-navigation:1.2.0'
}
i have also added following lines in gradel properties
android.useAndroidX=true
android.enableJetifier=true
i don't know what problem is, in YT and on websites its shows these dependecies are sufficent and meowbottom bar working.
You have to use this tag in your xml file to implement, then it will work. AS you are using 1.2.0 version.
<com.etebarian.meowbottomnavigation.MeowBottomNavigation
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btm_nav"
android:layout_gravity="bottom"
app:mbn_backgroundBottomColor="#color/purple_200"
app:mbn_circleColor="#color/white"
app:mbn_selectedIconColor="#color/purple_200"
app:mbn_defaultIconColor="#color/white"/>

Categories

Resources