I've just started learning Compose (like an hour a...
# compose
j
I've just started learning Compose (like an hour ago). I'm trying to create a google map view from the crane demo app (https://github.com/android/compose-samples/blob/23fef0091a7f952516fcbd489c84760892[…]ain/java/androidx/compose/samples/crane/details/MapViewUtils.kt) and I'm trying to take out the mapview section out of the code and put it into my app. I'm getting an import error for LocalContext and LocalLifecycleOwner.
Copy code
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
Not getting much from google were these renamed possibly? Or do i need to add a dep somewhere
k
Which version of Compose are you depending on? There was a recent refactoring (in the last couple of weeks) of a bunch of ambients to local "things"
j
Copy code
Android Studio Arctic Fox | 2020.3.1 Canary 7
Build #AI-203.7148.57.2031.7136282, built on February 9, 2021
Runtime version: 11.0.8+10-b944.6842174 x86_64
VM: OpenJDK 64-Bit Server VM by N/A
macOS 10.16
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 8
Registry: external.system.auto.import.disabled=true
k
Which version of Compose are you using in your app? In your Gradle build script.
👍 1
j
I'm new to compose and not the most experienced with android studio. Will that work or is there somewhere to get the kotlin compose veresion inside canary
Copy code
plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "fin_aquatic_rentals.fin_aquatic_rentals"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '<http://proguard-rules.pro|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.21'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    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.0-alpha06'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
k
This -
$compose_version
- what is that version?
j
Copy code
A newer version of androidx.compose.material:material than 1.0.0-alpha08 is available: 1.0.0-alpha12
ah ok should i update to alpha 12
k
Line 57
j
Ok, I dont have a buildSrc Dependencies.kt. I'll go read up on using one and I think once i get the deps properly installed these import errors should be fixed
k
You don't need to go down the
buildSrc
route for a simple app where you explore things
j
well i plan to have this app slowly evolve to replace a cross platform app thats already wrote
is the buildSrc route recommended for compose projects or is the gradle route better?
k
👍 1
It's basically a folder that is treated by Gradle in a "special" way for everything related to build scripts. It's useful once your build logic becomes relatively complex
And you know how some people love their build complexity 🙂
🙂 1