2011-10-07 40 views
12

所以我幾乎總是得到這樣一些消息時,我編我的Android應用:使用Xlint:棄用了Android

[javac] Note: /home/kurtis/sandbox/udj/androidApp/src/org/klnusbaum/udj/PlaylistFragment.java uses or overrides a deprecated API. 
[javac] Note: Recompile with -Xlint:deprecation for details. 

如何重新編譯使用此選項?我必須在我的build.xml中編輯一些東西嗎?

+2

如果使用Gradle而不是Ant,請參閱http://stackoverflow.com/questions/18689365/how-to-add-xlintunchecked-to-my-android-gradle-based-project – aleb

回答

11

是的,每低於build.xml文件中的聲明,如果您要...

 
     - Customize only one target: 
      - copy/paste the target into this file, *before* the 
       <setup/> task. 
      - customize it to your needs. 

這意味着:

  1. 轉到$ ANDROID_SDK_ROOT /工具/螞蟻/main_rules.xml文件並複製「編譯」目標。

  2. 它的<設置/ >任務之前粘貼到你的build.xml文件

  3. 然後將下面的元素添加到任務:

    <compilerarg value="-Xlint:deprecation"/> 
    
  4. 同樣,你可以添加其他編譯器選項,如選中操作:

    <compilerarg value="-Xlint:unchecked"/> 
    
+0

太棒了。當我回家時,我會試試這個,可能會贊成並接受你的答案。 –

2

它看起來像您應該可以在項目文件夾的根目錄中指定build.propertiesant.properties中的選項。我試過這個,它似乎沒有工作。 我想避免編輯我的build.xml文件,因爲如果您需要更新項目,稍後會增加複雜性。但是,我無法找到解決辦法。然而,而不是複製整個compile目標我又說:

<property name="java.compilerargs" value="-Xlint:unchecked" /> 

只是在文件的底部import前行。

23

這些屬性也可以Ant命令行上定義的,避免了修改:

ant "-Djava.compilerargs=-Xlint:unchecked -Xlint:deprecation" debug

爲了使所有lint警告:

ant -Djava.compilerargs=-Xlint debug

+0

謝謝。優秀的建議。 – Bram

14

更簡單和無需複製完整的javac目標:在ant.properties文件中放入以下行:

java.compilerargs=-Xlint:unchecked 

這樣,它只是從Android SDK默認構建配置中覆蓋java.compilerargs。 (你可以檢查自己,它默認情況下是空的,順便說一句)。沒有與SDK更新混淆,可能會更改默認的javac目標,而不通知您的項目。

只是更細化的方式! :)