android.mk
LOCAL_PATH := $(call my-dir) APP_ABI := armeabi include $(CLEAR_VARS) LOCAL_LDLIBS :=-llog LOCAL_MODULE := libjxnative LOCAL_SRC_FILES := jxnative.c include $(BUILD_SHARED_LIBRARY)
jxnative.c #include <jni.h> #include <android/log.h> //com.modern.taxiterminal.terminal #define TAG "jxnative-jni" // 这个是自定义的LOG的标识 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,TAG ,__VA_ARGS__) // 定义LOGD类型 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,TAG ,__VA_ARGS__) // 定义LOGI类型 #define LOGW(...) __android_log_print(ANDROID_LOG_WARN,TAG ,__VA_ARGS__) // 定义LOGW类型 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,TAG ,__VA_ARGS__) // 定义LOGE类型 #define LOGF(...) __android_log_print(ANDROID_LOG_FATAL,TAG ,__VA_ARGS__) // 定义LOGF类型 JNIEXPORT void JNICALL Java_com_jni_ght_ccalljava_ac01_nativeSetup (JNIEnv *env, jobject thiz) { LOGE("success baby\n"); }
///build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "31.0.0" defaultConfig { applicationId "com.jni.ght.ccalljava" minSdkVersion 23 targetSdkVersion 23 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main { jniLibs.srcDirs = ['libs']//指明在JNI } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' }