Mac bajo la instalación y uso de AndroidStduio NDK

1 y montado cmake ndk

Aquí Insertar imagen Descripción
CMAKE instalar plug-ins:
Aquí Insertar imagen Descripción

2 nuevos proyectos

Seleccione Native C ++
Aquí Insertar imagen Descripción
introdujo en el directorio del proyecto NDK
Aquí Insertar imagen Descripción

ndk.dir=/xx/xx/Library/Android/sdk/ndk/21.0.6113669

3 función de registro de impresión

NDK uso dentro de la biblioteca de registro de impresión -> liblog.so
Aquí Insertar imagen Descripción

// 使用NDK里面的日志库来打印  liblog.so
#include <android/log.h>

#define TAG "Hongx"

#define LOGD(...)__android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)

Aquí Insertar imagen Descripción

file(GLOB sourceFiles logCpp/*.h logCpp/*.cpp logCpp/*.c)

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        native-lib.cpp

        ${sourceFiles}

        )

Aquí Insertar imagen Descripción

#include "logCpp/hxlog.h"

extern "C" JNIEXPORT jstring JNICALL
Java_com_hongx_ndk2_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";

//     LOGD("AAAAAAAAAAAAAAAAAAA");
     LOGD("BBBBBBBBBBBBBBBBBBB");

    return env->NewStringUTF(hello.c_str());
}

Después de la operación, el registro de impresión:Aquí Insertar imagen Descripción

Publicados 446 artículos originales · ganado elogios 67 · vistas 240 000 +

Supongo que te gusta

Origin blog.csdn.net/hongxue8888/article/details/105038876
Recomendado
Clasificación