Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:() undefined reference to `__android_log_write' ERROR?

I am trying to debug a JNI C function by inserting log messages, but I can't get it to work. I tried everything but i have this error:

Error:(61) undefined reference to `__android_log_write'

at this line : __android_log_write(prio, sTag, buf);

here is my 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)

i have two file .gradle, here is the first one:

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')
}

and here is the 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'
}

I'm using gradle experimental.classpath 'com.android.tools.build:gradle-experimental:0.7.0'

I really search all over internet and i didn't get a good solution, hope I'll find here.. Thanx!

like image 583
Walid Avatar asked Jun 03 '16 15:06

Walid


1 Answers

modify your module gradle file ndk block like this and try :

ndk {
        platformVersion = 21;
        moduleName "engine"
        toolchain = "clang"
        stl = 'gnustl_static'         
        cppFlags.addAll(['-std=c++11', '-Wall', '-D__STDC_INT64__'])
        ldLibs.addAll(['android', 'log'])         
    }
like image 183
Arpan Sarkar Avatar answered Oct 22 '22 07:10

Arpan Sarkar