17

I've compiled a binary using the Android NDK toolchain, and am attempting to deploy it to a device. An application which has been built with the NDK using JNI will then execute this binary via native code. I'm hoping to avoid rooting the device.

The binary will be used by multiple applications, so I'd like to store it in a shared location, rather than once per application.

I can't find an appropriate location to deploy this binary to - these are the places I've tried:

  1. /mnt/sdcard - using getExternalStoragePublicDirectory() from the SDK, however the SD card is mounted as noexec, meaning I can't run it.

  2. /system/bin - read-only file system, so can't copy. I can push the file using adb push if I remount /system on the emulator using:

    mount -o rw,remount -t yaffs2 /dev/block/mtd3 /system
    

    However I'd like to avoid this, as the device would need to be rooted.

  3. /data/local - using adb push, I can push the binary to this location. However, I can't seem to find a way to do this in code (using the Android SDK). The internal storage mechanism points to /data/data/package.

I've compiled native code which calls this executable, using arm-linux-androideabi-g++ shipped with the NDK toolchain. This works with the binary in /system/bin and /data/local.

In summary, I'm looking for a location in the Android file system to which I can copy a file from the project /assets folder, which world-executable permissions are possible.

Tom Smith
  • 193
  • 1
  • 1
  • 8

3 Answers3

13

/data/local/tmp/ and "/data/data/" + packageName + "/files"

for direct testing you target binary , first is recommend.

Frei Zhang
  • 417
  • 6
  • 12
5

If you can use adb, you can prepare directory /data/local/bin with 777 permissions.

Alternatively, you can create a file in the private app directory (/data/data/your.package.unique.name/files), and set the file permissions to 777 755.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • 2
    777 means other apps can replace the executable with malware; that's unnecessary and a very bad idea. The others needs to be able to read and execute, but not write. – Chris Stratton Dec 04 '12 at 00:56
  • 1
    Correction accepted. The permissions should be set to 755 for the file. – Alex Cohn Dec 04 '12 at 09:15
1

If you want to avoid rooting the device then basically SD card is the only place you can assume is world writeable


EDIT: mind recent changes in Android framework as of 2014/2015!.

It's better to make your binary part of installable APK which then extract this binary out of APK into private storage, make it world executable etc and somehow announce binary location, but in general expect some problems depending on OS version and vendor

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141