-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.9.3 incompatible with AGP 7.4.1 #118
Comments
Thanks for the report. The limited testing that we do should be able to also test AGP 7.4.x around rust-android-gradle/plugin/build.gradle Lines 30 to 39 in 4fba4b9
Thanks for the report! |
Seconding the breakage. Not sure if I'll be able to spend time debugging it any time soon though. |
It's working for me under AGP 7.4.1 and 8.0.0-beta03 both.But I'm just doing some test..so my code are in the same source set. src In case you need.Here is some different.
and build.gradle
|
Yeah, it seems like the problem went away for me in the past few days. I'm sending in two PRs to add 7.4.2 to the tests. |
OK,It repreduces in Gradle 8.0-rc02 and AGP 7.4.1. It seems like the problem went away after Bumping Gradle to 8.0.1. |
I've been getting it again, I think there's some caching interfering with whether or not it works. I can get it to work under 7.4.2 sometimes, but if I wipe caches and try again then I'll get the problem again. Trying to dig in a bit more. Gradle 7.6 and AGP 7.4.2. |
Some more detail. EDIT: Lots more detail, I'm just just adding updates while I wait for builds to run. I'm checking for the bug, where the JNI doesn't make it onto the device and we get If I switch my AGP version from 7.3.1 to 7.4.2, do a clean and a re-build, then the I did some rebuilds, including clearing Android Studio's cache, and it seemed to be working. At this point I had this in my build.gradle.kts:
So so far so good? I commented out the line that added it to the debug source set and the test failed, then added it back and it worked again. Then I tried launching the debug build of the app and that worked, then ran the "release" build of the app, and it the app crashed, library not found. Added Ok, so it's a source set issue? I commented the sourceSet lines out, confirmed that the test failed, then added ... And then I decided to do some confirmation by doing a clean and test with no build-cache, and got an error about having duplicate libraries... (task mergeDebugJniLibFolders failed, duplicate resources, with both paths listed seeming to point to the same file.) I removed the sourceset addition line (so no manual adding to the source set and it worked again. So, ok, we've got some serious build cache interference here and most of what's above is suspect. In the end I commented out everything except the cargo configuration block and the "depends on CargoBuild" block". So just this:
I ran that with But after some more testing it failed... So I'm still not sure, but my best guess is that, when starting with a fully clean cache, the first build will fail and it'll continue to fail until you make a change to your build.gradle file which causes one of the tasks to run again. I think there's some kind of build dependency issue, maybe something changed related to when source sets are added. But I need to get going so that's where this stands at the moment... Key takeaway: all tests here should be done without cache, after invalidating Android Studio's cache. |
im seeing something kinda similar. Im trying to run gradle on a docker container and if i run If I only run I dont use AGP at all though |
oh wait im on 7.3.1. i have an issue with my tooling which is updating me to 7.4 i think |
Theres an issue tracking it here. looks like an AGP bug? |
I've solved my issue - it was actually the issue discussed here. Interesting that it can trigger the duplicate resource error. |
I was running into (the same?) issues with my project after upgrading to gradle 8.0.2, where changes to my rust files weren't getting picked up in the android app. I hacked together a fix by registering the project.afterEvaluate {
// collect all the target dirs we compile to
def jniTargetDirs = []
tasks.withType(com.nishtahir.CargoBuildTask).forEach {
jniTargetDirs += new File("$buildDir/rustJniLibs", it.toolchain.folder)
}
// make sure we rerun the "merge jni lib folders" tasks any time they change
tasks.matching { it.name.matches(/merge.*JniLibFolders/) }.forEach {
jniTargetDirs.forEach { dir -> it.inputs.dir(dir) }
}
}
|
So a few weeks back I looked at the code and it's not in a great shape. IIRC pretty much everything is created The Android Gradle Plugin has stabilized a set of APIs that are meant for properly hooking in things like this (https://developer.android.com/studio/build/extend-agp). In the next few weeks I'm planning on basically re-implementing the Rust plugin in my project using those APIs (if anything so that we can upgrade past AGP 7.3) and I'll be able to share that code, which could probably be ported back into this plugin. Also, it's worth noting that the tests for the plugin only check to make sure that the rust library is built, not whether it gets packaged into an apk or aar, which is why the extra tests that I tried to add weren't catching it. |
I use this configuration to fix the problem that run will not package rustJniLibs tasks.whenObjectAdded {
if ((this.name == "mergeDebugJniLibFolders" || this.name == "mergeReleaseJniLibFolders")) {
this.dependsOn("cargoBuild")
// fix mergeDebugJniLibFolders UP-TO-DATE
this.inputs.dir(buildDir.resolve("rustJniLibs/android"))
}
} |
mozilla/rust-android-gradle#118 (comment) Observations: - The relevant task is called `cargoBuildArm64`, but it's ran as an intermediate dependency of `cargoBuild`; - `buildDir.resolve()` doesn't exist (deprecated? It's not in the Java 21 docs), but the sub-path `new File()` constructor does; - `it.toolchain` on `com.nishtahir.CargoBuildTask` is `null` outside of `project.afterEvaluate`; - Using purely typed `withType` queries allows one to write the expression without hardcoded task names, and automatically link all relevant tasks together.
I couldn't get the above to work 1 for various obscure reasons (timing between various callbacks, things being tasks.matching { it.name.matches(/merge.*JniLibFolders/) }.configureEach {
it.inputs.dir(new File(buildDir, "rustJniLibs/android"))
it.dependsOn("cargoBuild")
} project.afterEvaluate {
tasks.withType(com.nishtahir.CargoBuildTask).forEach { buildTask ->
tasks.withType(com.android.build.gradle.tasks.MergeSourceSetFolders).configureEach {
it.inputs.dir(new File(new File(buildDir, "rustJniLibs"), buildTask.toolchain.folder))
it.dependsOn(buildTask)
}
}
} Thanks all for posting your snippets! It's sad to see that this project has been abandoned, would be great to spend some time to get a fix for this merged instead. Footnotes
|
mozilla/rust-android-gradle#118 (comment) Observations: - The relevant task is called `cargoBuildArm64`, but it's ran as an intermediate dependency of `cargoBuild`; - `buildDir.resolve()` doesn't exist (deprecated? It's not in the Java 21 docs), but the sub-path `new File()` constructor does; - `it.toolchain` on `com.nishtahir.CargoBuildTask` is `null` outside of `project.afterEvaluate`; - Using purely typed `withType` queries allows one to write the expression without hardcoded task names, and automatically link all relevant tasks together.
Thanks @MarijnS95, I kept running into tasks.matching { it.name.matches(/merge.*JniLibFolders/) }.configureEach {
it.inputs.dir(new File(buildDir, "rustJniLibs/android"))
it.dependsOn("cargoBuild")
} |
iOS script needed to rebuild the dynamic library since we're using the macro based binding generation Android Gradle setup needed some workarounds to ensure the native libs were packaged properly after being rebuilt. See mozilla/rust-android-gradle#118 (comment). Also, the Android Gradle setup needed the `bindGen` task to depend on `cargoBuild` because we're using macro based binding generation.
Adding my 2 bytes of information in case it helps others. I am currently on AGP 8.1.2 and frequently hit the same issue as @klcantrell with Using the same fix mentioned in that comment seem to solve the issues for my case. |
My alternative is to use cmake with corrossion. |
It can't package compiled rust jni libs to aar.So java.lang.UnsatisfiedLinkError not found ocurrs. AGP 7.3.1 has no problem.
The text was updated successfully, but these errors were encountered: