错误:()未定义引用`__android_log_write’ERROR?

我试图通过插入日志消息来调试JNI C函数,但我无法让它工作.我尝试了一切,但我有这个错误:

Error:(61) undefined reference to `__android_log_write'

在这一行:__ android_log_write(prio,sTag,buf);

这是我的android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE    := engine
LOCAL_SRC_FILES := engine.c common.c effiindexb.c alertsmanager.c
LOCAL_CFLAGS += -std=c99
#APP_CFLAGS += -std=c99
LOCAL_LDLIBS :=  -llog
include $(BUILD_SHARED_LIBRARY)

我有两个文件.gradle,这是第一个:

apply plugin: 'com.android.model.application'

model {
android {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.2"

    defaultConfig {
        applicationId = "com.effidriver"
        minSdkVersion.apiLevel = 16
        targetSdkVersion.apiLevel = 23

    }
    ndk {
        moduleName "engine"
        toolchain = 'clang'
        CFlags.addAll(['-Wall'])
    }

    buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-rules.txt'))
        }
    }

    productFlavors {

        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
   }
   }

dependencies {
compile project(':library')
compile 'com.android.support:support-v4:23.3.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/TestFlightLib.jar')
compile project(path: ':library')
compile project(path: ':library')
}

这是seconde .gradle:

apply plugin: 'com.android.model.library'

model {
android {
    compileSdkVersion = 'Google Inc.:Google APIs:17'
    buildToolsVersion = "24.0.0 rc3"

    defaultConfig {
        minSdkVersion.apiLevel = 16
        targetSdkVersion.apiLevel = 23
    }

    buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-rules.txt'))
        }
    }
}
}

dependencies {
   compile 'com.android.support:support-v4:23.0.0'
}

我正在使用gradle experimental.classpath’com.android.tools.build:gradle-experimental:0.7.0′

我真的在互联网上搜索,我没有得到一个很好的解决方案,希望我会在这里找到.. Thanx!

最佳答案 像这样修改你的模块gradle文件ndk块并尝试:

ndk {
        platformVersion = 21;
        moduleName "engine"
        toolchain = "clang"
        stl = 'gnustl_static'         
        cppFlags.addAll(['-std=c++11', '-Wall', '-D__STDC_INT64__'])
        ldLibs.addAll(['android', 'log'])         
    }
点赞