Convert app-nia-catalog to compose multiplatform application

pull/2064/head
lihenggui 2 years ago
parent 75afb8ab06
commit 6b2d2b4f1b

@ -13,27 +13,58 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.google.samples.apps.nowinandroid.FlavorDimension
import com.google.samples.apps.nowinandroid.NiaFlavor
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
/*
* Copyright 2022 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.
*/
plugins {
alias(libs.plugins.nowinandroid.android.application)
alias(libs.plugins.nowinandroid.android.application.compose)
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.compose)
alias(libs.plugins.compose.compiler)
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
}
jvm("desktop")
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}
sourceSets {
val desktopMain by getting
androidMain.dependencies {
implementation(libs.compose.ui.tooling.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(projects.core.designsystem)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
}
}
android {
@ -41,10 +72,12 @@ android {
applicationId = "com.google.samples.apps.niacatalog"
versionCode = 1
versionName = "0.0.1" // X.Y.Z; X = Major, Y = minor, Z = Patch level
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
compileSdk = libs.versions.android.compileSdk.get().toInt()
// The UI catalog does not depend on content from the app, however, it depends on modules
// which do, so we must specify a default value for the contentType dimension.
missingDimensionStrategy(FlavorDimension.contentType.name, NiaFlavor.demo.name)
missingDimensionStrategy("contentType", "demo")
}
packaging {
@ -53,6 +86,9 @@ android {
}
}
namespace = "com.google.samples.apps.niacatalog"
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
buildTypes {
release {
@ -62,15 +98,31 @@ android {
signingConfig = signingConfigs.named("debug").get()
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
isCoreLibraryDesugaringEnabled = true
}
dependencies {
debugImplementation(libs.compose.ui.tooling)
coreLibraryDesugaring(libs.android.desugarJdkLibs)
}
}
dependencies {
implementation(libs.androidx.activity.compose)
compose.desktop {
application {
mainClass = "MainKt"
implementation(projects.core.designsystem)
implementation(projects.core.ui)
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "com.google.samples.apps.niacatalog"
packageVersion = "1.0.0"
}
}
}
dependencyGuard {
configuration("releaseRuntimeClasspath")
compose.experimental {
web.application {}
}

@ -0,0 +1,28 @@
/*
* Copyright 2024 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.
*/
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.google.samples.apps.niacatalog.ui.NiaCatalog
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "NiA Catalog",
) {
NiaCatalog()
}
}

@ -0,0 +1,4 @@
import androidx.compose.ui.window.ComposeUIViewController
import com.google.samples.apps.niacatalog.ui.NiaCatalog
fun MainViewController() = ComposeUIViewController { NiaCatalog() }
Loading…
Cancel
Save