source value 1.5 is obsolete and will be removed in a future release

前端 未结 3 636
南方客
南方客 2021-02-12 11:39

How do I prevent the two warnings below from generating an error that stops the build process ?

-compile:
    [javac] Compiling 77 source files to /Users/andev/W         


        
相关标签:
3条回答
  • 2021-02-12 12:07

    To be able to build, I created a file ant.properties in the facebook project (first project that is compiled) with the contents :

    java.compilerargs=-Xlint:-options
    
    0 讨论(0)
  • 2021-02-12 12:09

    Another possibility (which will fix it for all Android builds made with Ant), is to tweak the default parameters for the -compile task in <android-sdk>\tools\ant\build.xml.

    At the <!-- compilation options --> section, you can either set the compiler flags:

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

    or, alternatively, change the source and target parameters:

    <property name="java.target" value="1.6" />
    <property name="java.source" value="1.6" />
    

    As of now, 1.6 is enough to avoid the warning.

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

    This is set in the ${sdk.dir}/tools/ant/build.xml file. At the beginning of the file are many property settings, e.g.

    <!-- compilation options -->
    <property name="java.encoding" value="UTF-8" />
    <property name="java.target" value="1.5" />
    <property name="java.source" value="1.5" />
    <property name="java.compilerargs" value="" />
    <property name="java.compiler.classpath" value="" />
    

    Also at the beginning of this file is a comment

    At the beginning of the file is a list of properties that can be overridden
    by adding them to your ant.properties (properties are immutable, so their
    first definition sticks and is never changed).
    

    So, in order to override any property in general and source value and target value in particular, you can put these properties into the ant.properties file in your project directory

    java.source=1.6
    java.target=1.6
    

    This overrides the default settings in ${sdk.dir}/tools/ant/build.xml and thus prevents the warnings.

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