Familiar with Android and Linux
Developers will laugh at this weak article, but this article is intended for developers who do not know it. Of course, I will be very happy if you are familiar with it and intend to continue reading it. :)
As we all know, Android is based on Linux, so everyone can think that Android should be able to run programs in Linux, but this platform uses ARM
So where can I find an ARM Linux compiler? Here I recommend the Sourcery G ++ compiler, which is:
Http://www.codesourcery.com/sgpp/lite/arm/portal/release1803
Because my system is Windows, I downloadedIA32 Windows InstallerAfter the installation is completed step by step, we can use C/C ++
Write a program, compile it, and run it on AVD or your machine.
Below is a Hello World Program I wrote in C.
#include <stdio.h>int main(void){char s[20];scanf("%s",s);printf("Hello world, from %s.\n",s);return 0;}
SaveHello. cBecause
Android Linux kernel does not have standard I/O library functions, so we use static compilation.
Arm-none-linux-gnueabi-gcc-static
-O hello. c
Then we use adb to upload the hello program to AVD or your machine's/data
Directory. You may wonder why you want to upload the file to this directory? The reason is that the/system/bin and/sbin directories of Android are Read Only.
System, and all the file owner users under/mnt/sdcard are system, and the permission group is sdcard_r, even if it is root
The account cannot add executable permissions for files. Of course, you may also find other directories that can upload and change file permissions.
Adb push hello/data
Then we use adb
Shell Command to enter the shell of your Android device and change its permissions.
Adb shell
Cd/data
Chmod 777 hello
The execution result is as follows:
./Hello
Newcj
Hello world, from newcj.
How about it? Interesting. Please try it now. I believe you will also feel interesting!