NDK 原生库(新手入门)

首先是文件布局:

$ tree .
.
└── jni
    ├── Android.mk
    ├── Application.mk
    ├── hello-jni.cpp
    └── hello-jni.h

1 directory, 4 files

所有文件内容:

$ ls | xargs cat

# Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_CPPFLAGS  := -std=c++11
LOCAL_SRC_FILES := hello-jni.cpp
include $(BUILD_STATIC_LIBRARY)  # BUILD_SHARED_LIBRARY


# Application.mk
APP_STL := c++_static

APP_ABI := armeabi armeabi-v7a x86


# hello-jni.cpp
#include "hello-jni.h"
#include 

void printx()
{
    __android_log_print(2,"xxxxx","printx\n");
}

    TEST11::TEST11(std::string name) {
        shared_ptr a(new std::string(name));
        _name.reset(new std::string(name));

        __android_log_print(2,"xxxxx","%s\n", name.c_str());
    }
    TEST11::~TEST11() {

    }


# hello-jni.h
#include 
#include 
#include 

#ifdef COMPLIANCE_CPP98
#include 
#else
#include 
#endif

#ifdef COMPLIANCE_CPP98
using namespace std::tr1;
#endif
using namespace std;

void printx();

class TEST11
{
public:
    TEST11(std::string name);
    ~TEST11();

    shared_ptr _name;
};

在 jni 统计目录执行:

ndk-build

静态库在目录 obj/local/

-完-

你可能感兴趣的:(NDK 原生库(新手入门))