7

I am currently experiencing Android Studio warning me about certain Kotlin functions that don't exist. I assume this is an Android Studio only problem as I can compile and run my project just fine

For example, Android Studio is unable to recognize val rows = mutableListOf<MeasuredRow>(). It provides the warning: Unresolved reference: mutableListOf. That said, I can use some other Kotlin functions and classes just fine.

The only solution is downgrading which I do not want to do

App-wide gradle:

buildscript {
    ext.kotlin_version = "1.4.32"
    ext.compose_version = '1.0.0-beta04'
    ext.hilt_version = '2.33-beta'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            jvmTarget = '1.8'
            allWarningsAsErrors = false
            // Opt-in to experimental compose APIs
            freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
            // Enable experimental coroutines APIs, including collectAsState()
            freeCompilerArgs += '-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App module specific Gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    }
    buildscript {
        apply from: '../dependencies.gradle'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.0.0-beta04'
    }
    buildTypes {
        release {
            minifyEnabled true
            debuggable false
            shrinkResources = true
            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.kotlin:kotlin-stdlib:$kotlin_version"
    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.compiler:compiler:1.0.0-beta04"
    implementation 'androidx.compose.ui:ui:1.0.0-beta04'
    implementation 'androidx.compose.ui:ui-tooling:1.0.0-beta04'
    implementation 'androidx.compose.foundation:foundation:1.0.0-beta04'
    implementation 'androidx.compose.material:material:1.0.0-beta04'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha06'
    implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-beta04'
    implementation "androidx.navigation:navigation-compose:1.0.0-alpha09"
    implementation "androidx.hilt:hilt-navigation-compose:1.0.0-alpha01"
    implementation 'dev.chrisbanes.accompanist:accompanist-insets:0.6.2'

    // ViewModel
    def lifecycle_version = "2.3.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04'
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

    // hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-compiler:$hilt_version"

    // Image Loading
    implementation group: 'com.google.accompanist', name: 'accompanist-imageloading-core', version: '0.7.0'
    implementation "com.google.accompanist:accompanist-glide:0.7.0"
}

It is important to know that my app works and is installable with no issues (even on a clean install)

What I've tried:

  • Reinstall Windows PC
  • Invalidate Cache/Restart
  • Delete .Android studio in home directory
  • Delete ./.idea folder
3
  • I encountered this problem as well just now and I am very dissapointed as this hampers the current project I am working on. The perils of working on unstable releases. Are you working on Jetpack Compose? At this point I will be downgrading to Canary 8 as this was the last version that was stable for me.
    – Neon Warge
    Apr 13, 2021 at 15:09
  • 1
    @NeonWarge correct. this is a Compose project. In the end I decided to revert to an older version
    – Zun
    Apr 13, 2021 at 16:19
  • I have heard similar complaints from others, such as in the #compose channel in Kotlinlang Slack. Personally, I stopped my Canary upgrade cycle at 12, mostly due to the Gradle 7.0 change -- I'll wait until Arctic Fox his beta before making that move. issuetracker.google.com/issues/185562147 and issuetracker.google.com/issues/183816740 may be related. However, neither issue seems to have a sample project. If anyone seeing this is in position to create a project that reproduces the problem and can add that to an issue, that might help expedite repairs. Apr 20, 2021 at 12:26

1 Answer 1

-2

It works now for me.

AS 2020.3.1 canary 15

Kotlin 1.5.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.