c语言 - 错误:"Android log was not declared in this scope"



我试图加载一个旧的c项目(android 5.1, API 22)在android studio 2.2。源代码包括使用android记录器。当我在工作室创建项目时。studio报告一些错误:

Error:(34, 21) error: '__android_log' was not declared in this scope
Information:(84, 5) in expansion of macro 'LOGD'
Warning:(35, 79) warning: format '%s' expects argument of type 'char*', but argument 10 has type 'void*' [-Wformat=]
Information:(91, 9) in expansion of macro 'LOGI'
Error:(34, 35) error: expected ';' before '_print'
Information:(102, 5) in expansion of macro 'LOGD'
Error:(34, 21) error: '__android_log' was not declared in this scope
Information:(107, 5) in expansion of macro 'LOGD'
...

我尝试将日志库添加到Gradle脚本

productFlavors {
    fat {
        dimension "abi"
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86"
            versionCode = 0;
            ldLibs.addAll(["log"]) // <- not working
        }
        minSdkVersion 21
        targetSdkVersion 22
    }
    armv7a {
        dimension "abi"
        ndk {
            abiFilter "armeabi"
            versionCode = 1;
            ldLibs "log" // <- not working neither
        }
        minSdkVersion 21
        targetSdkVersion 22
    }
}

但是工作室报告错误:Error:(71, 0) Could not get unknown property 'ldLibs' for ProductFlavor_Decorated

谁知道如何在android studio 2.2中添加日志库?

谢谢。

这可能是因为NDK中实际上没有android-22。Android 5.1没有任何新的本地api,所以NDK没有这个目录。尝试将targetSdkVersion设置为21?

真正重要的是要注意:当使用NDK时,你的目标API级别是你的最低API级别。我相信Gradle并没有强制执行这一点,但是本机代码很可能无法在低于目标API级别的设备上运行。

相关内容

最新更新