Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ jobs:
if [[ "${{ runner.os }}" == "Windows" ]]; then
SDKMANAGER=$(echo $SDKMANAGER | tr '/' '\').bat
fi
${ANDROID_HOME}${SDKMANAGER} --install 'ndk;21.4.7075529' 'ndk;23.1.7779620'
${ANDROID_HOME}${SDKMANAGER} --install 'ndk;30.0.16248370'
shell: bash

- name: Setup Java 17
- name: Setup Java 25
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 17
java-version: 25
cache: 'gradle'

- name: Assemble samples/app
Expand All @@ -83,6 +83,12 @@ jobs:
run: |
./gradlew -p samples/library :assembleDebug --info --warning-mode all

- name: Test samples/unittest
if: runner.os == 'Linux'
run: |
echo 'rust.targets=x86_64,linux-x86-64' > samples/unittest/local.properties
./gradlew -p samples/unittest testDebugUnitTest --info --warning-mode all

# Work around https://github.com/actions/cache/issues/454.
- name: Gradle stop
run: |
Expand Down Expand Up @@ -116,15 +122,15 @@ jobs:
if [[ "${{ runner.os }}" == "Windows" ]]; then
SDKMANAGER=$(echo $SDKMANAGER | tr '/' '\').bat
fi
${ANDROID_HOME}${SDKMANAGER} --install 'ndk;21.4.7075529' 'ndk;23.1.7779620'
${ANDROID_HOME}${SDKMANAGER} --install 'ndk;30.0.16248370'
shell: bash

# Use Java 17
- name: Setup Java 17
# Use Java 25
- name: Setup Java 25
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 17
java-version: 25
cache: 'gradle'

- name: Gradle setup
Expand Down Expand Up @@ -167,20 +173,20 @@ jobs:
if [[ "${{ runner.os }}" == "Windows" ]]; then
SDKMANAGER=$(echo $SDKMANAGER | tr '/' '\').bat
fi
${ANDROID_HOME}${SDKMANAGER} --install 'ndk;21.4.7075529' 'ndk;23.1.7779620'
${ANDROID_HOME}${SDKMANAGER} --install 'ndk;30.0.16248370'
shell: bash

- name: Setup Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-linux-android,x86_64-unknown-linux-gnu,aarch64-linux-android

# Use Java 17
- name: Setup Java 17
# Use Java 25
- name: Setup Java 25
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 17
java-version: 25
cache: 'gradle'

- name: Gradle setup
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Set up JDK 17
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
java-version: 17
java-version: 25
distribution: 'temurin'

- name: Write gradle.properties
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ gradle-app.setting
.gradletasknamecache

.cargo
**/maven-repo/
**/maven-repo/
.kotlin/
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Cross compile Rust Cargo projects for Android targets.

Requires Android Gradle Plugin 9.0 or newer and Gradle 9.1 or newer. Projects still on Android Gradle Plugin 8
can keep using the 0.10.0 release.


<p align="left">
<a alt="Version badge" href="https://plugins.gradle.org/plugin/org.mozilla.rust-android-gradle.rust-android">
Expand Down Expand Up @@ -70,14 +73,8 @@ Finally, run the `cargoBuild` task to cross compile:
```sh
./gradlew cargoBuild
```
Or add it as a dependency to one of your other build tasks, to build your rust code when you normally build your project:
```gradle
tasks.whenTaskAdded { task ->
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
task.dependsOn 'cargoBuild'
}
}
```
Each variant's jniLibs merge and unit test tasks depend on `cargoBuild`, so building or testing the project
builds the Rust code first.

## Configuration

Expand Down Expand Up @@ -448,23 +445,24 @@ and builds will likely fail.)

## Passing arguments to cargo

The plugin passes project properties named like `RUST_ANDROID_GRADLE_target_..._KEY=VALUE` through
The plugin passes project properties named like `RUST_ANDROID_GRADLE_TARGET_<target>_<KEY>=VALUE` through
to the Cargo invocation for the given Rust `target` as `KEY=VALUE`. Target should be upper-case
with "-" replaced by "_". (See [the links from this Cargo issue](https://github.com/rust-lang/cargo/issues/5690).) So, for example,

```groovy
project.RUST_ANDROID_GRADLE_I686_LINUX_ANDROID_FOO=BAR
ext.RUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_FOO = "BAR"
```
and
```shell
./gradlew -PRUST_ANDROID_GRADLE_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ...
./gradlew -PRUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ...
```
and
```
env ORG_GRADLE_PROJECT_RUST_ANDROID_GRADLE_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ./gradlew ...
env ORG_GRADLE_PROJECT_RUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ./gradlew ...
```
all set `FOO=BAR` in the `cargo` execution environment (for the "armv7-linux-androideabi` Rust
target, corresponding to the "x86" target in the plugin).
all set `FOO=BAR` in the `cargo` execution environment for the `armv7-linux-androideabi` Rust
target, which is the `arm` target in the plugin. A `gradle.properties` entry works too. An `ext`
value must be set in the project that applies the plugin, or through `allprojects`.

# Development

Expand Down
14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ buildscript {
Properties versionProperties = new Properties()
versionProperties.load(new FileInputStream("$project.rootDir/version.properties"))

// Kotlin 1.9.22: Required for Gradle 8.5+ (old Kotlin Gradle plugin uses removed APIs)
ext.kotlin_version = '1.9.22'
// AGP 8.2.0: Required for Gradle 8.5+ compatibility
ext.agp_version = '8.2.0'
ext.kotlin_version = '2.4.21'
ext.agp_version = '9.0.0'
ext.plugin_version = versionProperties.getProperty("version")

repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
url = "https://plugins.gradle.org/m2/"
}
}
dependencies {
Expand All @@ -24,13 +22,13 @@ subprojects {
repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
url = "https://plugins.gradle.org/m2/"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
tasks.register('clean', Delete) {
delete rootProject.layout.buildDirectory
}

wrapper {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 5 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-all.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading