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

[Android NDK] libandroid_support.a incorrectly being linked on API 21+ when building fully static binary with c++-static #12840

Open
chenxiaolong opened this issue Jan 16, 2021 · 1 comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug

Comments

@chenxiaolong
Copy link

Description of the problem / feature request:

When building a fully statically linked binary with the c++-static STL on Android, libandroid_support.a gets linked unconditionally, which leads to multiple definition errors like:

external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: external/androidndk/ndk/platforms/android-29/arch-arm/usr/lib/../lib/libc.a(locale.o): multiple definition of 'duplocale'

As I understand it, libandroid_support.a is only supposed to be used on API versions older than 21 and only on armeabi-v7a and x86.

I suspect this behavior is caused by the glob defined here:

String template =
"ndk/sources/cxx-stl/%stl%/libs/%targetCpu%/*.%fileExtension%";

libandroid_support.a is in the same directory as libc++_static.a.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I've created a simple repro here: https://gist.github.com/chenxiaolong/dcda157428e60489efa7a2f9346e581e

git clone https://gist.github.com/dcda157428e60489efa7a2f9346e581e.git
cd dcda157428e60489efa7a2f9346e581e
# Both armeabi-v7a and x86 fail
bazel build --config=android_armeabi-v7a :main
bazel build --config=android_x86 :main

What operating system are you running Bazel on?

Ubuntu 20.04.1 on WSL2

What's the output of bazel info release?

3.7.2

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

n/a

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

n/a

Have you found anything relevant by searching the web?

This was the same issue, but for CMake: android/ndk#17

This is the comment from an NDK maintainer mentioning that libandroid_support is mean for API <21: android/ndk#17 (comment)

Any other information, logs, or outputs that you want to share?

n/a

@jin jin added team-Android Issues for Android team untriaged labels Jan 19, 2021
@ahumesky ahumesky added P2 We'll consider working on this in future. (Assignee optional) type: bug and removed untriaged labels Jun 18, 2021
@ahumesky
Copy link
Contributor

ahumesky commented Oct 6, 2022

Bazel's NDK integration has been rewritten into a separate Starlark implementation, you might try using the new rules:
https://github.com/bazelbuild/rules_android_ndk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug
Projects
None yet
Development

No branches or pull requests

3 participants