How to compile C into an executable binary file and run it in Android from Android Shell?

后端 未结 5 1978
闹比i
闹比i 2020-11-28 03:25

I have a Device on which I installed Android Gingerbread 2.3.4 Here i want to run C executable file on android device

I am able to run android NDK application on thi

5条回答
  •  庸人自扰
    2020-11-28 03:39

    In a nutshell,

    First, to cross-compile your C code from your host machine, use NDK toolchain with sysroot option and position independent option -fPIE -pie.

    $NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc \
    --sysroot=$NDKROOT/platforms/android-22/arch-arm64 -fPIE -pie main.c -o main
    

    the arch part arrch64 or arch-arm64, the toolchain version part 4.9, platform version part android-22, and the binary format for your host machine darwin-x86_64 may vary by your environment.

    Second, push your binary under /data/local/tmp and execute it from adb shell.

提交回复
热议问题