Android technology 16: Compile binary files that can be directly run in Android, android binary
We all know that all applications in Android run on the Dalvik Virtual Machine of Android. Generally, the program does not directly deal with the operating system. Even if the underlying method is called, JNI technology is used. However, we can directly use the C language to write binary files and run them directly at the underlying layer. The following describes the procedure.
1. Install and download the compiler and linker software. Sourcery G ++ Lite Edition for ARM.
Arm-none-linux-gnueabi-gcc.exe is the compile command
Bin/arm-none-linux-gnueabi-ld.exe is a link command
2. Write C code
To demonstrate how to easily write the simplest code, output hello and world. For example, I wrote the hello. c file in the d:/temp directory.
# Include <stdio. h>
Int main (){
Printf ("helloworld \ n ");
Return 0;
}
3. Compile the hello. c file
Cmd --- d:/--- cd temp enter the arm-none-linux-gnueabi-gcc hello. c-static-o hello under the temp directory, and generate the hello binary file in the directory.
4. push the hello file to the mobile phone
Start the simulator --- adb push hello/data/hello
5. modify attributes
Adb shell
Cd/data/
Chmod 777 hello
Modify hello to an executable file
6. Execution File
./Hello
7. Display
Helloworld
How does android mainxml run in android?
Hello, every time you start an anroid project, the component information is directly read from main. xml. Generally, main. xml stores some la S and components used.
Why does Android not directly execute Linux programs? Instead, how can I develop one?
To answer this question, simply technically speaking, there are some questions about moving Linux directly to a mobile terminal: the commonly used graphic interface in Linux is X Window, although improvements have been made in the Unix/mainframe era, however, the client/server architecture is inefficient. It is not very suitable for mobile terminal X Window. It is just a graphical interface protocol, and the Window manager is also needed, most people are familiar with gnome or KDE running on the desktop system. In fact, there are many other common window managers, such as xfce and twm. These commonly used Window managers are not suitable for the lack of good encapsulation of the graphic interface of touch screen Linux, X Window Programming is complicated, and controls do not have uniform interface specifications and programming interfaces. Various Window managers use their own controls, making it difficult to unify the interface style.
Poor cross-platform compatibility. Linux binary executable files depend on the CPU architecture. If multiple vendors use processors of different architectures, android programs cannot run without an efficient package management system. Linux systems use different package management systems, such as apt, rpm, dpkg/ipkg loose management of executable files/library files/configuration files, it is not suitable for Android mobile platforms to place each App in a relatively independent file space/virtual machine. There are other technical reasons, such as poor support for fonts, images, and special interface effects.