Android NDK 使用stlport

本文详细介绍了如何将C++ STL库与JNI接口进行集成应用,通过实际代码示例展示了如何在JNI中使用STL库进行数据操作,并强调了实践的重要性。同时,文章还探讨了在不同情况下选择stlport静态或共享库的注意事项。

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

最近在看box2d这个物理引擎,之前没有仔细自己写过jni的调用,只是看了看jni的语法和几个例子觉得还行难度不是很大,只是jni接口写起来很麻烦,一直没有自己动手做,

今天在论坛中看有人问stlport使用的问题,就自己动手写了下,发现这里面水还是比较深的,真是只有动手试了以后才只知道水深水浅;

下面是C++代码:


#include <string.h> #include <jni.h> #include <iostream> #include <memory> #include <vector> #include <list> #include <algorithm> using namespace std; jstring Java_com_example_hellojni_HelloJni_stlportUsage( JNIEnv* env, jobject thiz ) { vector<int> vec; vec.push_back(1); vector<string> sVec; sVec.push_back("hello-jni"); sVec.push_back(""); list<string> sList; sList.push_back("hello-jni"); vector<int>::iterator iter = find(vec.begin(), vec.end(), 1); return env->NewStringUTF("Hello from JNI !"); }
首先准备好Application.mk

APP_STL := stlport_static 或者APP_STL := stlport_shared


APP_STL := stlport_shared时要注意:

static { System.loadLibrary("stlport_shared"); }

然后修改android.mk


# Copyright (C) 2009 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-jni LOCAL_C_INCLUDES := $(LOCAL_PATH)/. LOCAL_SRC_FILES := crinson_jni.cpp com_example_hellojni_HelloJni.cpp include $(BUILD_SHARED_LIBRARY)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值