不能用Android Studio打印JNI的日志信息

 2023-01-20    270  

问题描述

错误我得到:

错误:未定义的引用’__android_log_print’

不能用Android Studio打印JNI的日志信息

我已经将此行添加到我的.cpp文件:

#include <android/log.h>

我已经尝试了两者: __ android_log_print 和 __ android_log_write

我还在我的android.mk文件(我正在手动编译)中链接了登录库.

local_ldlibs:= -llog

我还尝试了一些我发现的替代方法:

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog

这是我的android.mk:

LOCAL_PATH := $(call my-dir)

#used to skip re-compiling libraw
#include $(CLEAR_VARS)
#LOCAL_MODULE    := libraw_r
#LOCAL_SRC_FILES := ../obj/local/armeabi/libraw_r.so
#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libraw
#include $(PREBUILT_SHARED_LIBRARY)

#used for compiling libraw
include $(CLEAR_VARS)
LOCAL_CFLAGS += -I$(SYSROOT)/usr/lib/include/libraw -pthread -w
LOCAL_CXXFLAGS += -I$(SYSROOT)/usr/lib/include/libraw -pthread -w
LOCAL_MODULE     := libraw_r                    # name of your module
LOCAL_LDLIBS     += -L$(SYSROOT)/usr/lib -lstdc++ # libraries to link against, lstdc++ is auto-linked

LOCAL_SRC_FILES  :=  internal/dcraw_common.cpp internal/dcraw_fileio.cpp internal/demosaic_packs.cpp src/libraw_cxx.cpp src/libraw_c_api.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libraw
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := armapi
LOCAL_SRC_FILES := armapi.cpp
LOCAL_SHARED_LIBRARIES := libraw_r
include $(BUILD_SHARED_LIBRARY)

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog

这是build.gradle文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        ndk {
            moduleName "armapi"
            ldLibs "log"
        }
    }

    sourceSets {

        main {
            manifest.srcFile 'AndroidManifest.xml'

            jniLibs.srcDir 'libs' // use the jni .so compiled from the manual ndk-build command
            jni.srcDirs = [] //disable automatic ndk-build call

            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']


        }


        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')


    }

}

推荐答案

似乎使用gradle + android Studio android.mk 文件被忽略.

如说明在这里,尝试将以下指令添加到您的build.gradle:

android {
    defaultConfig {
        ndk {
            moduleName "modulename"
            ldLibs "log"
        }
    }
}

其他推荐答案

在您的android.mk文件中添加此

local_ldlibs:= -llog -ljnigraphics

其他推荐答案

我将Gradle 2.5与Android Studio 1.4.1一起使用,并且使用此语法对我有用:

ldLibs += "log"

模型build.gradle应该是类似的东西:


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

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

            defaultConfig.with {
                applicationId = "com.local.some.project"
                minSdkVersion.apiLevel = 17
                targetSdkVersion.apiLevel = 23
                versionCode = 1
                versionName = "1.0"
            }
        }

        android.buildTypes {
            release {
                minifyEnabled = false
                proguardFiles += file('proguard-rules.pro')
            }
        }

        android.ndk {
            moduleName = "MyModel"
            ldLibs += "log"
        }

        compileOptions.with {
            sourceCompatibility = JavaVersion.VERSION_1_7
            targetCompatibility = JavaVersion.VERSION_1_7
        }
    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile files('libs/some3rdParty.jar')
    }
    

以上所述是小编给大家介绍的不能用Android Studio打印JNI的日志信息,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/26195.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。