Home > Software engineering >  Unresolved reference everything when i create new jetpack compose project
Unresolved reference everything when i create new jetpack compose project

Time:11-10

i found some broke problem here, this is new project with default sample code I haven't do anything with the code then my android studio looks like in the image

android studio

I've try a lot of things including uninstalling android studio and re-installing this android studio, but I still found the same problem

plugins {
  id 'com.android.application'
  id 'kotlin-android'
}

android {
compileSdk 31

defaultConfig {
    applicationId "id.rizki.nidelist"
    minSdk 23
    targetSdk 31
    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'
    useIR = true
}
buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion compose_version
    kotlinCompilerVersion '1.5.21'
}
packagingOptions {
    resources {
        excludes  = '/META-INF/{AL2.0,LGPL2.1}'
    }
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.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.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4. '
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"
}

CodePudding user response:

You're not using the correct dependency versions. Most importantly, you are not using the correct version of Kotlin or Java:

In your project grade file use this:

buildscript {
    ext {
        compose_version = '1.1.0-beta01'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
    }

}

In your app's gradle file:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.10'
}

apply from: 'codeinc.gradle'

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 21
        targetSdkVersion 31
        versionName "1.0"

        //def yourVersionCode = getIncrementedVersionCode()
        versionCode 1

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
        useIR = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion '1.5.31'
    }
}

dependencies {

    def lifecycle_version = '2.4.0'
    def activity_version = '1.4.0'
    def retrofit_version = "2.9.0"
    def paging_version = '3.1.0-beta01'

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0-rc01'
    implementation 'com.google.android.material:material:1.5.0-alpha05'
    implementation "androidx.activity:activity-ktx:$activity_version"
    implementation "androidx.activity:activity-compose:$activity_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.material:material-icons-extended:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
    implementation "androidx.compose.foundation:foundation:$compose_version"
    implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-rc01"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0'
}
  • Related