Browse Source

Unify build.gradle.kts for experimental samples (#2445)

+ add Android traget for Minesweeper example
pull/2447/head
Nikita Lipsky 2 years ago committed by GitHub
parent
commit
85faea7243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      experimental/examples/chat-mpp/build.gradle.kts
  2. 1
      experimental/examples/chat-mpp/gradle.properties
  3. 11
      experimental/examples/chat-mpp/settings.gradle.kts
  4. 3
      experimental/examples/chat-mpp/src/androidMain/res/res/values/strings.xml
  5. 2
      experimental/examples/chat-mpp/src/androidMain/res/values/strings.xml
  6. 45
      experimental/examples/falling-balls-mpp/build.gradle.kts
  7. 1
      experimental/examples/falling-balls-mpp/gradle.properties
  8. 1
      experimental/examples/falling-balls-mpp/settings.gradle.kts
  9. 2
      experimental/examples/falling-balls-mpp/src/androidMain/res/values/strings.xml
  10. 82
      experimental/examples/minesweeper/build.gradle.kts
  11. 10
      experimental/examples/minesweeper/gradle.properties
  12. 15
      experimental/examples/minesweeper/settings.gradle.kts
  13. 22
      experimental/examples/minesweeper/src/androidMain/AndroidManifest.xml
  14. 15
      experimental/examples/minesweeper/src/androidMain/kotlin/MainActivity.kt
  15. 7
      experimental/examples/minesweeper/src/androidMain/kotlin/actualfuns.android.kt
  16. 3
      experimental/examples/minesweeper/src/androidMain/res/values/strings.xml
  17. 23
      experimental/examples/minesweeper/src/commonMain/kotlin/game.kt
  18. 51
      experimental/examples/minesweeper/src/commonMain/kotlin/gameInteraction.kt
  19. 2
      experimental/examples/minesweeper/src/desktopMain/kotlin/main.desktop.kt
  20. 0
      experimental/examples/minesweeper/src/desktopMain/resources/assets/clock.png
  21. 0
      experimental/examples/minesweeper/src/desktopMain/resources/assets/flag.png
  22. 0
      experimental/examples/minesweeper/src/desktopMain/resources/assets/mine.png
  23. 19
      experimental/examples/minesweeper/src/jsMain/kotlin/main.js.kt
  24. 19
      experimental/examples/minesweeper/src/macosMain/kotlin/main.macos.kt
  25. 31
      experimental/examples/minesweeper/src/uikitMain/kotlin/main.uikit.kt

18
experimental/examples/chat-mpp/build.gradle.kts

@ -50,7 +50,7 @@ kotlin {
// Workaround for an issue:
// https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location
// Compose comiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// Compose compiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// TODO: remove workaround when switch to Kotlin 1.8
val disableKonanVerification = "-Xverify-compiler=false"
@ -103,15 +103,15 @@ kotlin {
dependsOn(commonMain)
kotlin.srcDirs("src/jvmMain/kotlin")
dependencies {
api("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.activity:activity-compose:1.4.0")
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-compose:1.5.0")
}
}
val desktopMain by getting {
dependencies {
dependencies {
implementation(compose.desktop.currentOs)
}
}
}
val jsMain by getting {
@ -195,13 +195,6 @@ afterEvaluate {
}
}
// TODO: remove when https://youtrack.jetbrains.com/issue/KT-50778 fixed
project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.java).configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xir-dce-runtime-diagnostic=log"
)
}
android {
compileSdk = 32
@ -222,4 +215,3 @@ android {
}
}
}

1
experimental/examples/chat-mpp/gradle.properties

@ -7,6 +7,7 @@ kotlin.native.cacheKind=none
kotlin.native.useEmbeddableCompilerJar=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableGranularSourceSetsMetadata=true
# Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true
android.useAndroidX=true

11
experimental/examples/chat-mpp/settings.gradle.kts

