Android Studio JNI开发C/C++使用__android_log_print输出Log

by Netfairy - 2017-03-01

build.gradle:

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ndk {
                moduleName "test"
                ldLibs "log"//实现__android_log_print
                abiFilters "armeabi", "armeabi-v7a", "x86"
            }
        }
    }

test.c:

#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <android/log.h>
#include <string.h>

#define  LOG_TAG    "netfairy-log"
#define  log(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define  log(...)  __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define  log(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

...
...
...
log("88888888");
...
...
...