2013-02-08 78 views
5

我正在開發一個android應用程序,並且擔心我們引入的代碼使用的API級別比其minSdkVersion晚。自動檢查是否違反了android:minSdkVersion

我想知道是否有任何方法來自動檢測這些違規行爲。

在這個應用程序的AndroidManifest.xml文件,它規定:

<uses-sdk android:minSdkVersion="8" 
      android:targetSdkVersion="17" /> 

NDK,版本是似乎是給我這個警告(或者是該警告的另一個原因是?):

Android NDK: Found stable platform levels: 14 3 4 5 8 9 
Android NDK: Found max platform level: 14 
Android NDK: Parsing ./jni/Application.mk 
Android NDK: Found APP_PLATFORM=android-17 in ./project.properties 
Android NDK: Adjusting APP_PLATFORM android-17 to android-14 and enabling -fPIE 
/android-ndk/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml  

雖然我知道任何工具不可能是100%準確的,由於運行時的調度,除了:

  • 全AU的運行的minSdkVersion一個設備上的所有的代碼路徑一個完整的測試(在這種情況下機器人-8 = 2.2 = Froyo的)的源代碼的DIT,或

...有棉絨狀工具,構建設置更改還是其他任何可用於識別至少最明顯/明顯違規的內容?

如果沒有這樣的事情存在,是否有一個全面的API列表或將使審計更容易?

+0

,我想我也許可以設定目標回'Android的8'和它可能會產生編譯器警告或錯誤的不可用的功能,但似乎並沒有工作 - 「android list targets」不顯示8可用,儘管它似乎被標記爲安裝在「android」下。我可能會很快考慮在某個時間點尋找並安裝較早版本的SDK和NDK,但認爲在此期間值得諮詢stackoverflow人羣的智慧。 – leander 2013-02-08 23:03:11

+1

大部分的關注點都放在了SDK上 - Lint會告訴你關於你使用的東西比你的'minSdkVersion'更新的情況。不過,NDK目前可能缺乏這種東西。 – CommonsWare 2013-02-08 23:05:51

+0

我剛剛發現'[javac]注意:用-Xlint重新編譯:deprecation for details.'這可能是我需要的... – leander 2013-02-08 23:07:05

回答

4

它看起來像Android的lint工具做一些檢查(感謝@CommonsWare在評論以上):

$ which lint 
/android-sdk-macosx/tools/lint 

$ lint myProjectDir --check NewApi 

Scanning .: ..... 

No issues found. 

看樣子你也可以爲ant lint的SDK工具修訂的運行這個21

林特有各種不錯的輸出格式,看起來!集成通過--xml詹金斯等..


此外,在ant.properties,你可以設置這樣的事情有由javac進行一些lint檢查:

java.compilerargs=-Xlint:all 

目前還不清楚是否javac報告類似lint的事件 - 檢查NewApi,但至少報告[deprecation]條目。 (如果您找到了有關javac報告的參考資料,請發表評論。)


對於後人,這裏是lint的NewApi檢查的描述:

$ lint --show NewApi 
NewApi 
------ 
Summary: Finds API accesses to APIs that are not supported in all targeted API 
versions 

Priority: 6/10 
Severity: Error 
Category: Correctness 

This check scans through all the Android API calls in the application and 
warns about any calls that are not available on all versions targeted by this 
application (according to its minimum SDK attribute in the manifest). 

If you really want to use this API and don't need to support older devices 
just set the minSdkVersion in your AndroidManifest.xml file. 
If your code is deliberately accessing newer APIs, and you have ensured (e.g. 
with conditional execution) that this code will only ever be called on a 
supported platform, then you can annotate your class or method with the 
@TargetApi annotation specifying the local minimum SDK to apply, such as 
@TargetApi(11), such that this check considers 11 rather than your manifest 
file's minimum SDK as the required API level. 

,這裏是一些有用的鏈接關於lint

2

我發現最簡單的解決方法是 此行添加到文件Application.mk

覆蓋APP_MIN_PLATFORM_LEVEL = 99