Mac sous l'installation et l'utilisation de AndroidStduio NDK

1 et monté NDK cmake

Insérer ici l'image Description
Cmake installer des plug-ins:
Insérer ici l'image Description

2 nouveaux projets

Sélectionnez C ++ natif
Insérer ici l'image Description
introduit dans le répertoire projet NDK
Insérer ici l'image Description

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

3 Fonction d'impression du journal

NDK utilisation à l' intérieur de la bibliothèque pour imprimer journal -> liblog.so
Insérer ici l'image Description

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

#define TAG "Hongx"

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

Insérer ici l'image Description

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}

        )

Insérer ici l'image Description

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

Après l'opération, le journal d'impression:Insérer ici l'image Description

Publié 446 articles originaux · louange gagné 67 · vues 240 000 +

Je suppose que tu aimes

Origine blog.csdn.net/hongxue8888/article/details/105038876
conseillé
Classement