Android NDK 使用stlport

最近在看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)





你可能感兴趣的:(android,jni,iterator,express,library,permissions)