Android - JNI添加標準C++檔案

來源:互聯網
上載者:User

標籤:mystra   android   jni   c++   stl   

JNI添加標準C++檔案


本文地址: http://blog.csdn.net/caroline_wendy


其餘參考: http://blog.csdn.net/caroline_wendy/article/details/39032551


如果需要調用標準C++庫, 則需要在jni檔案夾下, 添加Application.mk方法.

在其中聲明使用C++的標準模板庫(STL)APP_STL := gnustl_static

APP_STL := gnustl_staticAPP_CPPFLAGS := -frtti -fexceptions#APP_ABI := armeabi-v7a

然後建立 添加C++源檔案和標頭檔, 在 Android.mk中聲明

標頭檔是檔案夾路徑(同目錄可以省略), 源檔案是cpp檔案地址, 注意是"+=", 表明是繼續添加

#LOCAL_C_INCLUDES += ./LOCAL_SRC_FILES += ./sayname.cpp

Android.mk具體檔案:

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE    := HelloMyJniLOCAL_SRC_FILES := HelloMyJni.cpp#LOCAL_C_INCLUDES += ./LOCAL_SRC_FILES += ./sayname.cppinclude $(BUILD_SHARED_LIBRARY)

標頭檔和源檔案內容:

/* * sayname.h * *  Created on: 2014年9月4日 *      Author: Administrator */#ifndef SAYNAME_H_#define SAYNAME_H_#include <string>using namespace std;string sayname(void);#endif /* SAYNAME_H_ *//* * sayname.cpp * *  Created on: 2014年9月4日 *      Author: Administrator */#include "sayname.h"string sayname(void) {string str = "Hello Spike and Caroline and Wendy!!!";return str;}



介面檔案就可以調用, 這些標準C++檔案了.

具體調用方法:

#include <jni.h>#include "com_example_hellomyjni_JniClient.h"#include "sayname.h"JNIEXPORT jstring JNICALL Java_com_example_hellomyjni_JniClient_sayName  (JNIEnv *env, jclass) {string str = sayname();return env->NewStringUTF(str.c_str());}




Android - JNI添加標準C++檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.