Ubuntu 16.04 下 构建 Android(NDK) 应用
Last updated on May 7, 2023 pm
[TOC]
NDK Build
Generate .so
or .a
files using NDK tools:
Edit
.java
file;Generate header file for the java file using JDK tools
javac
andjavah
;1
2
3# 在 `src` 目录下
javac com/ndk/test/OpenCVTest.java
javah -classpath ./ -jni com.ndk.test.OpenCVTestEdit
Android.mk
andApplication.mk
files;Generate
.so
or.a
files using commandndk-build
;Load the library and using its methods
NDK Tips
Android NDK 从2013年开始支持了C++11,从2015年开始支持C++14,在 Android.mk
中加入
1 |
|
When compiling c++ code with -std=c++11
and using gnustl_shared
, many C99 math functions are not provided by the APP_STL := c++_static
may help. (from Issue: C++11 cmath functions not in std namespace)
Build Android Project
Build Ant Project
generate
build.xml
for Ant1
android update project -p .
build ant project
1
ant debug/release
Build Eclipse Project
Sign APK
Generate keystore file
1
keytool -genkey -alias ChenguangCam -keyalg RSA -validity 100000 -keystore AndroidCameraApp.keystore
Sign Apk
- 使用第三方工具:爱加密签名工具;
- 使用命令行
1
2jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore
<path_to_AndroidCameraApp.keystore> -storepass 123456 -keypass 123456 -signedjar <path_to_signed.apk> <path_to_unsign.apk> ChenguangCam - Eclipse Project: 右键单击项目名称,选择"Android Tools",再选择"Export Signed Application Package…";
- Ant Project: add key.store and key.alias properties to ant.properties file;
Install APK
Install apk file to devices
1
2
3adb install <path_to_apk>
# or
adb install -r <path_to_apk>uninstall apk
1
adb uninstall <package-name>
Debug
Native C++ Crash Debug
当NDK生成的 .so 运行崩掉时,通过NDK工具查找相关信息。
ndk-stack
1) 实时分析日志
程序运行过程中,执行如下命令:
1 |
|
当程序崩溃时,可输出崩溃信息。
2) 获取日志再分析
程序运行过程中,执行如下命令:
1 |
|
程序崩溃后,通过如下命令获取崩溃信息:
1 |
|
或 通过关键字查找
- NDK logcat crash keywords > --------- beginning of crash > backtrace
arm-linux-androideabi-addr2line
获取日志中关键函数指针,例如
#00 pc 00031896 /data/app/com.tools/lib/arm/libtools.so
根据地址,使用如下命令找到对应的函数:
1 |
|
Check File Dependencies
arm-linux-androideabi-readelf
- check .so file
1
arm-linux-androideabi-readelf -d *.so
应用认领
应用认领那些事:
http://droidyue.com/blog/2014/12/14/android-yingyong-renling/?utm_source=tuicool&utm_medium=referral