Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fernandospr/minimal-android-ios-backend-lib
Minimal Kotlin library to share logic in Android, iOS and JVM Backend projects.
https://github.com/fernandospr/minimal-android-ios-backend-lib
android backend ios jvm kotlin kotlin-multiplatform library swift
Last synced: 20 days ago
JSON representation
Minimal Kotlin library to share logic in Android, iOS and JVM Backend projects.
- Host: GitHub
- URL: https://github.com/fernandospr/minimal-android-ios-backend-lib
- Owner: fernandospr
- Created: 2022-07-05T17:41:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-23T12:38:49.000Z (12 months ago)
- Last Synced: 2024-11-08T10:50:42.052Z (2 months ago)
- Topics: android, backend, ios, jvm, kotlin, kotlin-multiplatform, library, swift
- Language: Swift
- Homepage:
- Size: 1.13 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Demonstrates a minimal Kotlin library to share logic in Android, iOS and JVM Backend projects using Kotlin Multiplatform.
This repository contains the following folders:
* minimal-android-ios-backend-lib
* android-sample-app
* ios-sample-app
* backend-sample-app## minimal-android-ios-backend-lib
Contains the Kotlin code to share across platforms.You'll find this simple class:
```kotlin
class Example {
fun hello(who: String) = "Hello $who!"
}
```
### Compiling the library for Android/JVM apps
1. Execute the Gradle Task: `publishToMavenLocal` using `./gradlew publishToMavenLocal`.
This task will publish in your `~/.m2/repository` folder.2. Open the Android/JVM/Backend client project and make sure you have `mavenLocal()` in your repositories configuration.
3. Add the dependency:
* For Android: `implementation("{group}:{rootProject.name}-android:{version}")`. For this example, it's `implementation("com.github.fernandospr:minimal-android-ios-backend-lib-android:1.0.0")`.
* For JVM: `implementation("{group}:{rootProject.name}-jvm:{version}")`. For this example, it's `implementation("com.github.fernandospr:minimal-android-ios-backend-lib-jvm:1.0.0")`.
4. Now in your Android/JVM app code you can import the library classes.
### Compiling the library for iOS apps
1. Execute the Gradle Task: `assemble{libName}ReleaseXCFramework` using `./gradlew assemble{libName}ReleaseXCFramework`. For this example, it's `./gradlew assembleMAIBLibReleaseXCFramework`. This task will generate the framework in `build/XCFrameworks/release` of the library project.
2. Copy the framework to your iOS client project.
3. Open your iOS client project using Xcode, go to the project properties, open `General` tab and add the framework in the `Frameworks, Libraries and Embedded Content` section.
4. Now in your iOS app code you can import the library classes.## android-sample-app
Contains a sample Android App that uses the library.To build this app you'll need to compile the library locally first, as explained above.
`MainActivity.kt` contains the following code that uses the `Example` class from the library:
```kotlin
import com.github.fernandospr.maiblib.Exampleclass MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
...
val example = Example()
findViewById(R.id.textView).text = example.hello("Fernando")
}
}
```### Screenshots
## ios-sample-app
Contains a sample iOS App that uses the library.To build this app you'll need to compile the library locally and copy it to the iOS project folder, as explained above.
`ViewController.swift` contains the following code that uses the `Example` class from the library:
```swift
import MAIBLibclass ViewController: UIViewController {
...
override func viewDidLoad() {
...
let example = Example()
label.text = example.hello(who: "Fernando")
}
}
```### Screenshots
## backend-sample-app
Contains a sample Kotlin Backend App that uses the library.To build this app you'll need to compile the library locally first, as explained above.
`Controller.kt` contains the following code that uses the `Example` class from the library:
```kotlin
import com.github.fernandospr.maiblib.Example@RestController
@RequestMapping("/web")
class WebController {@GetMapping("/hello")
fun hello(@RequestParam("who") who: String) = Example().hello(who)
}@RestController
@RequestMapping("/api")
class ApiController {@GetMapping("/hello")
fun hello(@RequestParam("who") who: String) = ApiResponse(Example().hello(who))
}
```### Screenshots
Using the `Example` class in a Web server that returns a String:Using the `Example` class in an API that returns JSON: