cargo-mobile: Gradle Error (org.gradle.wrapper.GradleWrapperMain)

Issue

Hello,

I have installed all the required dependencies (I believe), and have successfully run an example for desktop, on macOS.

When I now run cargo android run I get:

Detected connected device: OnePlus 8 Pro (IN2025) with target "aarch64-linux-android"
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
error: Failed to assemble APK
    Command "/Users/wbrickner/Documents/Projects/rust-mobile-test/gen/android/testy/gradlew --project-dir
    /Users/wbrickner/Documents/Projects/rust-mobile-test/gen/android/testy assembleArm64Debug --warn" didn't complete
    successfully, exiting with code 1.

Environment

I am running the Bevy example with the present commit of this repo, with rust 1.50 nightly. I believe my NDK version is 21.3.6528147.

$ gradle --version yields

------------------------------------------------------------
Gradle 5.6.2
------------------------------------------------------------

Build time:   2019-09-05 16:13:54 UTC
Revision:     55a5e53d855db8fc7b0e494412fc624051a8e781

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          11.0.8 (AdoptOpenJDK 11.0.8+10)
OS:           Mac OS X 10.16 x86_64

(This gradle output is slightly incorrect in one obvious place, I am actually running macOS Big Sur 11.0.1 w/ Intel ISA).

Hopefully this is enough information to help track down the issue which I assume is internal to the cargo-mobile project generation process.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Very peculiar! I was able to replicate this issue (well, in a way) - I created a fresh project with cargo mobile init and then run cargo android run and got the same error as you did by looking into adb logcat. But, then I tried to run cargo android run for the second time and it surprisingly worked! The app launched correctly - from this point on no error was raised any time I ran cargo android run I was able to replicate it with at least two different project/templates.

It seems like this time this might be some issue connected to the compilation process in cargo/cargo-mobile, so I’ll look into it, but it would be great if you could confirm that the similar thing happens on your machine.

I’ll also attach logs from both of my cargo android run --verbose runs and adb logcat | grep -i "Cargo" output if anyone wants to take a look at them: cargo-android-run-0.txt adb-logcat.txt cargo-android-run-1.txt

Yeah, it is just a simple window example with a logger connected and nothing else really, by invoking cargo run to run the project on your PC you can see the logs displayed in the terminal. The logs aren’t displayed for Android though (at least for me) but I’m not sure if that’s intentional.

Anyway, I’m really glad that it’s working for you now! If it’s cool with you I think it’s worth closing this issue (as MR removing LFS and fixing gradle-wrapper.jar was merged today into master) and creating a new one connected to this need to run cargo android run twice after creating a new project.

Thanks for reporting this, and for trying out cargo-mobile!

Is gen/android/testy/gradle/wrapper/gradle-wrapper.jar present?

Does it work if you run from Android Studio instead?