Android NDK纯C++开发(2)

本文介绍了如何使用native_app_glue进行纯C++的Android NDK开发。主要内容包括源码main.cpp的修改,如增加LOCAL_LDLIBS和LOCAL_STATIC_LIBRARIES,AndroidManifest.xml中Activity需设为NativeActivity。特别强调了android_main和android_dummy函数的作用,以及纯C++程序的基本构成,指出虽然能运行但不响应事件的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续了解使用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

<
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值