Skip to content

Commit

Permalink
Add an android example (#45)
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
Maximkaaa authored Feb 8, 2024
1 parent 74f3524 commit fea71a8
Show file tree
Hide file tree
Showing 45 changed files with 1,257 additions and 165 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude = [
"wasm_examples/many_points",
"wasm_examples/lambert",
"wasm_examples/with_egui",
"android_examples/raster_tiles/rust",
]

[workspace.package]
Expand Down
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ it can be used on any platform that `wgpu` supports:
Still, the backend is not integral part of the Galileo design, so we will probably
try other promising backends (like [vello](https://github.com/linebender/vello)).

![Android](https://maximkaaa.github.io/galileo/android.png)

## FFI

At this point, you can develop an application using Galileo only in Rust. But there is
a POC example of how we envision future development on other platforms: [wasm_examples/raster_tiles].
When all main features of Galileo are more or less stable (or when a need arises) we
will add FFI bindings to other languages using `wasm-bindgen` and `uniffi`. This will
allow you to create your applications in `JS`, `Kotlin`, `Swift` or `Python` using
common API.

## Features

Galileo is an active WIP, here is the list of the features that are already present:
Expand Down Expand Up @@ -91,10 +102,12 @@ them all done at the same time. So here's our current plan and priorities:

# Running examples

Rust examples of using Galileo are located at [`galileo/examples`]. Refer to the [readme](galileo/examples/README.md)
Rust examples of using Galileo are located at [`galileo/examples`](galileo/examples). Refer to the [readme](galileo/examples/README.md)
for the list, description and run instructions.

There are also examples of running Galileo in a web-browser located at [`web_examples`] folder. These are
## Web

There are also examples of running Galileo in a web-browser located at [`wasm_examples`](wasm_examples) folder. These are
excluded from the workspace (because Cargo does not like cross-platform workspaces).
To run those you will need to [install wasm-pack](https://rustwasm.github.io/wasm-pack/installer/):

Expand All @@ -105,6 +118,10 @@ wasm-pack build wasm_examples/countries --target no-modules --release
After that open `index.html` in your browser (must be served from `localhost`, use your
favourite developer server).

## Android

Check out [this example](android_examples/raster_tiles/README.md) to run Galileo on Android.

## Cross-compile from Linux to Windows

Install the target:
Expand All @@ -127,14 +144,18 @@ cargo build --target x86_64-px-windows-gnu

# Sponsoring

There is still a lot of work to be done to make Galileo feature-full, production ready and useful for many. And we
would love to work on this full-time to bring this to you as soon as possible. So we are looking for sponsors
to make it possible.

Sponsor funds will help support maintainer's dedicated work and eventually fund freelance contributors.

If you think this library can be useful to you or someone you love, consider supporting its development. Sponsoring
comes with additional advantages:
* Increase development speed. All funds will be spent on development.
* Increase development speed.
* Make your needs our priority.
* See your logo on the project's page.

Please, contact the maintainer of the project with any questions related to sponsoring.

# License

You can use this library without any worries as it is licensed under either of
Expand Down
16 changes: 16 additions & 0 deletions android_examples/raster_tiles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
/app/src/main/jniLibs
25 changes: 25 additions & 0 deletions android_examples/raster_tiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This example app demonstrates how to run Galileo map as a Rust app on Android.

To run the example install Android Studio with NDK.

Then to build the rust part:

```shell
# Install Cargo NDK
cargo install cargo-ndk

# Install android targets
rustup target add \
aarch64-linux-android \
armv7-linux-androideabi \
x86_64-linux-android \
i686-linux-android

# Export NDK location. The location and version number on your system may differ from the bellow
export ANDROID_NDK_HOME=~/Android/Sdk/ndk/26.1.10909125/

# Build the app
cargo ndk -t arm64-v8a -t armeabi-v7a -t x86 -t x86_64 -o ../app/src/main/jniLibs/ build
```

After that you can run the application from the Android Studio.
1 change: 1 addition & 0 deletions android_examples/raster_tiles/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
70 changes: 70 additions & 0 deletions android_examples/raster_tiles/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.example.rastertilesandroid"
compileSdk = 34
ndkVersion = "26.1.10909125"

defaultConfig {
applicationId = "com.example.rastertilesandroid"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
21 changes: 21 additions & 0 deletions android_examples/raster_tiles/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.rastertilesandroid

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.rastertilesandroid", appContext.packageName)
}
}
31 changes: 31 additions & 0 deletions android_examples/raster_tiles/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.RasterTilesAndroid"
tools:targetApi="31">

<activity
android:name="android.app.NativeActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data android:name="android.app.lib_name" android:value="raster_tiles_android" />
</activity>
</application>

</manifest>
Loading

0 comments on commit fea71a8

Please sign in to comment.