开发者

Google-NDK / Compiling command-line C applications without any JNI interaction

开发者 https://www.devze.com 2023-03-15 01:26 出处:网络
Android-NDK is mostly used to write/port native libs which can be called from Java through the JNI mechanism.

Android-NDK is mostly used to write/port native libs which can be called from Java through the JNI mechanism.

I have an ARM based evalboard embedding Android. This evalboard has a serial port so that I can log with a remote terminal on it and then launch commands or other apps ("command line apps" - non Java apps).

I wonder if that is possible with Android NDK开发者_开发技巧 to compile "pure" C applications which I will later use as a command on the remote shell? The main idea is to benefit from the toolchain provided by Google-NDK to build code which never interacts with the Dalvik machine.

Best Regards, Apple92


Hello World C program using Android Toolchain is an article to explain how to compile using android toolchain. I think it useful to you.


Yes, you can compile command line programs using the NDK. If you take a look at any functioning Android system, you'll find many examples of command line programs which have been compiled using that same compiler.


Yes, there is BUILD_EXECUTABLE command, which acts like BUILD_SHARED_LIBRARY but produces an executable. The trick is the libraries your executable depends upon - they will either need to be on device already (/system/bin) or you will have to upload them with your executable.

I came up with the following script to upload and execute tests:

#!/bin/sh

adb shell rm -r /data/temp
adb shell mkdir /data/temp

for i in dst/* 
do
  adb push ${i} /data/temp
done

cat <<EOF | adb shell
LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/data/temp
/data/temp/test
exit
EOF
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号