Skip to content
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

Support and add a sample/test showing how to include a Rust binary like $name instead of a library like lib$name.so #30

Open
Mygod opened this issue Mar 1, 2020 · 11 comments

Comments

@Mygod
Copy link
Contributor

Mygod commented Mar 1, 2020

gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3. Android gradle plugin 4.0.0-beta01.

Mygod added a commit to Mygod/rust-android-gradle that referenced this issue Apr 24, 2020
@thomcc
Copy link
Contributor

thomcc commented Apr 24, 2020

Can you elaborate here? We should be outputting lib$name.so currently.

@Mygod
Copy link
Contributor Author

Mygod commented Apr 24, 2020

According to my test, it didn't work until we used some patch like shadowsocks/shadowsocks-android@5ea3e35.

@thomcc
Copy link
Contributor

thomcc commented Apr 26, 2020

Can you elaborate on "didn't work"? Sorry, just trying to understand what the issue is.

@Mygod
Copy link
Contributor Author

Mygod commented Apr 28, 2020

Yeah as said in title, the output binary is named $name instead of lib$name.so, so it does not get bundled into apk.

@Mygod
Copy link
Contributor Author

Mygod commented Apr 28, 2020

I understand that the code I changed in #31 is supposed to do exactly that but somehow that did not work.

Mygod added a commit to Mygod/rust-android-gradle that referenced this issue May 3, 2020
@Mygod
Copy link
Contributor Author

Mygod commented May 5, 2020

Okay I guess the issue is that we are compiling a binary instead of libraries like most Android apps do. I wonder what's the easiest way to do this with this plugin then. Currently we are using a convoluted workaround: shadowsocks/shadowsocks-android@833b35e

@ncalexan ncalexan changed the title Output binary is $name instead of lib$name.so Support and add a sample/test showing how to include a Rust binary like $name instead of a library like lib$name.so Apr 23, 2021
@ncalexan
Copy link
Member

Should somebody see this, I think we can support this without a workaround right now using targetIncludes. I'll leave this ticket to include a sample project that does exactly this.

@Mygod
Copy link
Contributor Author

Mygod commented Jul 12, 2021

I am not sure how this relates to compiling a binary?

@ncalexan
Copy link
Member

I am not sure how this relates to compiling a binary?

If I understand correctly, the issue is that cargo build debug will produce binary, but the plugin won't package it into jniLibs (which is where executables must go, last I checked). I think you can use targetIncludes to package it, but I haven't verified. Hence, let's have a sample project/test showing how to do it and making sure we don't regress the functionality. Is that clear?

@Mygod
Copy link
Contributor Author

Mygod commented Jul 12, 2021

I think last time I checked, the binary is not extracted from apk if the filename does not match lib$name.so. I could check again sometime.

@ncalexan
Copy link
Member

OK, I took a look at this. The way I'd like to support binaries is as follows:

  1. Make libname optional and add binname and/or binnames.
  2. Make binnames add --bin ... to the command line as appropriate
  3. Follow https://developer.android.com/ndk/guides/wrap-script#packaging_wrapsh and put the executable file into the Java resources. (I could be convinced that renaming to binname.so is enough here.)
  4. Verify that the APK does get the binary in the correct libs/$arch/... location in the APK.
  5. Verify that we can actually execute the binary on device and emulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants