1 / 3

C/C++ programming on Android

C/C++ programming on Android. Console C/C++ programming on Android without NDK. Get compile for the ARM tool chain (get the one targeted at "GNU/Linux"): http://www.codesourcery.com/gnu_toolchains/arm/download.html This only runs on linux Make new dir Create empty doc Save doc as hello.cpp

zenia
Download Presentation

C/C++ programming on Android

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C/C++ programming on Android

  2. Console C/C++ programming on Android without NDK • Get compile for the ARM tool chain (get the one targeted at "GNU/Linux"): http://www.codesourcery.com/gnu_toolchains/arm/download.html • This only runs on linux • Make new dir • Create empty doc • Save doc as hello.cpp • Open doc and enter • #include “stdio.h” • int main(intargc, char **argv) { • printf("Hello, world!\n"); • return 0; • } • Save • arm-none-linux-gnueabi-gcc -static -o hello hello.c • (move executable on window drive) • adb push hello /data/misc/hello • This will most likely fail. If so, then • adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /data • Then adb shell chmod 777 /data/misc/hello • adb shell chmod 777 /data/misc/hello • Then run it adb shell /data/misc/hello

  3. Starting a console program from java • The only way for an android app to execute something that needs root access is to make a separate c/c++ program and run that program from your app. • You could write the program in another language, but you would need to arm compiler for that language • Of course, this requires that the phone is rooted • The path to the su program. • Sometimes just “su” works, other times you need /system/bin/su • The su program is installed when you root the phone • To test you have root, • C:\android\android-sdk\platform-tools\adb shell • $: su • ls /data/data • Once you have root, this listing will work and not give an error • Path to program • String programPath = “/mnt/sdcard/hello”; • //ProcessBuilderpb = new ProcessBuilder(new String[]{"/system/bin/sh", "-c", programPath}); • ProcessBuilderpb = new ProcessBuilder(new String[]{“su", "-c", programPath}); • pb.redirectErrorStream(true); • Process process; • process = pb.start(); • BufferedReader reader =new BufferedReader(new InputStreamReader(process.getInputStream())); • String rline; • while ((rline = reader.readLine()) != null) {} • process.waitFor();

More Related