diff --git a/hello-swift-java/hashing-app/src/main/java/com/example/hashingapp/MainActivity.kt b/hello-swift-java/hashing-app/src/main/java/com/example/hashingapp/MainActivity.kt
index 24cd5c8..ca1db54 100644
--- a/hello-swift-java/hashing-app/src/main/java/com/example/hashingapp/MainActivity.kt
+++ b/hello-swift-java/hashing-app/src/main/java/com/example/hashingapp/MainActivity.kt
@@ -91,4 +91,4 @@ fun HashScreen() {
)
}
}
-}
\ No newline at end of file
+}
diff --git a/hello-swift-java/hashing-lib/Package.swift b/hello-swift-java/hashing-lib/Package.swift
index 0295118..0b82eea 100644
--- a/hello-swift-java/hashing-lib/Package.swift
+++ b/hello-swift-java/hashing-lib/Package.swift
@@ -47,7 +47,8 @@ let package = Package(
.library(
name: "SwiftHashing",
type: .dynamic,
- targets: ["SwiftHashing"])
+ targets: ["SwiftHashing"]
+ )
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-java", branch: "main"),
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 0be2778..fbd42d8 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -29,6 +29,11 @@ project(":hello-swift-java-hashing-lib").projectDir = file("hello-swift-java/has
include(":hello-swift-java-hashing-app")
project(":hello-swift-java-hashing-app").projectDir = file("hello-swift-java/hashing-app")
+include(":swift-java-weather-app-weather-lib")
+project(":swift-java-weather-app-weather-lib").projectDir = file("swift-java-weather-app/weather-lib")
+include(":swift-java-weather-app-weather-app")
+project(":swift-java-weather-app-weather-app").projectDir = file("swift-java-weather-app/weather-app")
+
// raw-jni examples
include(":hello-swift-raw-jni")
include(":hello-swift-raw-jni-callback")
diff --git a/swift-java-weather-app/.gitignore b/swift-java-weather-app/.gitignore
new file mode 100644
index 0000000..6e582d1
--- /dev/null
+++ b/swift-java-weather-app/.gitignore
@@ -0,0 +1,41 @@
+.DS_STORE
+
+# Swift
+.build/
+.swiftpm/
+Package.resolved
+
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Log/OS Files
+*.log
+
+# Android Studio generated files and folders
+captures/
+.externalNativeBuild/
+.cxx/
+*.aab
+*.apk
+output-metadata.json
+
+# IntelliJ
+*.iml
+.idea/
+misc.xml
+deploymentTargetDropDown.xml
+render.experimental.xml
+
+# Keystore files
+*.jks
+*.keystore
+
+# Google Services (e.g. APIs or Firebase)
+google-services.json
+
+# Android Profiling
+*.hprof
\ No newline at end of file
diff --git a/swift-java-weather-app/README.md b/swift-java-weather-app/README.md
new file mode 100644
index 0000000..1343467
--- /dev/null
+++ b/swift-java-weather-app/README.md
@@ -0,0 +1,95 @@
+# swift-java on Android
+
+This example contains a sample Android application that demonstrates how to call Swift code from an Android app.
+It shows you how to call `async` Swift functions from Kotlin/Java and also how it is possible
+to implement a Swift `protocol` using a Java class and pass that back to Swift.
+
+The example consists of an Android application (`weather-app`) and a Swift library (`weather-lib`) that fetches the weather for the current location. The Swift library uses [swift-java](https://github.com/swiftlang/swift-java) and the new JNI mode to **automatically generate Java wrappers** for calling into the Swift library.
+
+
+
+## Overview
+
+The project is structured into two main parts:
+### **`weather-lib`**:
+A Swift package that uses `swift-openapi-generator` to call the [Open-Meteo Weather API](https://open-meteo.com/). It is configured with a Gradle build script (`build.gradle`). This module utilizes the [swift-java](https://github.com/swiftlang/swift-java) project to create the necessary JNI bindings.
+
+The Swift library exposes a Swift `protocol` named `LocationFetcher`, which is used by `WeatherClient` to
+retrieve the current user location. This is a traditional API design in Swift, and allows any consumers
+of the library to provide their own mechanism of retrieving the location. For iOS, this could mean using `CLLocationManager`.
+
+`swift-java` allows us to implement the `LocationFetcher` protocol using a Java class,
+and therefore use Android APIs to retrieve the user location and pass that back to Swift.
+This is implemented in the `LocationService` class.
+
+After fetching the user location, the `WeatherClient` will fetch the weather
+using the automatically generated OpenAPI bindings. This method is marked as `async`
+and we can easily call that from Java/Kotlin, where it will return a [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html)
+
+### **`weather-app`**:
+A standard Android application written in Kotlin using Jetpack Compose.
+
+## Prerequisites
+
+Before you can build and run this project, you need to have the following installed:
+
+* **Java Development Kit (JDK)**: This example requires the use of JDK 25. This is only necessary to locally publish the swift-java dependencies, and will not be required in the future. To simplify the build steps, we recommend installing JDK 25 and following all the steps below using the same JDK. Ensure the `JAVA_HOME` environment variable is set to your JDK installation path.
+* **Swiftly**: You need to install [Swiftly](https://www.swift.org/install/) to download the latest open-source Swift toolchain
+* **Swift SDK for Android**: You need to install the [Swift SDK for Android](https://swift.org/install)
+
+## Setup and Configuration
+
+### Prepare Swift Android SDK and matching Swift
+
+Currently, these examples utilize very recent nightly Swift Android SDK versions.
+
+You can follow [these instructions](https://www.swift.org/documentation/articles/swift-sdk-for-android-getting-started.html) to install an appropriate Swift SDK for Android.
+
+### Publish `swift-java` packages locally
+As the `swift-java` project does not yet publish the necessary Java packages needed at runtime, we need to do it ourselves, by performing the following steps:
+
+> Note: This step will not be necessary once swift-java publishes releases.
+
+In order to publish all artifacts from this library, you must use JDK 25, because some parts of swift-java are built for the most recent Java versions. You will not have to use JDK 25 for the rest of the development process.
+A simple way to install and manage local Java installations is [sdkman](https://sdkman.io):
+
+> Note: You will _not_ have to use most recent Java versions for your Android app, and the example currently targets Java language version 11.
+
+Here's how to install `sdkman`:
+```bash
+curl -s "https://get.sdkman.io" | bash
+```
+Now restart the terminal so that the `sdk` utility is added to your path, and then set JDK 25 as your current Java install.
+
+```bash
+sdk install java 25.0.1-amzn --use # only in order to publish swift-java artifacts locally
+export JAVA_HOME="${HOME}/.sdkman/candidates/java/current"
+```
+
+Next, let's prepare and publish the swift-java support libraries:
+
+1. Enter the `hashing-lib` directory
+ ```bash
+ cd weather-lib
+ ```
+2. Resolve Swift Packages
+ ```bash
+ swift package resolve
+ ```
+3. Publish the `swift-java` packages to local Maven repo
+ ```bash
+ ./.build/checkouts/swift-java/gradlew --project-dir .build/checkouts/swift-java :SwiftKitCore:publishToMavenLocal
+ ```
+
+## Running the example
+
+1. Open the `swift-android-examples` project in Android Studio.
+
+2. Select the `weather-app` Gradle target.
+
+3. Run the app on an Android emulator or a physical device.
+
+4. Press the "Fetch Weather" button.
+
+
+
diff --git a/swift-java-weather-app/resources/example.png b/swift-java-weather-app/resources/example.png
new file mode 100644
index 0000000..8d0a239
Binary files /dev/null and b/swift-java-weather-app/resources/example.png differ
diff --git a/swift-java-weather-app/weather-app/.gitignore b/swift-java-weather-app/weather-app/.gitignore
new file mode 100644
index 0000000..42afabf
--- /dev/null
+++ b/swift-java-weather-app/weather-app/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/build.gradle.kts b/swift-java-weather-app/weather-app/build.gradle.kts
new file mode 100644
index 0000000..61d00b0
--- /dev/null
+++ b/swift-java-weather-app/weather-app/build.gradle.kts
@@ -0,0 +1,63 @@
+plugins {
+ alias(libs.plugins.android.application)
+ alias(libs.plugins.kotlin.android)
+ alias(libs.plugins.kotlin.compose)
+}
+
+android {
+ namespace = "com.example.weatherapp"
+ compileSdk = 36
+
+ defaultConfig {
+ applicationId = "com.example.weatherapp"
+ minSdk = 28
+ targetSdk = 36
+ versionCode = 1
+ versionName = "1.0"
+
+ testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ buildTypes {
+ release {
+ isMinifyEnabled = false
+ proguardFiles(
+ getDefaultProguardFile("proguard-android-optimize.txt"),
+ "proguard-rules.pro"
+ )
+ }
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+ kotlinOptions {
+ jvmTarget = "17"
+ }
+ buildFeatures {
+ compose = true
+ }
+}
+
+dependencies {
+ implementation(libs.androidx.core.ktx)
+ implementation(libs.androidx.lifecycle.runtime.ktx)
+ implementation(libs.androidx.activity.compose)
+ implementation("androidx.fragment:fragment-ktx:1.7.1")
+ implementation(platform(libs.androidx.compose.bom))
+ implementation(libs.androidx.ui)
+ implementation(libs.androidx.ui.graphics)
+ implementation(libs.androidx.ui.tooling.preview)
+ implementation(libs.androidx.material3)
+ implementation("com.google.android.gms:play-services-location:21.0.1")
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4")
+ implementation("org.swift.swiftkit:swiftkit-core:1.0-SNAPSHOT")
+ implementation(project(":swift-java-weather-app-weather-lib"))
+ testImplementation(libs.junit)
+ androidTestImplementation(libs.androidx.junit)
+ androidTestImplementation(libs.androidx.espresso.core)
+ androidTestImplementation(platform(libs.androidx.compose.bom))
+ androidTestImplementation(libs.androidx.ui.test.junit4)
+ debugImplementation(libs.androidx.ui.tooling)
+ debugImplementation(libs.androidx.ui.test.manifest)
+}
diff --git a/swift-java-weather-app/weather-app/proguard-rules.pro b/swift-java-weather-app/weather-app/proguard-rules.pro
new file mode 100644
index 0000000..481bb43
--- /dev/null
+++ b/swift-java-weather-app/weather-app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/androidTest/java/com/example/weatherapp/ExampleInstrumentedTest.kt b/swift-java-weather-app/weather-app/src/androidTest/java/com/example/weatherapp/ExampleInstrumentedTest.kt
new file mode 100644
index 0000000..94455b3
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/androidTest/java/com/example/weatherapp/ExampleInstrumentedTest.kt
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+ @Test
+ fun useAppContext() {
+ // Context of the app under test.
+ val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+ assertEquals("com.example.weatherapp", appContext.packageName)
+ }
+}
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/AndroidManifest.xml b/swift-java-weather-app/weather-app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..0fa972c
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/AndroidManifest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/MainActivity.kt b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/MainActivity.kt
new file mode 100644
index 0000000..c773b4d
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/MainActivity.kt
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp
+
+import android.Manifest
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.activity.enableEdgeToEdge
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.activity.viewModels
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Button
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import com.example.weatherapp.ui.theme.WeatherAppTheme
+import com.example.weatherapp.viewmodel.WeatherViewModel
+
+class MainActivity : ComponentActivity() {
+
+ private val viewModel: WeatherViewModel by viewModels()
+
+ private val requestPermissionLauncher =
+ registerForActivityResult(
+ ActivityResultContracts.RequestPermission()
+ ) { isGranted: Boolean ->
+ if (isGranted) {
+ viewModel.fetchWeather()
+ }
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ enableEdgeToEdge()
+ setContent {
+ WeatherAppTheme {
+ Surface(
+ modifier = Modifier.fillMaxSize().padding(top = 64.dp),
+ color = MaterialTheme.colorScheme.background
+ ) {
+ WeatherScreen(viewModel) {
+ requestPermissionLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION)
+ }
+ }
+ }
+ }
+ }
+}
+
+@Composable
+fun WeatherScreen(viewModel: WeatherViewModel, onFetchWeatherClick: () -> Unit) {
+ val weatherData = viewModel.weatherData.collectAsState().value
+ val error = viewModel.error.collectAsState().value
+
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(32.dp),
+ verticalArrangement = Arrangement.spacedBy(12.dp)
+ ) {
+ Button(onClick = onFetchWeatherClick) {
+ Text("Fetch Weather")
+ }
+
+ weatherData?.let {
+ Text("Temperature: ${it.temperature}°C")
+ Text("Wind Speed: ${it.windSpeed} km/h")
+ Text("Wind Direction: ${it.windDirection}°")
+ }
+
+ error?.let {
+ Text("Error: $it", color = MaterialTheme.colorScheme.error)
+ }
+ }
+}
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/services/LocationService.kt b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/services/LocationService.kt
new file mode 100644
index 0000000..00b9b54
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/services/LocationService.kt
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp.services
+
+import android.Manifest
+import android.content.Context
+import android.content.pm.PackageManager
+import androidx.core.content.ContextCompat
+import com.google.android.gms.location.FusedLocationProviderClient
+import com.google.android.gms.location.LocationServices
+import com.example.weatherlib.LocationFetcher
+import com.example.weatherlib.Location
+import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.tasks.await
+import org.swift.swiftkit.core.SwiftArena
+
+typealias AndroidLocation = android.location.Location
+
+class LocationService(private val context: Context) : LocationFetcher {
+ private val arena = SwiftArena.ofAuto()
+
+ private val fusedLocationClient: FusedLocationProviderClient =
+ LocationServices.getFusedLocationProviderClient(context)
+
+ override fun currentLocation(`swiftArena$`: SwiftArena?): Location {
+ val androidLocation: AndroidLocation? = if (ContextCompat.checkSelfPermission(
+ context,
+ Manifest.permission.ACCESS_FINE_LOCATION
+ ) == PackageManager.PERMISSION_GRANTED
+ ) {
+ runBlocking {
+ fusedLocationClient.lastLocation.await()
+ }
+ } else {
+ null
+ }
+
+ if (androidLocation == null) {
+ throw IllegalStateException("Failed to retrieve location. Ensure location permissions are granted and location services are enabled.")
+ }
+
+ val location = Location.init(androidLocation.latitude, androidLocation.longitude, arena);
+ return location
+ }
+}
diff --git a/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Color.kt b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Color.kt
new file mode 100644
index 0000000..f9c0931
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Color.kt
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp.ui.theme
+
+import androidx.compose.ui.graphics.Color
+
+val Purple80 = Color(0xFFD0BCFF)
+val PurpleGrey80 = Color(0xFFCCC2DC)
+val Pink80 = Color(0xFFEFB8C8)
+
+val Purple40 = Color(0xFF6650a4)
+val PurpleGrey40 = Color(0xFF625b71)
+val Pink40 = Color(0xFF7D5260)
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Theme.kt b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Theme.kt
new file mode 100644
index 0000000..61ed15c
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Theme.kt
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp.ui.theme
+
+import android.app.Activity
+import android.os.Build
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.darkColorScheme
+import androidx.compose.material3.dynamicDarkColorScheme
+import androidx.compose.material3.dynamicLightColorScheme
+import androidx.compose.material3.lightColorScheme
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.LocalContext
+
+private val DarkColorScheme = darkColorScheme(
+ primary = Purple80,
+ secondary = PurpleGrey80,
+ tertiary = Pink80
+)
+
+private val LightColorScheme = lightColorScheme(
+ primary = Purple40,
+ secondary = PurpleGrey40,
+ tertiary = Pink40
+
+ /* Other default colors to override
+ background = Color(0xFFFFFBFE),
+ surface = Color(0xFFFFFBFE),
+ onPrimary = Color.White,
+ onSecondary = Color.White,
+ onTertiary = Color.White,
+ onBackground = Color(0xFF1C1B1F),
+ onSurface = Color(0xFF1C1B1F),
+ */
+)
+
+@Composable
+fun WeatherAppTheme(
+ darkTheme: Boolean = isSystemInDarkTheme(),
+ // Dynamic color is available on Android 12+
+ dynamicColor: Boolean = true,
+ content: @Composable () -> Unit
+) {
+ val colorScheme = when {
+ dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
+ val context = LocalContext.current
+ if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
+ }
+
+ darkTheme -> DarkColorScheme
+ else -> LightColorScheme
+ }
+
+ MaterialTheme(
+ colorScheme = colorScheme,
+ typography = Typography,
+ content = content
+ )
+}
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Type.kt b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Type.kt
new file mode 100644
index 0000000..318c6f2
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/ui/theme/Type.kt
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp.ui.theme
+
+import androidx.compose.material3.Typography
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.sp
+
+// Set of Material typography styles to start with
+val Typography = Typography(
+ bodyLarge = TextStyle(
+ fontFamily = FontFamily.Default,
+ fontWeight = FontWeight.Normal,
+ fontSize = 16.sp,
+ lineHeight = 24.sp,
+ letterSpacing = 0.5.sp
+ )
+ /* Other default text styles to override
+ titleLarge = TextStyle(
+ fontFamily = FontFamily.Default,
+ fontWeight = FontWeight.Normal,
+ fontSize = 22.sp,
+ lineHeight = 28.sp,
+ letterSpacing = 0.sp
+ ),
+ labelSmall = TextStyle(
+ fontFamily = FontFamily.Default,
+ fontWeight = FontWeight.Medium,
+ fontSize = 11.sp,
+ lineHeight = 16.sp,
+ letterSpacing = 0.5.sp
+ )
+ */
+)
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/viewmodel/WeatherViewModel.kt b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/viewmodel/WeatherViewModel.kt
new file mode 100644
index 0000000..ec05e31
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/java/com/example/weatherapp/viewmodel/WeatherViewModel.kt
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp.viewmodel
+
+import android.app.Application
+import android.util.Log
+import androidx.lifecycle.AndroidViewModel
+import androidx.lifecycle.application
+import androidx.lifecycle.viewModelScope
+import com.example.weatherapp.services.LocationService
+import com.example.weatherlib.WeatherClient
+import com.example.weatherlib.WeatherData
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.future.await
+import kotlinx.coroutines.launch
+import org.swift.swiftkit.core.SwiftArena
+
+class WeatherViewModel(application: Application) : AndroidViewModel(application) {
+ private val arena = SwiftArena.ofAuto()
+
+ private val _weatherData = MutableStateFlow(null)
+ val weatherData = _weatherData.asStateFlow()
+
+ private val _error = MutableStateFlow(null)
+ val error = _error.asStateFlow()
+
+ fun fetchWeather() {
+ viewModelScope.launch {
+ try {
+ val locationService = LocationService(application)
+ val weatherClient = WeatherClient.init(locationService, arena)
+ val weather = weatherClient.getWeather(arena).await()
+ _weatherData.value = weather
+ } catch (e: Exception) {
+ _error.value = "An unexpected error occurred: ${e.message}"
+ }
+ }
+ }
+}
diff --git a/swift-java-weather-app/weather-app/src/main/res/drawable/ic_launcher_background.xml b/swift-java-weather-app/weather-app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..07d5da9
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/swift-java-weather-app/weather-app/src/main/res/drawable/ic_launcher_foreground.xml b/swift-java-weather-app/weather-app/src/main/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 0000000..2b068d1
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-anydpi/ic_launcher.xml b/swift-java-weather-app/weather-app/src/main/res/mipmap-anydpi/ic_launcher.xml
new file mode 100644
index 0000000..6f3b755
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/mipmap-anydpi/ic_launcher.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/swift-java-weather-app/weather-app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
new file mode 100644
index 0000000..6f3b755
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-hdpi/ic_launcher.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-hdpi/ic_launcher.webp
new file mode 100644
index 0000000..c209e78
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-hdpi/ic_launcher.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..b2dfe3d
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-mdpi/ic_launcher.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-mdpi/ic_launcher.webp
new file mode 100644
index 0000000..4f0f1d6
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-mdpi/ic_launcher.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..62b611d
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-xhdpi/ic_launcher.webp
new file mode 100644
index 0000000..948a307
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..1b9a695
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
new file mode 100644
index 0000000..28d4b77
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..9287f50
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
new file mode 100644
index 0000000..aa7d642
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..9126ae3
Binary files /dev/null and b/swift-java-weather-app/weather-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ
diff --git a/swift-java-weather-app/weather-app/src/main/res/values/colors.xml b/swift-java-weather-app/weather-app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..f8c6127
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/values/colors.xml
@@ -0,0 +1,10 @@
+
+
+ #FFBB86FC
+ #FF6200EE
+ #FF3700B3
+ #FF03DAC5
+ #FF018786
+ #FF000000
+ #FFFFFFFF
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/values/strings.xml b/swift-java-weather-app/weather-app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..00461f1
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ Weather App
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/values/themes.xml b/swift-java-weather-app/weather-app/src/main/res/values/themes.xml
new file mode 100644
index 0000000..29b8bc1
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/values/themes.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/xml/backup_rules.xml b/swift-java-weather-app/weather-app/src/main/res/xml/backup_rules.xml
new file mode 100644
index 0000000..4df9255
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/xml/backup_rules.xml
@@ -0,0 +1,13 @@
+
+
+
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/main/res/xml/data_extraction_rules.xml b/swift-java-weather-app/weather-app/src/main/res/xml/data_extraction_rules.xml
new file mode 100644
index 0000000..9ee9997
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/main/res/xml/data_extraction_rules.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-app/src/test/java/com/example/weatherapp/ExampleUnitTest.kt b/swift-java-weather-app/weather-app/src/test/java/com/example/weatherapp/ExampleUnitTest.kt
new file mode 100644
index 0000000..70b33de
--- /dev/null
+++ b/swift-java-weather-app/weather-app/src/test/java/com/example/weatherapp/ExampleUnitTest.kt
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+package com.example.weatherapp
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+ @Test
+ fun addition_isCorrect() {
+ assertEquals(4, 2 + 2)
+ }
+}
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-lib/Package.swift b/swift-java-weather-app/weather-lib/Package.swift
new file mode 100644
index 0000000..846c868
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Package.swift
@@ -0,0 +1,81 @@
+// swift-tools-version: 6.2
+// The swift-tools-version declares the minimum version of Swift required to build this package.
+
+import CompilerPluginSupport
+import PackageDescription
+
+import class Foundation.FileManager
+import class Foundation.ProcessInfo
+
+// Note: the JAVA_HOME environment variable must be set to point to where
+// Java is installed, e.g.,
+// Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home.
+func findJavaHome() -> String {
+ if let home = ProcessInfo.processInfo.environment["JAVA_HOME"] {
+ return home
+ }
+
+ // This is a workaround for envs (some IDEs) which have trouble with
+ // picking up env variables during the build process
+ let path = "\(FileManager.default.homeDirectoryForCurrentUser.path()).java_home"
+ if let home = try? String(contentsOfFile: path, encoding: .utf8) {
+ if let lastChar = home.last, lastChar.isNewline {
+ return String(home.dropLast())
+ }
+
+ return home
+ }
+
+ fatalError("Please set the JAVA_HOME environment variable to point to where Java is installed.")
+}
+let javaHome = findJavaHome()
+
+let javaIncludePath = "\(javaHome)/include"
+#if os(Linux)
+ let javaPlatformIncludePath = "\(javaIncludePath)/linux"
+#elseif os(macOS)
+ let javaPlatformIncludePath = "\(javaIncludePath)/darwin"
+#else
+ // TODO: Handle windows as well
+ #error("Currently only macOS and Linux platforms are supported, this may change in the future.")
+#endif
+
+let package = Package(
+ name: "WeatherLibrary",
+ platforms: [.macOS(.v15)],
+ products: [
+ .library(
+ name: "WeatherLibrary",
+ type: .dynamic,
+ targets: ["WeatherLibrary"]
+ )
+ ],
+ dependencies: [
+ .package(url: "https://github.com/swiftlang/swift-java", branch: "main"),
+ .package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
+ .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
+ .package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
+ .package(url: "https://github.com/swift-server/swift-openapi-async-http-client", from: "1.0.0"),
+ ],
+ targets: [
+ .target(
+ name: "WeatherLibrary",
+ dependencies: [
+ .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
+ .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession", condition: .when(platforms: [.macOS, .iOS])),
+ .product(name: "OpenAPIAsyncHTTPClient", package: "swift-openapi-async-http-client", condition: .when(platforms: [.android])),
+ .product(name: "SwiftJava", package: "swift-java"),
+ .product(name: "CSwiftJavaJNI", package: "swift-java"),
+ .product(name: "SwiftJavaRuntimeSupport", package: "swift-java"),
+ ],
+ swiftSettings: [
+ .swiftLanguageMode(.v5),
+ .unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"], .when(platforms: [.macOS, .linux, .windows]))
+ ],
+ plugins: [
+ .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"),
+ .plugin(name: "JExtractSwiftPlugin", package: "swift-java")
+ ]
+ )
+ ]
+)
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/LocationFetcher.swift b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/LocationFetcher.swift
new file mode 100644
index 0000000..f7fcbcd
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/LocationFetcher.swift
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+public struct Location {
+ public let latitude: Double
+ public let longitude: Double
+
+ public init(latitude: Double, longitude: Double) {
+ self.latitude = latitude
+ self.longitude = longitude
+ }
+}
+
+/// Responsible for fetching GPS locations
+public protocol LocationFetcher {
+ func currentLocation() -> Location
+}
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherClient.swift b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherClient.swift
new file mode 100644
index 0000000..a2cca67
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherClient.swift
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+#if os(Android)
+import OpenAPIAsyncHTTPClient
+#else
+import OpenAPIURLSession
+#endif
+import OpenAPIRuntime
+import Foundation
+
+public final class WeatherClient {
+ private let client: Client
+ private let locationFetcher: any LocationFetcher
+
+ public init(locationFetcher: any LocationFetcher) {
+ guard let serverURL = URL(string: "https://api.open-meteo.com") else {
+ fatalError("Could not create server URL.")
+ }
+
+ self.locationFetcher = locationFetcher
+ self.client = Client(
+ serverURL: serverURL,
+ transport: WeatherClient.makeTransport()
+ )
+ }
+
+ /// Fetches the current weather for a specific geographic location.
+ public func getWeather() async throws -> WeatherData {
+ let location = self.locationFetcher.currentLocation()
+ let response = try await client.getV1Forecast(.init(query: .init(latitude: location.latitude, longitude: location.longitude, currentWeather: true)))
+
+ switch response {
+ case .ok(let okResponse):
+ switch okResponse.body {
+ case .json(let forecast):
+ guard let current = forecast.currentWeather else {
+ throw WeatherError.unexpectedResponse
+ }
+
+ return WeatherData(
+ temperature: current.temperature,
+ windSpeed: current.windspeed,
+ windDirection: current.winddirection
+ )
+ }
+
+ default:
+ throw WeatherError.apiError("Received an API error: \(response)")
+ }
+ }
+
+ private static func makeTransport() -> some ClientTransport {
+#if os(Android)
+ return AsyncHTTPClientTransport(configuration: .init())
+#else
+ return URLSessionTransport()
+#endif
+ }
+}
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherData.swift b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherData.swift
new file mode 100644
index 0000000..aae7946
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherData.swift
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+/// Represents the current weather conditions for a specific location.
+public struct WeatherData: Hashable {
+ public let temperature: Double
+ public let windSpeed: Double
+ public let windDirection: Double
+}
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherError.swift b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherError.swift
new file mode 100644
index 0000000..2659c47
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/WeatherError.swift
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2025 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+//
+//===----------------------------------------------------------------------===//
+
+public enum WeatherError: Error {
+ case apiError(String)
+ case unexpectedResponse
+
+ public var description: String {
+ switch self {
+ case .apiError(let message):
+ return "API Error: \(message)"
+ case .unexpectedResponse:
+ return "The server returned an invalid or unexpected response."
+ }
+ }
+}
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/openapi-generator-config.yaml b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/openapi-generator-config.yaml
new file mode 100644
index 0000000..fe5587d
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/openapi-generator-config.yaml
@@ -0,0 +1,4 @@
+generate:
+ - types
+ - client
+namingStrategy: idiomatic
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/openapi.yaml b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/openapi.yaml
new file mode 100644
index 0000000..2b4034f
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/openapi.yaml
@@ -0,0 +1,461 @@
+openapi: 3.0.0
+info:
+ title: Open-Meteo APIs
+ description: 'Open-Meteo offers free weather forecast APIs for open-source developers and non-commercial use. No API key is required.'
+ version: '1.0'
+ contact:
+ name: Open-Meteo
+ url: https://open-meteo.com
+ email: info@open-meteo.com
+ license:
+ name: Attribution 4.0 International (CC BY 4.0)
+ url: https://creativecommons.org/licenses/by/4.0/
+ termsOfService: https://open-meteo.com/en/features#terms
+paths:
+ /v1/forecast:
+ servers:
+ - url: https://api.open-meteo.com
+ get:
+ tags:
+ - Weather Forecast APIs
+ summary: 7 day weather forecast for coordinates
+ description: 7 day weather variables in hourly and daily resolution for given WGS84 latitude and longitude coordinates. Available worldwide.
+ parameters:
+ - name: hourly
+ in: query
+ explode: false
+ schema:
+ type: array
+ items:
+ type: string
+ enum:
+ - temperature_2m
+ - relative_humidity_2m
+ - dew_point_2m
+ - apparent_temperature
+ - pressure_msl
+ - cloud_cover
+ - cloud_cover_low
+ - cloud_cover_mid
+ - cloud_cover_high
+ - wind_speed_10m
+ - wind_speed_80m
+ - wind_speed_120m
+ - wind_speed_180m
+ - wind_direction_10m
+ - wind_direction_80m
+ - wind_direction_120m
+ - wind_direction_180m
+ - wind_gusts_10m
+ - shortwave_radiation
+ - direct_radiation
+ - direct_normal_irradiance
+ - diffuse_radiation
+ - vapour_pressure_deficit
+ - evapotranspiration
+ - precipitation
+ - weather_code
+ - snow_height
+ - freezing_level_height
+ - soil_temperature_0cm
+ - soil_temperature_6cm
+ - soil_temperature_18cm
+ - soil_temperature_54cm
+ - soil_moisture_0_1cm
+ - soil_moisture_1_3cm
+ - soil_moisture_3_9cm
+ - soil_moisture_9_27cm
+ - soil_moisture_27_81cm
+ - name: daily
+ in: query
+ schema:
+ type: array
+ items:
+ type: string
+ enum:
+ - temperature_2m_max
+ - temperature_2m_min
+ - apparent_temperature_max
+ - apparent_temperature_min
+ - precipitation_sum
+ - precipitation_hours
+ - weather_code
+ - sunrise
+ - sunset
+ - wind_speed_10m_max
+ - wind_gusts_10m_max
+ - wind_direction_10m_dominant
+ - shortwave_radiation_sum
+ - uv_index_max
+ - uv_index_clear_sky_max
+ - et0_fao_evapotranspiration
+ - name: latitude
+ in: query
+ required: true
+ description: "WGS84 coordinate"
+ schema:
+ type: number
+ format: double
+ - name: longitude
+ in: query
+ required: true
+ description: "WGS84 coordinate"
+ schema:
+ type: number
+ format: double
+ - name: current_weather
+ in: query
+ schema:
+ type: boolean
+ - name: temperature_unit
+ in: query
+ schema:
+ type: string
+ default: celsius
+ enum:
+ - celsius
+ - fahrenheit
+ - name: wind_speed_unit
+ in: query
+ schema:
+ type: string
+ default: kmh
+ enum:
+ - kmh
+ - ms
+ - mph
+ - kn
+ - name: timeformat
+ in: query
+ description: If format `unixtime` is selected, all time values are returned in UNIX epoch time in seconds. Please not that all time is then in GMT+0! For daily values with unix timestamp, please apply `utc_offset_seconds` again to get the correct date.
+ schema:
+ type: string
+ default: iso8601
+ enum:
+ - iso8601
+ - unixtime
+ - name: timezone
+ in: query
+ description: If `timezone` is set, all timestamps are returned as local-time and data is returned starting at 0:00 local-time. Any time zone name from the [time zone database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) is supported.
+ schema:
+ type: string
+ - name: past_days
+ in: query
+ description: If `past_days` is set, yesterdays or the day before yesterdays data are also returned.
+ schema:
+ type: integer
+ enum:
+ - 1
+ - 2
+ responses:
+ "200":
+ description: OK
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ latitude:
+ type: number
+ example: 52.52
+ description: WGS84 of the center of the weather grid-cell which was used to generate this forecast. This coordinate might be up to 5 km away.
+ longitude:
+ type: number
+ example: 13.419.52
+ description: WGS84 of the center of the weather grid-cell which was used to generate this forecast. This coordinate might be up to 5 km away.
+ elevation:
+ type: number
+ example: 44.812
+ description: The elevation in meters of the selected weather grid-cell. In mountain terrain it might differ from the location you would expect.
+ generationtime_ms:
+ type: number
+ example: 2.2119
+ description: Generation time of the weather forecast in milli seconds. This is mainly used for performance monitoring and improvements.
+ utc_offset_seconds:
+ type: integer
+ example: 3600
+ description: Applied timezone offset from the &timezone= parameter.
+ hourly:
+ $ref: "#/components/schemas/HourlyResponse"
+ hourly_units:
+ type: object
+ additionalProperties:
+ type: string
+ description: For each selected weather variable, the unit will be listed here.
+ daily:
+ $ref: "#/components/schemas/DailyResponse"
+ daily_units:
+ type: object
+ additionalProperties:
+ type: string
+ description: For each selected daily weather variable, the unit will be listed here.
+ current_weather:
+ $ref: "#/components/schemas/CurrentWeather"
+ "400":
+ description: Bad Request
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ error:
+ type: boolean
+ description: Always set true for errors
+ reason:
+ type: string
+ description: Description of the error
+ example: "Latitude must be in range of -90 to 90°. Given: 300"
+components:
+ schemas:
+ HourlyResponse:
+ type: object
+ description: For each selected weather variable, data will be returned as a floating point array. Additionally a `time` array will be returned with ISO8601 timestamps.
+ required:
+ - time
+ properties:
+ time:
+ type: array
+ items:
+ type: string
+ temperature_2m:
+ type: array
+ items:
+ type: number
+ relative_humidity_2m:
+ type: array
+ items:
+ type: number
+ dew_point_2m:
+ type: array
+ items:
+ type: number
+ apparent_temperature:
+ type: array
+ items:
+ type: number
+ pressure_msl:
+ type: array
+ items:
+ type: number
+ cloud_cover:
+ type: array
+ items:
+ type: number
+ cloud_cover_low:
+ type: array
+ items:
+ type: number
+ cloud_cover_mid:
+ type: array
+ items:
+ type: number
+ cloud_cover_high:
+ type: array
+ items:
+ type: number
+ wind_speed_10m:
+ type: array
+ items:
+ type: number
+ wind_speed_80m:
+ type: array
+ items:
+ type: number
+ wind_speed_120m:
+ type: array
+ items:
+ type: number
+ wind_speed_180m:
+ type: array
+ items:
+ type: number
+ wind_direction_10m:
+ type: array
+ items:
+ type: number
+ wind_direction_80m:
+ type: array
+ items:
+ type: number
+ wind_direction_120m:
+ type: array
+ items:
+ type: number
+ wind_direction_180m:
+ type: array
+ items:
+ type: number
+ wind_gusts_10m:
+ type: array
+ items:
+ type: number
+ shortwave_radiation:
+ type: array
+ items:
+ type: number
+ direct_radiation:
+ type: array
+ items:
+ type: number
+ direct_normal_irradiance:
+ type: array
+ items:
+ type: number
+ diffuse_radiation:
+ type: array
+ items:
+ type: number
+ vapour_pressure_deficit:
+ type: array
+ items:
+ type: number
+ evapotranspiration:
+ type: array
+ items:
+ type: number
+ precipitation:
+ type: array
+ items:
+ type: number
+ weather_code:
+ type: array
+ items:
+ type: number
+ snow_height:
+ type: array
+ items:
+ type: number
+ freezing_level_height:
+ type: array
+ items:
+ type: number
+ soil_temperature_0cm:
+ type: array
+ items:
+ type: number
+ soil_temperature_6cm:
+ type: array
+ items:
+ type: number
+ soil_temperature_18cm:
+ type: array
+ items:
+ type: number
+ soil_temperature_54cm:
+ type: array
+ items:
+ type: number
+ soil_moisture_0_1cm:
+ type: array
+ items:
+ type: number
+ soil_moisture_1_3cm:
+ type: array
+ items:
+ type: number
+ soil_moisture_3_9cm:
+ type: array
+ items:
+ type: number
+ soil_moisture_9_27cm:
+ type: array
+ items:
+ type: number
+ soil_moisture_27_81cm:
+ type: array
+ items:
+ type: number
+ DailyResponse:
+ type: object
+ description: For each selected daily weather variable, data will be returned as a floating point array. Additionally a `time` array will be returned with ISO8601 timestamps.
+ properties:
+ time:
+ type: array
+ items:
+ type: string
+ temperature_2m_max:
+ type: array
+ items:
+ type: number
+ temperature_2m_min:
+ type: array
+ items:
+ type: number
+ apparent_temperature_max:
+ type: array
+ items:
+ type: number
+ apparent_temperature_min:
+ type: array
+ items:
+ type: number
+ precipitation_sum:
+ type: array
+ items:
+ type: number
+ precipitation_hours:
+ type: array
+ items:
+ type: number
+ weather_code:
+ type: array
+ items:
+ type: number
+ sunrise:
+ type: array
+ items:
+ type: number
+ sunset:
+ type: array
+ items:
+ type: number
+ wind_speed_10m_max:
+ type: array
+ items:
+ type: number
+ wind_gusts_10m_max:
+ type: array
+ items:
+ type: number
+ wind_direction_10m_dominant:
+ type: array
+ items:
+ type: number
+ shortwave_radiation_sum:
+ type: array
+ items:
+ type: number
+ uv_index_max:
+ type: array
+ items:
+ type: number
+ uv_index_clear_sky_max:
+ type: array
+ items:
+ type: number
+ et0_fao_evapotranspiration:
+ type: array
+ items:
+ type: number
+ required:
+ - time
+ CurrentWeather:
+ type: object
+ description: "Current weather conditions with the attributes: time, temperature, wind_speed, wind_direction and weather_code"
+ properties:
+ time:
+ type: string
+ temperature:
+ type: number
+ windspeed:
+ type: number
+ winddirection:
+ type: number
+ weathercode:
+ type: integer
+ required:
+ - time
+ - temperature
+ - windspeed
+ - winddirection
+ - weathercode
diff --git a/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/swift-java.config b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/swift-java.config
new file mode 100644
index 0000000..895d8c4
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/Sources/WeatherLibrary/swift-java.config
@@ -0,0 +1,5 @@
+{
+ "javaPackage": "com.example.weatherlib",
+ "mode": "jni",
+ "enableJavaCallbacks": true
+}
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-lib/build.gradle b/swift-java-weather-app/weather-lib/build.gradle
new file mode 100644
index 0000000..dfca71d
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/build.gradle
@@ -0,0 +1,207 @@
+import java.nio.file.*
+import org.gradle.internal.os.OperatingSystem
+import groovy.json.JsonSlurper
+import kotlinx.serialization.json.*
+
+plugins {
+ alias(libs.plugins.android.library)
+}
+
+android {
+ namespace "com.example.weatherlib"
+ compileSdkVersion 36
+
+ defaultConfig {
+ minSdkVersion 28
+ }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+}
+
+dependencies {
+ implementation('org.swift.swiftkit:swiftkit-core:1.0-SNAPSHOT')
+}
+
+// Helper function to get swiftly executable path
+def getSwiftlyPath() {
+ def fromConfig = project.findProperty("swiftly.path") ?: System.getenv("SWIFTLY_PATH")
+ if (fromConfig) {
+ return file(fromConfig)
+ }
+
+ // Try to find swiftly in common locations
+ def homeDir = System.getProperty("user.home")
+ def possiblePaths = [
+ "$homeDir/.swiftly/bin/swiftly",
+ "$homeDir/.local/share/swiftly/bin/swiftly",
+ "$homeDir/.local/bin/swiftly",
+ "/usr/local/bin/swiftly",
+ "/opt/homebrew/bin/swiftly",
+ "/root/.local/share/swiftly/bin/swiftly"
+ ]
+
+ for (path in possiblePaths) {
+ if (file(path).exists()) {
+ return path
+ }
+ }
+
+ throw new GradleException("Swift SDK path not found. Please set swiftly.path in the gradle.properties file or set SWIFTLY_PATH environment variable.")
+}
+def getSwiftSDKPath() {
+ def fromConfig = project.findProperty("swift.sdk.path") ?: System.getenv("SWIFT_SDK_PATH")
+ if (fromConfig) {
+ return file(fromConfig)
+ }
+
+ // If no custom path is set, try to find the Swift SDK in common locations.
+ def homeDir = System.getProperty("user.home")
+ def possiblePaths = [
+ "${homeDir}/Library/org.swift.swiftpm/swift-sdks/", // Common on macOS
+ "${homeDir}/.config/swiftpm/swift-sdks/", // Common on Linux
+ "${homeDir}/.swiftpm/swift-sdks/", // Older location
+ "/root/.swiftpm/swift-sdks/" // For builds running as root (e.g., in some CI/Docker environments)
+ ]
+
+ // Iterate through the list of possible paths.
+ for (path in possiblePaths) {
+ // The 'file()' method is a Gradle helper that resolves a path string into a File object.
+ if (file(path).exists()) {
+ // If the directory exists, we've found it. Return the path immediately.
+ return file(path)
+ }
+ }
+
+ // If the loop completes without finding a valid path, throw an exception.
+ throw new GradleException("Swift SDK path not found. Please set swift.sdk.path in the gradle.properties file or set SWIFT_SDK_PATH environment variable.")
+}
+
+// List of Swift runtime libraries we want to include
+def swiftRuntimeLibs = [
+ "swiftCore",
+ "swift_Concurrency",
+ "swift_StringProcessing",
+ "swift_RegexParser",
+ "swift_Builtin_float",
+ "swift_math",
+ "swiftAndroid",
+ "dispatch",
+ "BlocksRuntime",
+ "swiftSwiftOnoneSupport",
+ "swiftDispatch",
+ "Foundation",
+ "FoundationEssentials",
+ "FoundationInternationalization",
+ "_FoundationICU",
+ "swiftSynchronization"
+]
+
+def sdkName = "swift-DEVELOPMENT-SNAPSHOT-2025-10-16-a-android-0.1.artifactbundle"
+def swiftVersion = "main-snapshot-2025-10-16"
+def minSdk = android.defaultConfig.minSdkVersion.apiLevel
+/**
+ * Android ABIs and their Swift triple mappings
+ */
+def abis = [
+ "arm64-v8a" : [triple: "aarch64-unknown-linux-android${minSdk}", androidSdkLibDirectory: "swift-aarch64", ndkDirectory: "aarch64-linux-android"],
+ "armeabi-v7a" : [triple: "armv7-unknown-linux-android${minSdk}", androidSdkLibDirectory: "swift-armv7", ndkDirectory: "arm-linux-android"],
+ "x86_64" : [triple: "x86_64-unknown-linux-android${minSdk}", androidSdkLibDirectory: "swift-x86_64", ndkDirectory: "x86_64-linux-android"]
+]
+def generatedJniLibsDir = layout.buildDirectory.dir("generated/jniLibs")
+def swiftSdkPath = "${getSwiftSDKPath().absolutePath}/${sdkName}"
+
+def buildSwiftAll = tasks.register("buildSwiftAll") {
+ group = "build"
+ description = "Builds the Swift code for all Android ABIs."
+
+ // If the package description changes, we should execute jextract again, maybe we added jextract to new targets
+ inputs.file(new File(projectDir, "Package.swift"))
+ inputs.dir(new File(layout.projectDirectory.asFile, "Sources/WeatherLibrary".toString()))
+
+ outputs.dir(layout.buildDirectory.dir("../.build/plugins/outputs/${layout.projectDirectory.asFile.getName().toLowerCase()}"))
+
+ File baseSwiftPluginOutputsDir = layout.buildDirectory.dir("../.build/plugins/outputs/").get().asFile
+ if (!baseSwiftPluginOutputsDir.exists()) {
+ baseSwiftPluginOutputsDir.mkdirs()
+ }
+ Files.walk(layout.buildDirectory.dir("../.build/plugins/outputs/").get().asFile.toPath()).each {
+ // Add any Java sources generated by the plugin to our sourceSet
+ if (it.endsWith("JExtractSwiftPlugin/src/generated/java")) {
+ outputs.dir(it)
+ }
+ }
+}
+
+// Create a build task for each ABI
+abis.each { abi, info ->
+ def task = tasks.register("buildSwift${abi.capitalize()}", Exec) {
+ group = "build"
+ description = "Builds the Swift code for the ${abi} ABI."
+
+ doFirst {
+ println("Building Swift for ${abi} (${info.triple})...")
+ }
+
+ outputs.dir(layout.projectDirectory.dir(".build/${info.triple}/debug"))
+
+ workingDir = layout.projectDirectory
+ executable(getSwiftlyPath())
+
+ // We must disable sandbox, because we use the `enableJavaCallbacks` feature
+ // of swift-java.
+ args("run", "swift", "build", "+${swiftVersion}", "--swift-sdk", info.triple, "--disable-sandbox")
+ }
+
+ buildSwiftAll.configure { dependsOn(task) }
+}
+
+def copyJniLibs = tasks.register("copyJniLibs", Copy) {
+ dependsOn(buildSwiftAll)
+
+ abis.each { abi, info ->
+ // Copy the built .so files
+ from(layout.projectDirectory.dir(".build/${info.triple}/debug")) {
+ include("*.so")
+ into(abi)
+ }
+
+ // Copy libc++_shared.so from NDK
+ from(file("${swiftSdkPath}/swift-android/ndk-sysroot/usr/lib/${info.ndkDirectory}/libc++_shared.so")) {
+ into(abi)
+ }
+
+ doFirst {
+ println("Copying Swift runtime libraries for ${abi}...")
+ }
+
+ // Copy the Swift runtime libraries
+ from(swiftRuntimeLibs.collect { libName ->
+ "${swiftSdkPath}/swift-android/swift-resources/usr/lib/${info.androidSdkLibDirectory}/android/lib${libName}.so"
+ }) {
+ into(abi)
+ }
+ }
+
+ into(generatedJniLibsDir)
+}
+
+// Add the java-swift generated Java sources
+android {
+ sourceSets {
+ main {
+ java {
+ srcDir(buildSwiftAll)
+ }
+
+ jniLibs {
+ srcDir(generatedJniLibsDir)
+ }
+ }
+ }
+}
+
+// Make sure we run our tasks before build
+preBuild.dependsOn(copyJniLibs)
\ No newline at end of file
diff --git a/swift-java-weather-app/weather-lib/gradle.properties b/swift-java-weather-app/weather-lib/gradle.properties
new file mode 100644
index 0000000..dddb525
--- /dev/null
+++ b/swift-java-weather-app/weather-lib/gradle.properties
@@ -0,0 +1,4 @@
+# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
+
+org.gradle.configuration-cache=true
+