@ -1,6 +1,7 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
@ -8,15 +9,13 @@ pluginManagement {
plugins {
val kotlinVersion = extra["kotlin.version"] as String
val agpVersion = extra["agp.version"] as String
val composeVersion = extra["compose.version"] as String
kotlin("jvm").version(kotlinVersion)
kotlin("multiplatform").version(kotlinVersion)
kotlin("android").version(kotlinVersion)
id("com.android.base").version(agpVersion)
val agpVersion = extra["agp.version"] as String
id("com.android.application").version(agpVersion)
id("com.android.library").version(agpVersion)
val composeVersion = extra["compose.version"] as String
id("org.jetbrains.compose").version(composeVersion)
}
}

3
experimental/examples/chat-mpp/src/androidMain/res/res/values/strings.xml

@ -1,3 +0,0 @@
<resources>
<string name="app_name">Chat app</string>
</resources>

2
experimental/examples/chat-mpp/src/androidMain/res/values/strings.xml

@ -1,3 +1,3 @@
<resources>
<string name="app_name">Chat app</string>
<string name="app_name">Chat</string>
</resources>

45
experimental/examples/falling-balls-mpp/build.gradle.kts

@ -5,15 +5,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.compose.experimental.dsl.IOSDevices
buildscript {
repositories {
mavenLocal()
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
plugins {
id("com.android.application")
kotlin("multiplatform")
@ -24,10 +15,10 @@ version = "1.0-SNAPSHOT"
repositories {
mavenLocal()
google()
mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()}
}
kotlin {
android()
@ -56,6 +47,13 @@ kotlin {
}
}
}
// Workaround for an issue:
// https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location
// Compose compiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// TODO: remove workaround when switch to Kotlin 1.8
val disableKonanVerification = "-Xverify-compiler=false"
iosX64("uikitX64") {
binaries {
executable() {
@ -63,7 +61,8 @@ kotlin {
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
"-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
)
}
}
@ -75,10 +74,9 @@ kotlin {
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
"-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
)
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
@ -187,15 +185,6 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
kotlin {
targets.withType<KotlinNativeTarget> {
binaries.all {
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
compose.desktop.nativeApplication {
targets(kotlin.targets.getByName("macosX64"))
distributions {
@ -214,14 +203,6 @@ afterEvaluate {
}
}
// TODO: remove when https://youtrack.jetbrains.com/issue/KT-50778 fixed
project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.java).configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xir-dce-runtime-diagnostic=log"
)
}
android {
compileSdk = 32

1
experimental/examples/falling-balls-mpp/gradle.properties

@ -11,6 +11,7 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true
android.useAndroidX=true
kotlin.js.webpack.major.version=4
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true

1
experimental/examples/falling-balls-mpp/settings.gradle.kts

@ -21,4 +21,3 @@ pluginManagement {
}
rootProject.name = "falling-balls-mpp"

2
experimental/examples/falling-balls-mpp/src/androidMain/res/values/strings.xml

@ -1,3 +1,3 @@
<resources>
<string name="app_name">Chat app</string>
<string name="app_name">Falling Balls</string>
</resources>

82
experimental/examples/minesweeper/build.gradle.kts

@ -5,30 +5,23 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.compose.experimental.dsl.IOSDevices
buildscript {
repositories {
mavenLocal()
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
plugins {
kotlin("multiplatform") version "1.7.10"
id("org.jetbrains.compose") version "1.3.0-alpha01-dev827"
id("com.android.application")
kotlin("multiplatform")
id("org.jetbrains.compose")
}
version = "1.0-SNAPSHOT"
repositories {
mavenLocal()
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
kotlin {
android()
jvm("desktop")
js(IR) {
browser()
@ -54,6 +47,13 @@ kotlin {
}
}
}
// Workaround for an issue:
// https://youtrack.jetbrains.com/issue/KT-53561/Invalid-LLVM-module-inlinable-function-call-in-a-function-with-debug-info-must-have-a-dbg-location
// Compose compiler produces nodes without line information sometimes that provokes Kotlin native compiler to report errors.
// TODO: remove workaround when switch to Kotlin 1.8
val disableKonanVerification = "-Xverify-compiler=false"
iosX64("uikitX64") {
binaries {
executable() {
@ -61,22 +61,22 @@ kotlin {
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
"-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
)
}
}
}
iosArm64("uikitArm64") {
binaries {
executable() {
binaries {
executable() {
entryPoint = "main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
"-linker-option", "-framework", "-linker-option", "CoreGraphics",
disableKonanVerification
)
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
@ -88,15 +88,23 @@ kotlin {
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.runtime)
//TODO hotfix of issue https://github.com/JetBrains/compose-jb/issues/2113
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependsOn(commonMain)
kotlin.srcDirs("src/jvmMain/kotlin")
dependencies {
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-compose:1.5.0")
}
}
@ -180,15 +188,6 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
kotlin {
targets.withType<KotlinNativeTarget> {
binaries.all {
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
// a temporary workaround for a bug in jsRun invocation - see https://youtrack.jetbrains.com/issue/KT-48273
afterEvaluate {
rootProject.extensions.configure<NodeJsRootExtension> {
@ -197,3 +196,24 @@ afterEvaluate {
nodeVersion = "16.0.0"
}
}
android {
compileSdk = 32
defaultConfig {
minSdk = 26
targetSdk = 32
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/res", "src/commonMain/resources")
}
}
}

10
experimental/examples/minesweeper/gradle.properties

@ -1,11 +1,17 @@
compose.version=1.3.0-alpha01-dev827
kotlin.version=1.7.10
agp.version=7.0.4
org.gradle.jvmargs=-Xmx3g
kotlin.code.style=official
kotlin.native.cacheKind=none
kotlin.native.useEmbeddableCompilerJar=true
org.gradle.jvmargs=-Xmx3g
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableGranularSourceSetsMetadata=true
# Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true
android.useAndroidX=true
kotlin.js.webpack.major.version=4
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true

15
experimental/examples/minesweeper/settings.gradle.kts

@ -1,11 +1,22 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
plugins {
val kotlinVersion = extra["kotlin.version"] as String
kotlin("multiplatform").version(kotlinVersion)
kotlin("android").version(kotlinVersion)
val agpVersion = extra["agp.version"] as String
id("com.android.application").version(agpVersion)
val composeVersion = extra["compose.version"] as String
id("org.jetbrains.compose").version(composeVersion)
}
}
rootProject.name = "minesweeper"

22
experimental/examples/minesweeper/src/androidMain/AndroidManifest.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jetbrains.minesweeper">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:exported="true"
android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

15
experimental/examples/minesweeper/src/androidMain/kotlin/MainActivity.kt

@ -0,0 +1,15 @@
package org.jetbrains.minesweeper
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import Game
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Game()
}
}
}

7
experimental/examples/minesweeper/src/androidMain/kotlin/actualfuns.android.kt

@ -0,0 +1,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
@Composable
actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
actual fun isMobileDevice() = true

3
experimental/examples/minesweeper/src/androidMain/res/values/strings.xml

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Minesweeper</string>
</resources>

23
experimental/examples/minesweeper/src/commonMain/kotlin/game.kt

@ -5,7 +5,9 @@ import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.ui.*
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.*
import kotlin.math.max
@ -13,6 +15,27 @@ import kotlin.math.max
@Composable
expect fun loadImage(src: String): Painter
fun loadImageAsColoredRect(src: String): Painter {
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
override fun DrawScope.onDraw() {
drawRect(color = color)
}
}
}
expect fun isMobileDevice(): Boolean
object Difficulty {
val EASY = GameSettings(9, 9, 10)
val MEDIUM = GameSettings(16, 16, 40)

51
experimental/examples/minesweeper/src/commonMain/kotlin/gameInteraction.kt

@ -1,30 +1,47 @@
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.*
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Modifier.gameInteraction(open: () -> Unit, flag: () -> Unit, seek: () -> Unit): Modifier =
pointerInput(open, flag, seek) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent(PointerEventPass.Main)
with(event) {
if (type == PointerEventType.Press) {
// TODO does not work yet, all events are of Unknown type (
val lmb = buttons.isPrimaryPressed
val rmb = buttons.isSecondaryPressed
if (isMobileDevice()) {
combinedClickable(
onClick = {
open()
},
onDoubleClick = {
seek()
},
onLongClick = {
flag()
}
)
} else {
pointerInput(open, flag, seek) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent(PointerEventPass.Main)
with(event) {
if (type == PointerEventType.Press) {
// TODO does not work yet, all events are of Unknown type (
val lmb = buttons.isPrimaryPressed
val rmb = buttons.isSecondaryPressed
if (lmb && !rmb) {
if (keyboardModifiers.isShiftPressed) {
seek()
} else {
open()
if (lmb && !rmb) {
if (keyboardModifiers.isShiftPressed) {
seek()
} else {
open()
}
} else if (rmb && !lmb) {
flag()
}
} else if (rmb && !lmb) {
flag()
}
}
}
}
}
}
}

2
experimental/examples/minesweeper/src/desktopMain/kotlin/main.desktop.kt

@ -28,3 +28,5 @@ fun main() = application {
@Composable
actual fun loadImage(src: String): Painter = painterResource(src)
actual fun isMobileDevice() = false

0
experimental/examples/minesweeper/src/commonMain/resources/assets/clock.png → experimental/examples/minesweeper/src/desktopMain/resources/assets/clock.png

Before

Width:  |  Height:  |  Size: 896 B

After

Width:  |  Height:  |  Size: 896 B

0
experimental/examples/minesweeper/src/commonMain/resources/assets/flag.png → experimental/examples/minesweeper/src/desktopMain/resources/assets/flag.png

Before

Width:  |  Height:  |  Size: 780 B

After

Width:  |  Height:  |  Size: 780 B

0
experimental/examples/minesweeper/src/commonMain/resources/assets/mine.png → experimental/examples/minesweeper/src/desktopMain/resources/assets/mine.png

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

19
experimental/examples/minesweeper/src/jsMain/kotlin/main.js.kt

@ -19,21 +19,6 @@ fun main() {
}
@Composable
actual fun loadImage(src: String): Painter {
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
override fun DrawScope.onDraw() {
drawRect(color = color)
}
}
}
actual fun isMobileDevice() = false

19
experimental/examples/minesweeper/src/macosMain/kotlin/main.macos.kt

@ -30,21 +30,6 @@ fun main() {
}
@Composable
actual fun loadImage(src: String): Painter {
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
override fun DrawScope.onDraw() {
drawRect(color = color)
}
}
}
actual fun isMobileDevice() = false

31
experimental/examples/minesweeper/src/uikitMain/kotlin/main.uikit.kt

@ -3,46 +3,21 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Application
import androidx.compose.ui.main.defaultUIKitMain
fun main() {
defaultUIKitMain("Minesweeper", Application("Minesweeper") {
Column {
// To skip upper part of screen.
Box(modifier = Modifier
.height(100.dp))
Game()
}
Game()
})
}
@Composable
actual fun loadImage(src: String): Painter {
// TODO Bundle pics and show images properly
val color = when (src) {
"assets/clock.png" -> Color.Blue
"assets/flag.png" -> Color.Green
"assets/mine.png" -> Color.Red
else -> Color.White
}
actual fun loadImage(src: String): Painter = loadImageAsColoredRect(src)
return object : Painter() {
override val intrinsicSize: Size
get() = Size(16f, 16f)
override fun DrawScope.onDraw() {
drawRect(color = color)
}
}
}
actual fun isMobileDevice() = true
Loading…
Cancel
Save