When I try to build my app in Android studio I get next error:
[x86] Compile : mpg123 <= getcpuflags.S
[x86] Compile : mpg123 <= dither.c
[x86] Compile : mpg123 <= feature.c
[x86] SharedLibrary : libmpg123.so
/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable
/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: treating warnings as errors
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/app/build/intermediates/ndkBuild/debug/obj/local/x86/libmpg123.so] Error 1
It is happen only for x86 ABI. I build successfully for armeabi-v7a ABI. But for x86 I get error. I am using SDL2-2.0.7, SDL2_image-2.0.2 and SDL2_mixer-2.0.2.
Android with armeabi-v7a is very slow that is why I need android with x86 to test my app.
Itās likely to be because of the change at API level 23, requiring that x86 shared libraries not contain text relocations (see here). That means they must be compiled as Position Independent Code (for example using the -fPIC compiler flag).
Two points. Firstly, disabling the warning (even if you can succeed in doing that) isnāt going to help, because recent versions of Android will not install an app that has Text Relocations in shareable libraries. So by disabling the warning you are simply transferring the problem from build-time to install-time!
Secondly, I think LOCAL_LDFLAGS controls the linker flags, not the compiler flags. Try putting the ā-fPICā in LOCAL_CFLAGS.
getcpuflags.S is an assembly language file so the -fPIC switch is not going to have any effect on that. If the text relocation is in that module, the only solution will be to re-write the assembler code. If itās a trivial function - which Iām guessing from the filename it probably is - that may not be too difficult.
Itās even possible that the code is already position-independent but the object module generated by the assembler contains a flag to say it isnāt. Until this issue arose that would have been harmless, but now it isnāt.
Arguably whoever maintains SDL_mixer should make the modification because itās not very satisfactory for a standard SDL extension to be incompatible with x86 Android. On the other hand itās the fault of Google for introducing this questionable restriction.
No, just a user. But because my app is affected by this issue I have done some research into it. At the moment I canāt support x86 Android later than Lollipop, and probably I never will. Itās less of a problem than it might have been because Intel have pulled out of mobile CPU development, so there probably wonāt be any more x86-based mobile devices. However it stops my app running on most Chromebooks which is more serious.
I think you mentioned earlier that an ARM build (which should not be affected by this issue) is too slow, but thatās not been my experience. The best ARM-based products (for example my OnePlus 5 phone) are much faster than any x86-based mobile devices I have ever tested. Perhaps you should consider that route.
It is very slow on android emulator. Besides it takes a lot of CPU when I start run app on armeabi-v7a emulator. I will buy some android device (or devices) for testing but only after I will run successfully and test on emulators.
I see only one option at current moment: connect somehow with SDL2 developers and ask them.
Oh, I see. Iāve never used an Android emulator; Iāve read too many reports of them giving misleading results. Iāve found testing on a real device to be entirely satisfactory, using USB debugging (adb).
@rtrussell, I have got an email from moderator of this forum. He have wrote that latest SDL_mixer changes have fixed the compile error: http://hg.libsdl.org/SDL_mixer .
I have downloaded latest changes from this page from line
2 days ago Sam Lantinga Added support for building mpg123 on Android arm64-v8a default tip
from field āfilesā which lead me to this page but it still doesnāt work for me. Besides, in new changes in file /app/src/main/cpp/SDL2_mixer/external/mpg123-1.25.6/Android.mk I see lines:
# This disables the following warning:
# warning: shared library text segment is not shareable
# However, the library still has PIC unaware assembly!
LOCAL_DISABLE_FATAL_LINKER_WARNINGS = true
I have tried earlier to set LOCAL_DISABLE_FATAL_LINKER_WARNINGS to the true, but every time I got an error:
dlopen failed: /data/app/com.myapp-1/lib/x86/libmpg123.so: has text relocations
and I got this error at this time after using the latest changes in SDL2_mixer. I got this error on Android emulator in pop-up window.
So, latest changes in mercurial repository donāt work.
Problem is in the mpg123 library and it was added to SDL2_mixer only in 2.0.2 version of mixer. mpg123 is absent in the 2.0.1 version of SDL2_mixer. Is it really so needed in the mixer if mixer became a broken in android x86?
I wonder if the issue has been misunderstood by whoever made those changes. Disabling the warning (which is what you were also trying to do) does not address the true problem, it simply defers it from being reported at build time (which is helpful) to it becoming a fatal error at install time (which is unhelpful). I donāt know of any solution other than modifying the assembly language code to be position-independent.