diff --git a/kmp/androidApp/.gitignore b/kmp/androidApp/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/kmp/androidApp/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/kmp/androidApp/build.gradle.kts b/kmp/androidApp/build.gradle.kts new file mode 100644 index 00000000..eedb0b66 --- /dev/null +++ b/kmp/androidApp/build.gradle.kts @@ -0,0 +1,58 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.compose.compiler) +} + +android { + namespace = "com.example.kmp.snippets" + compileSdk = libs.versions.compileSdk.get().toInt() + + defaultConfig { + applicationId = "com.example.kmp.snippets" + minSdk = libs.versions.minSdk.get().toInt() + targetSdk = libs.versions.targetSdk.get().toInt() + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + + buildFeatures { + compose = true + } +} + +dependencies { + val composeBom = project.dependencies.platform(libs.androidx.compose.bom) + implementation(composeBom) + implementation(project(":kmp:shared")) + + implementation(libs.androidx.compose.runtime) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.foundation) + implementation(libs.androidx.compose.foundation.layout) + implementation(libs.androidx.compose.ui.util) + implementation(libs.androidx.compose.material) + implementation(libs.androidx.lifecycle.runtime) + implementation(libs.androidx.lifecycle.viewModelCompose) +} \ No newline at end of file diff --git a/kmp/androidApp/proguard-rules.pro b/kmp/androidApp/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/kmp/androidApp/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/kmp/androidApp/src/main/AndroidManifest.xml b/kmp/androidApp/src/main/AndroidManifest.xml new file mode 100644 index 00000000..de749acb --- /dev/null +++ b/kmp/androidApp/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/kmp/androidApp/src/main/kotlin/com/example/kmp/snippets/MainScreen.kt b/kmp/androidApp/src/main/kotlin/com/example/kmp/snippets/MainScreen.kt new file mode 100644 index 00000000..e2757679 --- /dev/null +++ b/kmp/androidApp/src/main/kotlin/com/example/kmp/snippets/MainScreen.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.kmp.snippets + +import androidx.compose.runtime.Composable +import androidx.lifecycle.viewmodel.compose.viewModel + +// [START android_kmp_viewmodel_screen] +// androidApp/ui/MainScreen.kt + +@Composable +fun MainScreen( + viewModel: MainViewModel = viewModel( + factory = mainViewModelFactory, + ), +) { +// observe the viewModel state +} +// [END android_kmp_viewmodel_screen] diff --git a/kmp/shared/build.gradle.kts b/kmp/shared/build.gradle.kts index ed832cce..2ef25a93 100644 --- a/kmp/shared/build.gradle.kts +++ b/kmp/shared/build.gradle.kts @@ -5,14 +5,13 @@ plugins { } kotlin { - // Target declarations - add or remove as needed below. These define // which platforms this KMP module supports. // See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets androidLibrary { - namespace = "com.example.kmp.snippets" - compileSdk = 36 - minSdk = 24 + namespace = "com.example.kmp.snippets.shared" + compileSdk = libs.versions.compileSdk.get().toInt() + minSdk = libs.versions.minSdk.get().toInt() withHostTestBuilder { } @@ -24,6 +23,8 @@ kotlin { } } + jvmToolchain(17) + // For iOS targets, this is also where you should // configure native binary output. For more information, see: // https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks @@ -64,9 +65,7 @@ kotlin { androidMain { dependencies { - // Add Android-specific dependencies here. Note that this source set depends on - // commonMain by default and will correctly pull the Android artifacts of any KMP - // dependencies declared in commonMain. + } } @@ -88,5 +87,4 @@ kotlin { } } } - } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 111fd452..2a71512a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -39,5 +39,6 @@ include( ":identity:credentialmanager", ":xr", ":watchfacepush:validator", - ":kmp:shared", + ":kmp:androidApp", + ":kmp:shared" )