【问题标题】:Error: "Android log was not declared in this scope"错误:“Android 日志未在此范围内声明”
【发布时间】:2017-02-20 15:44:02
【问题描述】:

我正在尝试在 Android Studio 2.2 中加载旧的 c 项目(适用于 android 5.1,API 22)。源代码包括使用 android 记录器。当我在工作室构建项目时。工作室报一些错误:

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 中添加日志库吗?

谢谢。

【问题讨论】:

    标签: c android-studio android-ndk android-gradle-plugin


    【解决方案1】:

    这可能是因为 NDK 中实际上没有 android-22。 Android 5.1 没有任何新的原生 API,因此 NDK 没有该目录。尝试将targetSdkVersion 设置为 21?

    真正需要注意的是:使用 NDK 时,您的目标 API 级别是您的最低 API 级别。我相信 Gradle 不会强制执行此操作,但本机代码很可能不会在目标 API 级别以下的设备上运行。

    【讨论】:

    • 感谢您的回复丹。我尝试将 targetSdkVersion 更改为 21。但仍然有相同的构建错误。我还检查了 ndk-bundle/platforms/android-22//lib liblog.so 在那里。所以我认为这个问题一定是由于 Gradle 配置的缺失造成的。
    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 2015-06-23
    • 2010-10-02
    相关资源
    最近更新 更多