3

When I ndk compile a project using r10b 64 bit builder it compiles good without any problem

I am able to run the project in Lollipop succesfully and app runs as it supposed to be

But when I run the project in JellyBean at runtime I get the following error

could not load library "libopenvpn.so" needed by "/data/data/de.blinkt.openvpn/cache/pievpn.armeabi-v7a"; caused by soinfo_relocate(linker.cpp:987): cannot locate symbol "srandom" referenced by "libopenvpn.so"...CANNOT LINK EXECUTABLE

so when I researched I found its due to using 64 builder and solution is to use 32 bit builder.

When I use 32 builder I get the following error during compilation itself.

Android NDK: NDK Application 'local' targets unknown ABI(s): arm64-v8a x86_64 Android NDK: Please fix the APP_ABI definition in ./jni/Application.mk
/Users/ShajilShocker/Documents/Android/NDK/android-ndk-r10b/build/core/setup-app.mk:112: *** Android NDK: Aborting . Stop.

so If I omit arm64-v8a and x86_64 then it'd possibly compile but it won't run on 64 bit devices it seems.

is it possible that I can compile the same project first using 32 bit (commenting 64 architectures) and compile using 64 bit(uncomment 64 architectures) and run on both.

Any help is highly appreciated !

Thanks !

Community
  • 1
  • 1
Shajo
  • 873
  • 2
  • 11
  • 22
  • 1
    This was already addressed at the question you linked, however the asker there didn't choose the best answer - see Michaël's answer pointing out the importance of the target Android version. – Chris Stratton Apr 27 '15 at 17:32

2 Answers2

5

64-bit ARM & X86 devices (not sure about MIPS) running Lollipop can execute 32 or 64-bit native code (ARMv7a/ARMv8 and X86/X64). Android allows you to bind native code libraries with multiple ABI's (CPU-specific code) into an APK. These are also called "FAT" binaries. For example, to build a FAT binary containing both ARMv7a and ARMv8 code, add the following line to your Application.mk file:

APP_ABI := arm64-v8a armeabi-v7a

Then, in your Android.mk file, you can add specific settings for each CPU type:

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
<your custom ARM 32-bit build instructions here>
endif

ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
<your custom ARM 64-bit build instructions here>
endif

When you run your fat binary containing both 32 and 64-bit code on a 32-bit system, it will load the 32-bit code and vice versa. There shouldn't be any need to conditionally compile in the code for each target device. That's the purpose of the fat binary - the system automatically loads the library appropriate for the target architecture.

BitBank
  • 8,500
  • 3
  • 28
  • 46
  • So,Do you suggest me to take 32 bit NDK builder and make the changes ? – Shajo Apr 29 '15 at 14:37
  • @Shajo You need to decide how you want it to build and make the changes to Application.mk and Android.mk. Your question implies that you're not clear on how it works. You choose which ABI's to include in your app and separate object libraries will be built for each one. The ANT tools will bind them all into a single APK. – BitBank Apr 29 '15 at 14:44
  • I am thinking of omitting `arm64-v8a` and `x86_64` from application.mk `APP_ABI := arm64-v8a armeabi armeabi-v7a mips x86 x86_64 ` – Shajo Apr 29 '15 at 14:53
  • I just want the app not to fail on 64 bit devices as well – Shajo Apr 29 '15 at 14:55
  • If you don't want to specifically optimize for 64-bits and just build for ARMv7a and x86, it will work on both 32 and 64-bit devices, so that should suit your needs. If 32-bit binaries didn't work on 64-bit devices, everyone who recently bought a Galaxy S6 or HTC M9 would be quite upset. – BitBank Apr 29 '15 at 15:02
  • The entry of lollipop has already raised eyebrows ..I am just worried I am not making any costly mistake – Shajo Apr 29 '15 at 17:21
  • Lollipop enables 64-bit NDK apps, but doesn't require NDK apps to have 64-bit code (yet). – BitBank Apr 29 '15 at 17:40
1

You should use NDK Revision 10c at least to support 64-bit system, according to the official documentation, https://developer.android.com/about/versions/android-5.0-changes.html#64BitSupport .