继续了解使用native_app_glue来编写纯C++的Android NDK开发。
下面从一个"最简单“的可运行的程序来了解native_app_glue程序的基本组成。
1. 源码main.cpp:
// main.cpp
#include <android_native_app_glue.h>
/**
* This is the main entry point of a native application that is using
* android_native_app_glue. It runs in its own thread, with its own
* event loop for receiving input events and doing other things.
*/
void android_main(struct android_app* state) {
// Make sure glue isn't stripped.
app_dummy();
}
首先,需要包含头文件android_native_app_glue.h,然后,必须实现一个android_main()函数,否则是无法运行的(编译可能没有问题)。另外,在android_main里面必须至少调用app_dummy(),这个函数的作用是为了保证glue没有被优化掉,参考android_native_app_glue.h中的说明:
/**
* Dummy function you can call to ensure glue code isn't stripped.
*/
void app_dummy();
2. Android.mk
<