-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resources improvements for native macOS app (#5169)
First commit fixes compose resources for native macOS app (see currently broken chat app using `runDebugExecutableMacosArm64`). Second commit adds support for embedding resources into native macOS framework. Similar to how it works on iOS. This allows using the macOS compose code in an Xcode project. Just like iOS, using kotlin code as framwork. Then call the main function from the Xcode project to run the compose app. ## Testing First commit: run chat app using `runDebugExecutableMacosArm64` Second commit: Tested by adding macOS support to the iOS Xcode project in chat app (not in this PR). Can add the sample app if needed.
- Loading branch information
1 parent
e912311
commit 5870305
Showing
19 changed files
with
417 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
.../kmpResourcePublication/appModule/src/macosMain/composeResources/values/macos_strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="macOS_str">macOS string</string> | ||
</resources> |
10 changes: 10 additions & 0 deletions
10
...cts/misc/kmpResourcePublication/appModule/src/macosMain/kotlin/me/sample/app/App.macos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package me.sample.app | ||
|
||
import androidx.compose.runtime.Composable | ||
import kmpresourcepublication.appmodule.generated.resources.Res | ||
import kmpresourcepublication.appmodule.generated.resources.macOS_str | ||
import org.jetbrains.compose.resources.stringResource | ||
|
||
@Composable | ||
actual fun getPlatformSpecificString(): String = | ||
stringResource(Res.string.macOS_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
gradle-plugins/compose/src/test/test-projects/misc/macosResources/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("plugin.compose") | ||
kotlin("native.cocoapods") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
kotlin { | ||
cocoapods { | ||
version = "1.0" | ||
summary = "Some description for a Kotlin/Native module" | ||
homepage = "Link to a Kotlin/Native module homepage" | ||
pod("Base64", "1.1.2") | ||
framework { | ||
baseName = "shared" | ||
isStatic = true | ||
} | ||
} | ||
|
||
macosX64() | ||
macosArm64() | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(compose.runtime) | ||
implementation(compose.material) | ||
implementation(compose.components.resources) | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...lugins/compose/src/test/test-projects/misc/macosResources/expected/macosResources.podspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Pod::Spec.new do |spec| | ||
spec.name = 'macosResources' | ||
spec.version = '1.0' | ||
spec.homepage = 'Link to a Kotlin/Native module homepage' | ||
spec.source = { :http=> ''} | ||
spec.authors = '' | ||
spec.license = '' | ||
spec.summary = 'Some description for a Kotlin/Native module' | ||
spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' | ||
spec.libraries = 'c++' | ||
|
||
spec.dependency 'Base64', '1.1.2' | ||
|
||
if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework') | ||
raise " | ||
Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated. | ||
'pod install' should be executed after running ':generateDummyFramework' Gradle task: | ||
./gradlew :generateDummyFramework | ||
Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)" | ||
end | ||
|
||
spec.xcconfig = { | ||
'ENABLE_USER_SCRIPT_SANDBOXING' => 'NO', | ||
} | ||
|
||
spec.pod_target_xcconfig = { | ||
'KOTLIN_PROJECT_PATH' => '', | ||
'PRODUCT_MODULE_NAME' => 'shared', | ||
} | ||
|
||
spec.script_phases = [ | ||
{ | ||
:name => 'Build macosResources', | ||
:execution_position => :before_compile, | ||
:shell_path => '/bin/sh', | ||
:script => <<-SCRIPT | ||
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then | ||
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" | ||
exit 0 | ||
fi | ||
set -ev | ||
REPO_ROOT="$PODS_TARGET_SRCROOT" | ||
"$REPO_ROOT/gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ | ||
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ | ||
-Pkotlin.native.cocoapods.archs="$ARCHS" \ | ||
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION" | ||
SCRIPT | ||
} | ||
] | ||
spec.resources = ['build/compose/cocoapods/compose-resources'] | ||
end |
2 changes: 2 additions & 0 deletions
2
gradle-plugins/compose/src/test/test-projects/misc/macosResources/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.gradle.jvmargs=-Xmx8096M | ||
org.jetbrains.compose.experimental.macos.enabled=true |
Oops, something went wrong.