Skip to content

Commit

Permalink
use cargo-ndk-android instead of rust-android-gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed Oct 23, 2024
1 parent 2b35e69 commit 141513a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 57 deletions.
2 changes: 1 addition & 1 deletion examples/cat_facts/Android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cat_facts/Android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cat_facts/Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/cat_facts/Android/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cat_facts/Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.rust.android) apply false
alias(libs.plugins.cargo.ndk) apply false
}
10 changes: 5 additions & 5 deletions examples/cat_facts/Android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]
agp = "8.7.0"
agp = "8.7.1"
kotlin = "2.0.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.6"
activityCompose = "1.9.2"
composeBom = "2024.09.03"
activityCompose = "1.9.3"
composeBom = "2024.10.00"

# added
jna = "5.15.0"
Expand All @@ -16,7 +16,7 @@ rustAndroid = "0.9.4"
ktorClient = "2.2.2"
appcompat = "1.7.0"
material = "1.12.0"
materialIconsExtended = "1.7.3"
materialIconsExtended = "1.7.4"
coilCompose = "2.0.0-rc01"

[libraries]
Expand Down Expand Up @@ -50,5 +50,5 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

# added
rust-android = { id = "org.mozilla.rust-android-gradle.rust-android", version.ref = "rustAndroid" }
android-library = { id = "com.android.library", version.ref = "agp" }
cargo-ndk = { id = "com.github.willir.rust.cargo-ndk-android", version = "0.3.4" }
3 changes: 2 additions & 1 deletion examples/cat_facts/Android/shared/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
jniLibs
42 changes: 9 additions & 33 deletions examples/cat_facts/Android/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
namespace 'com.redbadger.catfacts.shared'
compileSdk 34

ndkVersion "27.1.12297006"
ndkVersion "28.0.12433566"

defaultConfig {
minSdk 34
Expand All @@ -26,9 +26,6 @@ android {
sourceCompatibility JavaVersion.VERSION_20
targetCompatibility JavaVersion.VERSION_20
}
kotlinOptions {
jvmTarget = '20'
}
sourceSets {
main.java.srcDirs += "${projectDir}/../../shared_types/generated/java"
}
Expand All @@ -49,37 +46,16 @@ dependencies {
androidTestImplementation libs.androidx.espresso.core
}

apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
apply plugin: 'com.github.willir.rust.cargo-ndk-android'

cargo {
module = "../.."
libname = "shared"
// these are the four recommended targets for Android that will ensure your library works on all mainline android devices
// make sure you have included the rust toolchain for each of these targets: \
// `rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android`
targets = ["arm", "arm64", "x86", "x86_64"]
extraCargoBuildArguments = ['--package', 'shared']
cargoCommand = System.getProperty("user.home") + "/.cargo/bin/cargo"
rustcCommand = System.getProperty("user.home") + "/.cargo/bin/rustc"
pythonCommand = "python3"
cargoNdk {
module = "../shared"
targetDirectory = "../target"
}

afterEvaluate {
// The `cargoBuild` task isn't available until after evaluation.
android.libraryVariants.configureEach { variant ->
def productFlavor = ""
variant.productFlavors.each {
productFlavor += "${it.name.capitalize()}"
}
def buildType = "${variant.buildType.name.capitalize()}"

tasks.named("compileDebugKotlin") {
it.dependsOn(tasks.named("typesGen"), tasks.named("bindGen"))
}

tasks.named("generate${productFlavor}${buildType}Assets") {
it.dependsOn(tasks.named("cargoBuild"))
}
tasks.named("compileDebugKotlin") {
it.dependsOn(tasks.named("typesGen"), tasks.named("bindGen"))
}
}

Expand All @@ -88,11 +64,11 @@ tasks.register('bindGen', Exec) {
workingDir "../../"
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
commandLine("cmd", "/c",
"cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate shared\\src\\shared.udl " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\'))
"cargo build --package shared --bin uniffi-bindgen && " + "target\\debug\\uniffi-bindgen generate shared\\src\\shared.udl " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\'))
} else {
commandLine("sh", "-c",
"""\
cargo build -p shared && \
cargo build --package shared --bin uniffi-bindgen && \
target/debug/uniffi-bindgen generate shared/src/shared.udl \
--language kotlin \
--out-dir $outDir
Expand Down
28 changes: 14 additions & 14 deletions examples/cat_facts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 141513a

Please sign in to comment.