2016-10-11 22 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