Skip to content

Commit

Permalink
KTOR-7832 Rewrite client-mpp sample to fix build errors (#211)
Browse files Browse the repository at this point in the history
* upgrade AGP plugin

* migrate Gradle to Kotlin DSL

* migrate Gradle to Kotlin DSL

* update iOS app

* rename macApp subproject to desktopApp, as more suitable name

* fix warning
  • Loading branch information
stokado authored Jan 8, 2025
1 parent f71470c commit 184239a
Show file tree
Hide file tree
Showing 23 changed files with 212 additions and 218 deletions.
6 changes: 3 additions & 3 deletions client-mpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
A sample project showing how to use a Ktor client in a [multiplatform application](https://ktor.io/docs/getting-started-ktor-client-multiplatform-mobile.html).

## Running
An application works on the following platforms: `Android`, `iOS`, `JavaScript`, and `macosX64`. To run the application, open it in IntelliJ IDEA and do one of the following:
An application works on the following platforms: `Android`, `iOS`, `JavaScript`, and `macosArm64`. To run the application, open it in IntelliJ IDEA and do one of the following:
* To run the Android application, use the `client-mpp.androidApp` [run configuration](https://www.jetbrains.com/help/idea/run-debug-configuration.html) created by IntelliJ IDEA automatically.

* To run the iOS application, open the [iosApp](iosApp) directory in Xcode and run it.
* To run the JavaScript application, execute the following command in a project's root directory:
```
./gradlew :jsApp:run
```
* To run `macosX64`, execute the following command in a project's root directory:
* To run `macosArm64`, execute the following command in a project's root directory:
```
./gradlew :macApp:runDebugExecutableNative
./gradlew :desktopApp:runDebugExecutableDesktop
```
34 changes: 0 additions & 34 deletions client-mpp/androidApp/build.gradle

This file was deleted.

35 changes: 35 additions & 0 deletions client-mpp/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

dependencies {
implementation(project(":shared"))
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
}

android {
compileSdk = 34
defaultConfig {
applicationId = "io.ktor.samples.mpp.client"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
}
buildTypes {
release {
isMinifyEnabled = false
}
}
packaging {
resources.excludes.add("META-INF/*.kotlin_module")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
namespace = "io.ktor.samples.mpp.client"
}
4 changes: 2 additions & 2 deletions client-mpp/androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.ktor.samples.mpp.client">
>

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
4 changes: 2 additions & 2 deletions client-mpp/build.gradle → client-mpp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
classpath("com.android.tools.build:gradle:7.0.4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0")
classpath("com.android.tools.build:gradle:8.6.1")
}
}

Expand Down
25 changes: 25 additions & 0 deletions client-mpp/desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id("org.jetbrains.kotlin.multiplatform")
}

kotlin {
// on Linux X64
// linuxX64("desktop")
// on Windows x64
// mingwX64("desktop")
// on MacOs X64
// macosX64("desktop")
// on MacOS Arm64
macosArm64("desktop") {
binaries {
executable()
}
}
sourceSets {
nativeMain {
dependencies {
implementation(project(":shared"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

fun main() = runBlocking {
val result = suspendCoroutine<String> { continuation ->
val result = suspendCoroutine { continuation ->
ApplicationApi().about {
continuation.resume(it)
}
Expand Down
12 changes: 10 additions & 2 deletions client-mpp/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
android.useAndroidX=true
kotlin.native.binary.memoryModel=experimental
#Kotlin
kotlin.code.style=official
kotlin.daemon.jvmargs=-Xmx2048M

#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8

#Android
android.nonTransitiveRClass=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion client-mpp/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 4 additions & 21 deletions client-mpp/iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
7555FF8B242A565B00829871 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7555FF89242A565B00829871 /* LaunchScreen.storyboard */; };
7555FF96242A565B00829871 /* iosAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF95242A565B00829871 /* iosAppTests.swift */; };
7555FFA1242A565B00829871 /* iosAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FFA0242A565B00829871 /* iosAppUITests.swift */; };
7555FFB2242A642300829871 /* shared.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7555FFB1242A642300829871 /* shared.framework */; };
7555FFB3242A642300829871 /* shared.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7555FFB1242A642300829871 /* shared.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -36,20 +34,6 @@
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
7555FFB4242A642300829871 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
7555FFB3242A642300829871 /* shared.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
7555FF7B242A565900829871 /* iosApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF7E242A565900829871 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -73,7 +57,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
7555FFB2242A642300829871 /* shared.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -170,11 +153,10 @@
isa = PBXNativeTarget;
buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */;
buildPhases = (
7555FFB5242A651A00829871 /* ShellScript */,
7555FFB5242A651A00829871 /* Compile Kotlin Framework */,
7555FF77242A565900829871 /* Sources */,
7555FF78242A565900829871 /* Frameworks */,
7555FF79242A565900829871 /* Resources */,
7555FFB4242A642300829871 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -292,7 +274,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
7555FFB5242A651A00829871 /* ShellScript */ = {
7555FFB5242A651A00829871 /* Compile Kotlin Framework */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -301,13 +283,14 @@
);
inputPaths = (
);
name = "Compile Kotlin Framework";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:packForXCode -PXCODE_CONFIGURATION=${CONFIGURATION}\n";
shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
15 changes: 0 additions & 15 deletions client-mpp/jsApp/build.gradle

This file was deleted.

19 changes: 19 additions & 0 deletions client-mpp/jsApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("org.jetbrains.kotlin.multiplatform")
}

kotlin {
js(IR) {
browser {
}
binaries.executable()
}

sourceSets {
val jsMain by getting {
dependencies {
implementation(project(":shared"))
}
}
}
}
File renamed without changes.
22 changes: 0 additions & 22 deletions client-mpp/macApp/build.gradle

This file was deleted.

11 changes: 5 additions & 6 deletions client-mpp/settings.gradle → client-mpp/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ pluginManagement {
gradlePluginPortal()
mavenCentral()
}

}
rootProject.name = 'client-mpp'

rootProject.name = "client-mpp"

include(':androidApp')
include(':macApp')
include(':jsApp')
include(':shared')
include(":androidApp")
include(":desktopApp")
include(":jsApp")
include(":shared")
Loading

0 comments on commit 184239a

Please sign in to comment.