2016-10-11 24 views
1

我正尝试在Android Studio 2.2中加载一个旧的c项目(用于android 5.1,API 22)。源代码包括使用android记录器。当我在工作室制作这个项目时。该工作室报告一些错误:错误:“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' 
... 

我试图登录库添加到摇篮脚本

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

谢谢。

回答

0

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

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

+0

感谢您的回复丹。我试图将targetSdkVersion更改为21.但仍具有相同的构建错误。我还检查了ndk-bundle/platforms/android-22//lib liblog.so在那里。所以我认为这个问题一定是由于缺少Gradle配置引起的。 – r0ng