标签:
Here‘s demo application called "Run Native Exe" to:
Package: NativeExe-0.2.apk
Source code: on Github (ADT project)
To install the package,
or type "adb install NativeExe-*.apk" in your PC if you have Android SDK.
You can use Runtime.exec() in standard Java. Here‘s sample code to run /system/bin/ls /sdcard in Android App:
try { // Executes the command. Process process = Runtime.getRuntime().exec("/system/bin/ls /sdcard"); // Reads stdout. // NOTE: You can write to stdin of the command using // process.getOutputStream(). BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); // Waits for the command to finish. process.waitFor(); return output.toString(); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); }
This code is based on this article. Thanks yussi to let me know this by comment.
First, you need to cross-compile your native executable for ARM.
Here‘s a way (dynamic link version). Or you can use Scratchbox (Japanese).
If you get a file with a format like this, it‘s probably OK:
% file yourapp yourapp: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, statically linked, not stripped
You have three ways to put the binary to the phone:
% adb shell $ su # mkdir /data/tmp # chmod 777 /data/tmp # exit $ exit % adb push yourapp /data/tmp % adb shell $ chmod 744 /data/tmp/yourapp $ /data/tmp/yourapp
Note that you cannot make files executable in /sdcard.
Run native executable in Android App
标签:
原文地址:http://www.cnblogs.com/shangdawei/p/4490859.html