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

--incompatible_remove_legacy_whole_archive produces empty .so binary #10051

Closed
korDen opened this issue Oct 17, 2019 · 5 comments
Closed

--incompatible_remove_legacy_whole_archive produces empty .so binary #10051

korDen opened this issue Oct 17, 2019 · 5 comments
Assignees
Labels

Comments

@korDen
Copy link

korDen commented Oct 17, 2019

Noticed this issue while migrating from bazel 0.29.1 to 1.0.0

I have an Android app that has NO java code (AndroidManifest defines android:hasCode="false"), and all the implementation is in JNI (lots of code).

bazel 0.29.1 produces a 290kb libjni.so binary
bazel 1.0.0 produces 6444 libjni.so binary. All the code is essentially stripped (ANactiveActivity_onCreate is missing, along with everything it calls).

I tracked it down to --incompatible_remove_legacy_whole_archive flag. Once enabled on 0.29.1, it produces the same broken .so file.

Not sure if it's related, but it could have something to do with my app not having any Java code:

<activity android:name="android.app.NativeActivity">
  <meta-data android:name="android.app.lib_name" android:value="jni" />
  <!-- skipped -->
</activity>

This creates NativeActivity which loads libjni.so. With 1.0.0 (or with --incompatible_remove_legacy_whole_archive) produced binary is a toast.

@korDen korDen changed the title --incompatible_require_java_toolchain_header_compiler_direct produces empty .so binary --incompatible_remove_legacy_whole_archive produces empty .so binary Oct 17, 2019
@korDen
Copy link
Author

korDen commented Oct 17, 2019

I guess it can be solved by including alwayslink = True in cc_library but that feels wrong.

@hlopko
Copy link
Member

hlopko commented Oct 30, 2019

I presume you're creating the final shared library using cc_binary(linkshared =1,...) way right? Does this cc_binary have sources? Which android ndk are you using?

@hlopko hlopko self-assigned this Oct 30, 2019
@hlopko
Copy link
Member

hlopko commented Dec 6, 2019

Closing for inactivity, please complain to reopen :)

@hlopko hlopko closed this as completed Dec 6, 2019
@arturdryomov
Copy link
Contributor

arturdryomov commented Dec 12, 2019

@hlopko, hey, I think it relates to #10323 which essentially breaks the official NDK example (see bazelbuild/examples#125 as well). Setting alwayslink indeed helps. Feels like since 1.0.0 rules_android started to strip everything from native binaries for some reason. Also seems like this happens after the native library is built since both commands below produce the same libjni_lib.so.

USE_BAZEL_VERSION="0.29.1" bazelisk build //app/src/main:jni_lib --crosstool_top=@androidndk//:default_crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=x86
USE_BAZEL_VERSION="1.0.0" bazelisk build //app/src/main:jni_lib --crosstool_top=@androidndk//:default_crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=x86

@arturdryomov
Copy link
Contributor

Seems to be related to #7362 as well. Actually, it was explicitly mentioned but didn’t get into the documentation and samples.

@hlopko, can you please explain for dummies like me what’s happening? Feels like alwayslink should be set to True for all Android native libraries — but I still don’t get what should be done: applications should do the switch themselves (the Android documentation should be adjusted then) or it can be applied for all Android targets on the rule level.

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

No branches or pull requests

5 participants