diff --git a/docs/getStarted.html b/docs/getStarted.html index f247837..8cfbb38 100644 --- a/docs/getStarted.html +++ b/docs/getStarted.html @@ -50,7 +50,7 @@
Before setting up Swift for Android, ensure that you have Android Studio installed on your macOS. Follow these steps: @@ -93,7 +93,7 @@
To create a new Swift Package Manager (SPM) project within the app/src/main/swift
subdirectory, run the following commands in the terminal:
-cd SwiftAndroidExample/app/src/main/swift ++
- +
+ Create a new SPM project within the
+app/src/main/swift
subdirectory, run the following + commands in the terminal from the root project directory: +++ ++mkdir -p app/src/main/swift +cd app/src/main/swift swift package init --name SwiftAndroidExample-
+ It will create a new SPM project named SwiftAndroidExample
within the
+ app/src/main/swift
subdirectory.This project follows the standard structure of
+ an SPM project and will be automatically built by Gradle as part of the Android project's
+ build process with custom build tasks configured in the build.gradle file.
+
+ Change the product type to a dynamic library in the SPM project manifest. To do that,
+ add the type: .dynamic
parameter in the library description in the
+ Package.swift
file located in the SPM project directory:
+
+products: [ + .library( + name: "SwiftAndroidExample", + type: .dynamic, // add this line + targets: ["SwiftAndroidExample"]), +], ++
-It will set up a new SPM project named-SwiftAndroidExample
inside theswift
subdirectory. -This project structure allows you to efficiently manage Swift dependencies and build your Swift code as a separate module within your Android Studio project. -
+ To configure SPM project build, make the following changes in the build.gradle
file:
+
app/build.gradle
file.android
section:
-android {
- sourceSets {
- main {
- jniLibs.srcDirs = ["lib"]
- }
+sourceSets {
+ main {
+ jniLibs.srcDirs = ["lib"]
}
}
@@ -156,14 +187,14 @@ dependencies
section, include:
+ In the dependencies
section, add:
-In the dependencies section, include: + implementation fileTree(dir: 'lib', include: ['*.jar'])
MainActivity.java
, add Swift runtime initialization in the onCreate
method:
+ ++ In
+ +MainActivity.java
, add the following code in theonCreate
method + which performs required Swift runtime initialization and loads theSwiftAndroidExample
+ JNI library containing Swift code from the SPM project: ++- - +@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + // Initialize Swift runtime and Swift Foundation library try { org.swift.swiftfoundation.SwiftFoundation.Initialize(this, false); } catch (Exception err) { android.util.Log.e("Swift", "Can't initialize Swift Foundation: " + err.toString()); } - // Continue with your activity code -} --
-System.loadLibrary("SwiftAndroidExample"); + // other activity initialization code +}-
In your Android application, you can declare Java methods that serve as bridges to Swift code. The implementation of these methods will be written in Swift, allowing seamless integration between the two languages. Here's an example: