Want to compile native Android binary I can run in terminal on the phone

前端 未结 4 1518
粉色の甜心
粉色の甜心 2020-11-29 17:55

I\'ve been trying for a couple days to compile a native ARM Android binary that will execute on my phone using a terminal application. I want to generate the same type of bi

4条回答
  •  一个人的身影
    2020-11-29 18:33

    First, make sure you have the NDK:

    http://developer.android.com/tools/sdk/ndk/index.html

    Here is the easiest way to compile a C binary for your phone:

    http://developer.android.com/tools/sdk/ndk/index.html

    http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html

    Usually $NDK(may be different) =

    Linux:

    /home//android-ndk

    Mac OS X:

    /Users//android-ndk

    In Terminal:

    # create tool-chain - one line
    # New method in ndk 12.
    $NDK/build/tools/make_standalone_toolchain.py --arch arm --install-dir=/tmp/my-android-toolchain
    # Old method.
    #$NDK/build/tools/make-standalone-toolchain.sh --platform=android-3 --install-dir=/tmp/my-android-toolchain
    
    # add to terminal PATH variable
    export PATH=/tmp/my-android-toolchain/bin:$PATH
    
    # make alias CC be the new gcc binary
    export CC=arm-linux-androideabi-gcc
    
    # compile your C code(I tried hello world)
    $CC -o foo.o -c foo.c
    
    # push binary to phone
    adb push foo.o /data/local/tmp
    
    # execute binary
    adb /data/local/tmp/foo.o
    

提交回复
热议问题