Compiling C code on an Android phone

I want to compile and run .c files that are sent to my AndroidApp. I want to compile ARM.c files for ARM. I am using Galaxy Nexus with Android 4.2. I installed the Android SDK and Android NDK I did this using the terminal IDE, but I do not want to compile it manually from the terminal. Now I downloaded GCC for Android (android-gcc-4.4.0) and I don’t know how to add this to my application and how to compile it from inside the Java code.

I read a lot of things on the Internet about this, but none of them helped me figure out how to do this.

So my problem is: How can I use the Android / NDK Toolchain from my Android application or any other toolchain to compile and run .c files.

EDIT: Now I got android-gcc unzipped right on my phone in the files directory (data / data /.../ files). I want to call the gcc compiler on the phone to compile the .c file. I tried using:

String[] cmds={MainActivity.this.getFilesDir() + "/android-gcc-4.4.0/bin/arm-eabi-gcc-4.4.0", "-c", file_path};
String result = "";
Process p = Runtime.getRuntime().exec(cmds);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null) 
{
    result += line + "\n";
}
alert_dialog("Output", result); // Creates and displays an alert dialog
in.close();
}
catch (Exception e) 
{
    alert_dialog("Error", e.toString() + "\n" + e.getMessage());
}

This was my approach calling gcc on Android, but I only get the exception: java.io.IOException: Error exec () executing. Command [...] Working directory: null Environment null.

Does anyone know how to properly call the android-gcc compiler on the phone?

Any thanks and thanks in advance

+5
source share
1 answer

This is not an officially supported scenario; no OS worthy of its salt would allow unprivileged applications to install executable code on a device perforce.

; . NDK . NDK, ARM.

-1

All Articles