After updating my Android Studio Canary version to 3.1, I started receiving Kotlin unresolved references for functions belonging to the kotlin standard library, and the issue also seems to be affecting Android Studio's ability to import the correct library.
I believe my issue is similar to this. Per a recent comment, changing my gradle kotlin version to 1.5.0 fixed the "unresolved reference" issue, but compose beta06 does not support 1.5.0 yet.
I was wondering if anybody had any luck solving this. I believe I have tried to update as many of my dependencies as well as clean building, invalidating cache and restarting.
Here is my gradle file.
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.leetcards"
minSdkVersion 21
targetSdkVersion 30
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'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
// Navigation
def nav_version = "1.0.0-alpha10"
implementation "androidx.navigation:navigation-compose:$nav_version"
// Accompanist
def accompanist_version = "0.9.0"
// implementation "com.google.accompanist:accompanist-coil:$accompanist_version"
// Networking (Retrofit and Moshi)
def retrofit_version = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
def moshi_kotlin_version = "1.12.0"
def moshi_converter_version = "2.9.0"
implementation "com.squareup.moshi:moshi-kotlin:$moshi_kotlin_version"
implementation "com.squareup.retrofit2:converter-moshi:$moshi_converter_version"
// Firebase
implementation platform('com.google.firebase:firebase-bom:27.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.firebaseui:firebase-ui-auth:7.1.1'
implementation 'com.facebook.android:facebook-android-sdk:4.x'
// Facebook login
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
// CameraX core library using the camera2 implementation
def camerax_version = "1.0.0"
// The following line is optional, as the core library is included indirectly by camera-camera2
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
// If you want to additionally use the CameraX Lifecycle library
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
// If you want to additionally use the CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha24"
}
I too have the same problem with Compose project in Android Studio after upgrade to Kotlin 1.5.0. Unresolved references seem to come from the mismatch between Kotlin version defined in project gradle files and Kotlin version bundled with Kotlin plugin. There is some old thread on SO describing similar issue in IntelliJ: link
Summarizing, there are 2 conflicting situations:
Switching to Kotlin 1.5.0 throws error about Jetpack Compose incompatibility;
Downgrading to Kotlin 1.4.32 allows to compile and install the app, however problem with unresolved references arises. Kotlin plugin cannot be easily downgraded (or can it?).
As a temporary measure I am switching between two Kotlin versions, in hope of finding better solution.
Related
I've benn programming my school proyect for several months and now im done. I used to compile my app directly to my phone (Android 12) but I need it to be at least API 28. I tried to change the Build Gradle target version from 31 to 28 but I'm having errors with the dependencies versions.
There is any safe and quick way to know which version exactly I need for each dependency?
Im currently using theese.
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
//Hilt
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.kdapp.estudiapp"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.1"
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}'
}
}
}
apply plugin: 'com.google.gms.google-services'
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'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.6'
implementation 'com.google.firebase:firebase-firestore-ktx:24.2.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"
//Firebase
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth:21.0.6'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
//Firebase -> Storage
implementation 'com.google.firebase:firebase-storage'
//Navigation
implementation 'androidx.navigation:navigation-compose:2.5.0'
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.5"
// Hilt DI
def hilt_lifecycle_viewmodel = "1.0.0-alpha03"
def hilt_navigation = "1.0.0-alpha03"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_lifecycle_viewmodel"
implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation"
//GSON
implementation 'com.google.code.gson:gsoenter code heren:2.9.0'
}
Any external dependencies require version checks specified on their official GitHub repo, or their website, if it isn't open-source. Now, as of a quick way to downgrade minSdk, just press Ctrl+Alt+Shift+S within Android Studio, and it'll open the project structure dialog. Find a field that says minSdk, and set it to whatever you require. I recommend setting the targetSdk and compileSdk to the maximum value available, they won't affect your app's deployment on lower api devices. There's also a suggestions pane in the dialog, which can help you update dependency versions studio deems to be out-dated. After having set everything, click Apply/Ok.
I am encounter a problem when I try to build the Android app and it appear error. The error appear after I add the last line in Gradle Build file (the natural language library).
Below is my gradle build file code
plugins {
id 'com.android.application'
id 'com.google.secrets_gradle_plugin' version '0.5'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myvolunteer"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled 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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-firestore:23.0.3'
implementation 'com.firebaseui:firebase-ui-firestore:8.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.firebase:firebase-storage:20.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Import the BoM for the Firebase platform
// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.google.firebase:firebase-analytics:19.0.1'
//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
//Circle Image View
implementation 'de.hdodenhof:circleimageview:3.1.0'
//Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.karumi:dexter:6.2.3'
implementation 'com.google.android.gms:play-services-location:18.0.0'
//Cloud-lang,but it causes duplicate classes occur.
implementation 'com.google.cloud:google-cloud-language:2.1.2'
}
Some of the error that I get when try to build the project in Android Studio (it's too much I can't put all of them here)
Duplicate class com.google.api.Advice found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.api.AuthProvider$1 found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.cloud.audit.AuthenticationInfo$Builder found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.longrunning.Operation$1 found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
How can I resolve this problem? I really need to add the Google Natural Language library to my app.
Updated: The attempt that I have tried but failed:
Firebase Android: Duplicate Protobuf classes found in modules
Duplicate Class while using firebase and google-cloud-texttospeech
Duplicate classes exception means that one of your dependencies uses implicitly the older or newer (with +) version of some library you also use in your project,
To resolve this issue you may add such block of code (put your library version after 'force') to your build.gradle file (Module:app):
configurations {
all {
resolutionStrategy {
// do not upgrade above 3.12.0 to support API < 21 while server uses
// COMPATIBLE_TLS, or okhttp3 is used in project
force 'com.squareup.okhttp3:okhttp:3.12.0'
force 'com.squareup.okhttp3:logging-interceptor:3.12.0'
}
}
}
You may also exclude some group from your dependencies. For a single dependency you way write:
dependencies {
// example
implementation('log4j:log4j:1.2.15') {
exclude group: 'javax.jms', module: 'jms'
}
}
I created a completely fresh jetpack compose project (from the project template) with Android Studio 4.0 Canary 6 and I attempted to add room dependencies.
Here is my app-level build.gradle:
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 "com.example.composewithroom"
minSdkVersion 29
targetSdkVersion 29
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 {
compose true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.ui:ui-framework:0.1.0-dev03'
implementation 'androidx.ui:ui-layout:0.1.0-dev03'
implementation 'androidx.ui:ui-material:0.1.0-dev03'
implementation 'androidx.ui:ui-tooling:0.1.0-dev03'
implementation "androidx.room:room-runtime:2.2.2"
implementation "androidx.room:room-ktx:2.2.2"
kapt "androidx.room:room-compiler:2.2.2" // e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
I get this error when I try to build it:
e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
This can be either "fixed" by removing kapt "androidx.room:room-compiler:2.2.2" or disabling compose compose true
Does anyone have any idea how to fix this or is the room database just unusable with Compose at the moment?
Should be fixed in 1.3.61... but Jetpack Compose compiler plugin is not updated.
You can find more information in the following YouTrack issue: IR (Jetpack Compose), KAPT, Room: "AssertionError: IR backend shouldn't call KotlinTypeMapper.mapType: MainActivity". Last comment states that:
The problem here is that JetPack Compose hasn't updated its internal Kotlin compiler to 1.3.61 yet. We'll see what we can do about it.
Also, the following issue in Google Issue Tracker: Annotation processors fail when compose is enabled
I'm creating a new Android project and I adding Dagger 2, but it fails with an error related to androidx libraries.
After using a template from within Android Studio, I've added a few lines, kotlin-kapt, and the dependencies for Dagger 2.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxxx.yyyy"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
androidExtensions {
experimental = true
}
kapt {
generateStubs = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'com.google.android.material:material:1.0.0-alpha1'
// Image Loading
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
// Dagger
implementation 'com.google.dagger:dagger-android:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'
// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.3'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
// Navigation
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha01'
// Pretty Logger
implementation 'com.orhanobut:logger:1.15'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'
}
When trying to build the application, it fails with the following errors.
error: cannot find symbol
public final class MainActivityViewModel extends android.arch.lifecycle.ViewModel {
^
symbol: class ViewModel
location: package android.arch.lifecycle
error: cannot find symbol
private final androidx.lifecycle.MediatorLiveData
^
symbol: class MediatorLiveData
location: package androidx.lifecycle
error: cannot find symbol
private androidx.navigation.NavController navController;
^
symbol: class NavController
location: package androidx.navigation
...
I've tried with androidx libraries, and the older libraries but both fail. If I removed the Dagger 2 dependencies it will build and run fine.
I'm currently using Android Studio 3.2 Canary 17.
Any idea what's going wrong?
Thanks.
Go to Settings -> Build, Execution, Deployment -> Compiler,
uncheck the 'Configure on demand' option if set.
Also make sure you are using latest gradle and Android Gradle plugin
I managed to track down the cause of the issue, it wasn't related to the build.gradle itself but the version of Java I was using.
Within Android Studios I have changed the JDK to use Java 10.
However, changing this setting back to using the embedded JDK has made the application compile successful.
but when I build it gives me an error
recently android updated for kotlin
and my android gradle vesion is 3.1.2
and kotlin version is 1.2.41
android studio 3.1.2
i'm targeting android p
this is latest version so i can't find more documentation on this problem and
please help me to find out this problem
android issues
Program type already present: android.support.v4.media.MediaBrowserCompat$ConnectionCallback$StubApi21
build.gradle(app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 'android-P'
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.xxxxxxx.xx"
minSdkVersion 18
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.anko:anko-commons:0.10.4'
implementation 'androidx.core:core-ktx:1.0.0-alpha1'
implementation "androidx.appcompat:appcompat:1.0.0-alpha1"
implementation "androidx.legacy:legacy-support-v4:1.0.0-alpha1"
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation "com.google.android.material:material:1.0.0-alpha1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
//firebase massaging
implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.google.firebase:firebase-core:15.0.2'
def lifecycle_version = "2.0.0-alpha1"
def room_version = "2.0.0-alpha1"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
// room database persistent
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// optional - Test helpers for LiveData
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
//data binding
//kapt 'com.android.databinding:compiler:3.1.2'
}
apply plugin: 'com.google.gms.google-services'
please help me what is problem I can't find out
i removed Androidx from my whole project but isue still parsist then
i found solution and replace
implementation 'androidx.core:core-ktx:1.0.0-alpha1'
to
implementation 'androidx.core:core-ktx:0.3'
and my problem is solved.
anyway thanks all second-time I'm going to use androidx (Android + Kotlin)
I'm waiting for jetpack stable version.
Actually this is a bug in Canary 14. You should wait for Canary 15 ;-)
Check out this session.
have you tried downloading android studio 3.2 canary 14? there is a new option to convert your files to androidX and will give you a preview of what it's going to do. Back up your files or at least use git to make sure it's safe.
thanks for the edit paul