Android and androidsdk

Source: Internet
Author: User

Android and androidsdk
Add Standard C ++ files to JNI


Address: http://blog.csdn.net/caroline_wendy


Other references: http://blog.csdn.net/caroline_wendy/article/details/39032551


If you need to callStandard C ++ LibraryInJni folder, AddApplication. mkMethod.

InDeclare the standard template library (STL) using C ++):APP_STL: = gnustl_static

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

Then create Add C ++ source file and header file, In Android. mk statement.

The header file is the folder path (the same directory can be omitted),The source file is the cpp file address.Note:"+ =", Indicating to continue adding

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

Android. mkSpecific file:

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)

Header file and source file content:

/** Sayname. h ** Created on: September 4, 2014 * Author: Administrator */# ifndef SAYNAME_H _ # define SAYNAME_H _ # include <string> using namespace std; string sayname (void ); # endif/* SAYNAME_H _ * // ** sayname. cpp ** Created on: September 4, 2014 * Author: Administrator */# include "sayname. h "string sayname (void) {string str =" Hello Spike and Caroline and Wendy !!! "; Return str ;}



Interface files can be called, these standard C ++ files.

Specific call method:

#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());}





What is android

Android means a robot. android phones use android phones. Google developed android phones and android phones do not know what the android phones mean.

What is android

Android means a robot. android phones use android phones. Google developed android phones and android phones do not know what the android phones mean.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.