David Pisoni
David Pisoni

Reputation: 3437

If I exclude all 64-bit libraries from my android app, will it run entirely in a 32-bit mode?

I am building my Android app excluding all ARM v7 and ARM64 v8 libraries, per this example: https://stackoverflow.com/a/30799825/736963 (though I include only armeabi in the ARM family.) This is because I have a 3rd-party library that is only built to the armeabi target. This scheme is working as expected, but I'm left with this nagging doubt...

Under this scheme, does that mean that if I run the app on 64-bit device that everything running in my app is running in a 32-bit mode? In other words, all the android/java code included in the app that ultimately reaches through to backing libraries, is it running the ARMv5 versions of the Android SDK (e.g., display routines, math routines, etc.)? Or do the calls to the Android SDK operate on platform-native code even if the included binaries (the .so's) are all ARMv5?

Upvotes: 3

Views: 1826

Answers (1)

mstorsjo
mstorsjo

Reputation: 13317

Yes, if the APK installer chooses to install 32 bit binaries (from an armeabi or armeabi-v7a directory), the whole process, including all platform libraries within your process, will run in 32 bit mode.

This is not quite as dramatic and bad as you think though. All the platform libraries will have been built with the maximum amount of optimizations for your current device, even in 32 bit mode. So even if your app contains binaries in armeabi mode, the platform's libraries aren't restricted to the limitations of that baseline; they will use whatever best instructions available on your particular device. The only downside is that it uses the slightly less efficient 32 bit mode, but the actual difference and effect is mostly marginal.

Do note that while there is quite a big performance difference between armeabi and armeabi-v7a, the two are compatible in the sense that both are 32 bit; a process loading armeabi-v7a libraries can also load libraries in armeabi format just fine. (You still need to have all binaries available in all the chosen ABIs though, but that's more of an APK installer design choice.)

So in case your app only uses this third party library but no other native code of your own, you should be fine (although, depending on what the library does, you would gain some performance if the third party library supplier would provide armeabi-v7a or arm64-v8a versions). If your app has extra native code of your own, you might want to consider building it in armeabi-v7a mode, but copy the third party library from armeabi to armeabi-v7a. As said above, it will load and run just fine, but will allow your own code to be built with more optimizations. (Since the 32 and 64 bit versions are incompatible, you can't put the armeabi version into arm64-v8a though, as you already tried.)

The main difference between armeabi and armeabi-v7a is that binaries built for the latter will use hardware floating point - if you do lots of floating point calculations, it will affect performance a lot, otherwise not that much. The difference between armeabi-v7a and arm64-v8a is normally not that big, for most code it's just a few percent at most.

Upvotes: 3

Related Questions