Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android APK refuses to install its native .so into /data on some devices

I successfully compiled and packaged the NativeActivity example from the Android NDK. It runs fine in the Android emulator and even on a TI OMAP3621 device (Nook Color). However, it crashes on a Tegra 2 device. I also noticed that the .so included in the APK is getting copied to /dev/dev/com.example.native_activity/lib/libnative-activity.so on the Nook, but not on the Tegra 2 phone. The /data/data/com.example.native_activity/lib directory is indeed created, but the .so that should be in there is missing! I even tried copying the .so in there manually, but the app still crashed when I tried to launch it.

Why would the installer allow the APK to install, but refuse to copy the .so?

The emulator is running Android 2.3.3 The Nook Color is running Android 4.0.4 The Tegra 2 phone is running Android 2.3.7

Update:

It turns out the app does run if I copy the .so to /data manually. So the problem now seems to be due to aapt's packaging, since when the phone installs the app it does not copy the .so. I am using aapt from the command line (not through Eclipse), so perhaps I'm not using the right options when including shared libraries. Can someone explain how aapt packages an APK that contains native shared libraries?

Another Update:

Well, this is weird. I just discovered that if I install the APK, then immediately get application info on the installed app and "Move to SD card," it works! The .so is copied to /data/data/com.example/native-activity as expected. And if I then choose "Move to phone," it works, too!

I am running Cyanogenmod 7 on a Tegra 2 device. Why would this work when moving/installing to the SD card, but not the phone?

like image 412
Synthetix Avatar asked Dec 11 '25 20:12

Synthetix


1 Answers

Library file not loading in 2.3 but loading in 4.0

Rebuild for all possible CPU/ABI combinations. Android 4 often tries to load armeabi-v7a while Android 2.x is happy with armeabi.

To do that, create/open Application.mk in the jni folder, and place the following:

APP_ABI := armeabi x86 armeabi-v7a mips

MIPS only if you've got NDK r8.

like image 159
Sunny Kumar Aditya Avatar answered Dec 14 '25 08:12

Sunny Kumar Aditya