Use Xlint:deprecation with android

后端 未结 5 2332
猫巷女王i
猫巷女王i 2021-02-19 10:57

So I almost always get some message like this when I\'m compiling my android app:

[javac] Note: /home/kurtis/sandbox/udj/androidApp/src/org/klnusbaum/udj/Playlis         


        
相关标签:
5条回答
  • 2021-02-19 11:45

    If you want to have a good CI + CD pipeline and you care about your code quality, a good option to show more information about lint complainings is by adding this to your top/root gradle.build:

    subprojects {
      gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
          options.compilerArgs += [
            '-Xlint:unchecked', // Shows information about unchecked or unsafe operations.
            '-Xlint:deprecation', // Shows information about deprecated members.
          ]
        }
      }
    }
    

    or

    subprojects {
      gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
          options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
      }
    }
    

    If you only want to add one option (you would normally add more), inside the task JavaCompile you just need to add:

    options.compilerArgs << "-Xlint:unchecked"
    

    It's 2018 and you can rely on Gradle to set this up. I only added two compiler argument options but there are much more. You can find more information here and here.

    0 讨论(0)
  • 2021-02-19 11:48

    These properties can also be defined on the Ant command line, avoiding edits:

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

    To enable all Lint warnings:

    ant -Djava.compilerargs=-Xlint debug

    0 讨论(0)
  • 2021-02-19 11:55

    Yes, per the statement below in the build.xml file, if you want to ...

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

    That means:

    1. Go to the $ANDROID_SDK_ROOT/tools/ant/main_rules.xml file and copy the "compile" target.

    2. Paste it into your build.xml file before the <setup/> task.

    3. Then add the following element to the task:

      <compilerarg value="-Xlint:deprecation"/>
      
    4. Likewise, you can add other compiler options, such as for unchecked operations:

      <compilerarg value="-Xlint:unchecked"/>
      
    0 讨论(0)
  • 2021-02-19 11:56

    It looks like you should just be able to specify the option in either build.properties or ant.properties in the root of your project folder. I tried this and it didn't seem to work. I wanted to avoid editing my build.xml file as this adds complication later if you need to update your project. However, I was unable to find a way around it. However, rather than copying the whole compile target I added:

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

    just before the import line at the bottom of the file.

    0 讨论(0)
  • 2021-02-19 12:02

    Even simpler and without the need to copy a complete javac target: put the following line in ant.properties file :

    java.compilerargs=-Xlint:unchecked
    

    This way, it just overrides java.compilerargs from Android SDK default build configuration. (You can check for yourself that it is empty by default, btw). No mess with SDK update that could change the default javac target without your project being notified.

    Just a more granular way to do! :)

    0 讨论(0)
提交回复
热议问题