Android系统的命令行操作及C程序编译

在Android系统执行C程序,需要使用Android系统的专用编译器NDK,下载NDK工具可以通过以下博文中给出的链接:

https://blog.csdn.net/baidu_35904821/article/details/62218559

Android API与版本对应关系:

https://www.jianshu.com/p/27711d61f221

除了使用封装好UI界面的Android程序编译环境如Android Studio或者MyEclipse调用NDK工具包,还可以自己动手配置相关环境变量后,在命令行使用NDK工具。

命令行NDK的使用方法有两种,以使用android-ndk-r13b的ARM架构版本为例,首先下载Windows或者Linux相应版本的NDK工具包,接着有两种方法如下:

1、Linux下配置路径export PATH=$PATH:$HOME/home/.../android-ndk-r13b,Windows下配置环境变量即可,然后编写Android.mk 与 Application.mk脚本,使用命令ndk-build即可。

关于Android.mk 与 Application.mk脚本,可以通过以下博文简单了解:

https://blog.csdn.net/libinbin147256369/article/details/80026182

https://www.jianshu.com/p/26275f3d583e

2、linux下source环境变量脚本,配置编译器和链接库,在shell中source执行配置脚本,脚本内容可以如下:

export PATH=$PATH:/home/.../android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/
alias android-gcc='arm-linux-androideabi-gcc --sysroot=/home/.../android-ndk-r13b/platforms/android-18/arch-arm'

脚本将arm-linux-androideabi-gcc编译器封装成android-gcc,执行android-gcc命令可以编译运行于Anroid系统的C程序(注意内核架构对编译器选择的影响)。

第二种方法比较适合快速编译和调试程序,可以通过命令android-gcc -v来检测初步配置是否成功:

fupenzi@ubuntu:~/workspace$ android-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-androideabi-gcc
COLLECT_LTO_WRAPPER=/home/yut/fuyp/android/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper
Target: arm-linux-androideabi
Configured with: /usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/configure --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --target=arm-linux-androideabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/buildbot/tmp/build/toolchain/temp-install --with-mpfr=/buildbot/tmp/build/toolchain/temp-install --with-mpc=/buildbot/tmp/build/toolchain/temp-install --with-cloog=/buildbot/tmp/build/toolchain/temp-install --with-isl=/buildbot/tmp/build/toolchain/temp-install --with-ppl=/buildbot/tmp/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-bionic-libs --enable-libatomic-ifuncs=no --enable-initfini-array --disable-nls --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --with-sysroot=/tmp/59719db9ae19ff43aef46bbcb79596b6/sysroot --with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=none --with-gxx-include-dir=/tmp/59719db9ae19ff43aef46bbcb79596b6/include/c++/4.9.x --with-bugurl=http://source.android.com/source/report-bugs.html --enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp --enable-gnu-indirect-function --disable-libsanitizer --enable-gold --enable-threads --enable-eh-frame-hdr-for-static --enable-graphite=yes --with-isl-version=0.11.1 --with-cloog-version=0.18.0 --with-arch=armv5te --program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default
Thread model: posix
gcc version 4.9.x 20150123 (prerelease) (GCC)

然后和使用GCC编译器一样,执行命令如:android-gcc client.c -o client_android,即可在Linux PC机上命令行编译Android系统的C程序。

附上一些常用的Android嵌入式系统的调试命令:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~常用调试命令~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
getprop
+++++获取系统的所有配置信息
getprop ro.product.cpu.abi
+++++获取单项配置信息
getprop ro.build.version.release
+++++获取Android版本信息
getprop ro.build.version.sdk
+++++获取系统API信息
setprop confnm value
+++++对指定配置项重新赋值
pm install -r xxx.apk
+++++安装android apk
pm list packages
+++++查看所有已经安装的APP
pm install/uninstall
+++++安装或者删除APP
am start -n com.app/.init.WelcomeActivity
+++++启动某应用,在AndroidManifest.xml文件中查看声明的Activity信息
am restart
+++++重启
dumpsys activity activities
+++++查看正在运行的Activity

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~busybox~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mount -o remount /
+++++重新挂载根文件系统,并将权限默认为rw,sdcard目录为可读可写
busybox chmod 777 file
+++++修改执行权限

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值