Skip to content

Commit aee2a88

Browse files
committed
Compile for Previews
1 parent 8d219ba commit aee2a88

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Demo/app/src/main/java/com/pureswift/swiftandroid/MainActivity.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class MainActivity : ComponentActivity() {
2020
}
2121

2222
private fun loadNativeLibrary() {
23-
System.loadLibrary("icuuc")
24-
System.loadLibrary("icui18n")
2523
System.loadLibrary("Foundation")
2624
System.loadLibrary("SwiftAndroidApp")
2725
}
@@ -45,6 +43,14 @@ class MainActivity : ComponentActivity() {
4543

4644
class MainActivityHello {
4745

46+
init {
47+
loadNativeLibrary()
48+
}
49+
50+
private fun loadNativeLibrary() {
51+
System.loadLibrary("SwiftAndroidApp")
52+
}
53+
4854
external fun sayHelloName(): String
4955
}
5056

@@ -60,6 +66,6 @@ fun Greeting(name: String, modifier: Modifier = Modifier) {
6066
@Composable
6167
fun GreetingPreview() {
6268
SwiftAndroidTheme {
63-
Greeting("Android")
69+
Greeting(MainActivityHello().sayHelloName())
6470
}
6571
}

Demo/build-swift.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ set -e
33
source swift-define
44

55
# Build with SwiftPM
6-
xcrun --toolchain swift swift build -c debug \
7-
--swift-sdk aarch64-unknown-linux-android24 \
6+
xcrun --toolchain swift swift build -c $SWIFT_COMPILATION_MODE \
7+
--swift-sdk $SWIFT_TARGET_NAME \
88
--toolchain $XCTOOLCHAIN \
99
--package-path $SWIFT_PACKAGE_SRC
1010

1111
# Copy compiled Swift package
1212
mkdir -p $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/
13-
cp -rf $SWIFT_PACKAGE_SRC/.build/aarch64-unknown-linux-android24/debug/libSwiftAndroidApp.so \
13+
cp -rf $SWIFT_PACKAGE_SRC/.build/$SWIFT_TARGET_NAME/debug/libSwiftAndroidApp.so \
1414
$SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/
15+
16+
# Build locally for preview
17+
xcrun --toolchain swift swift build -c $SWIFT_COMPILATION_MODE \
18+
--package-path $SWIFT_PACKAGE_SRC
19+
20+
# Copy to default Java JNI path
21+
mkdir -p ~/Library/Java/Extensions
22+
cp -rf $SWIFT_PACKAGE_SRC/.build/arm64-apple-macosx/debug/libSwiftAndroidApp.dylib \
23+
~/Library/Java/Extensions/

Demo/swift-define

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SRC_ROOT="${SRC_ROOT:=$(pwd)}"
33
SWIFT_TARGET_ARCH="${SWIFT_TARGET_ARCH:=aarch64}"
44
ANDROID_ARCH="${ANDROID_ARCH:=arm64-v8a}"
55
ANDROID_LIB="${ANDROID_LIB:=aarch64-linux-android}"
6+
SWIFT_COMPILATION_MODE="${SWIFT_COMPILATION_MODE:=debug}"
67

78
# Version
89
ANDROID_NDK_VERSION=24

0 commit comments

Comments
 (0)