This folder contains an Android app that can compile Wear OS watch faces as .apk or .aab at runtime.
It does so by using a custom Rust library depending on pack-api, plus a Java class which interfaces with that library (PackPackage.java).
Note that this example is a phone app, but the concept should work just as well on Wear OS.
Tested on macOS, should work on Linux with minimal modification.
- Install and set up
cargo - Install the Android SDK and NDK.
rustup target add aarch64-linux-androidrustup target add x86_64-linux-androidrustup target add armv7-linux-androideabi- Copy
pack-java/.cargo.exampletopack-java/.cargoand update the paths there to the correct ones - Run
./generate-testing-pem.shand copy its output - Place its output in
StaticExampleData.java'sCOMBINED_PEM_STRINGfield - Run
./provide-libraries-to-java-project.sh - Open
./PackFromJavain Android Studio and press the run button
Note: That step about running generate-testing-pem is very important! This repo ships with its PRIVATE KEY removed - you should generate your own and not share it with anyone. The app crashes if you don't insert a working private key from this step.
You should be presented with a phone activity that says "Compile an APK on-device" and upon clicking that button, you'll get a save file dialog for output.apk.
You can look into MainActivity.java for how this package is compiled.
If you need to, you could modify PackPackage.java to create a more idiomatic API, but theoretically you could leave it untouched if this example API doesn't bother you.
This is sample code, it isn't up to scratch, quality-wise, with the rest of the repo. For example, it does not handle errors. It's intended to give a taste of what it could be like to use Pack on Android. Please modify it to suit your needs.
