18

I am sure this is pretty easy qoestion, but I am stuck with building Android app using Ant from commandline. I have got this message: (use -source 7 or higher to enable diamond operator). What do I add to buildfile to make it compile using Java 1.7?

Heisenberg
  • 3,113
  • 3
  • 26
  • 52

4 Answers4

26

You need to set java.source and java.target. Either via -D:

ant release -Djava.source=7 -Djava.target=7

Or put it in ant.properties in your project:

# ant.properies contents:
java.source=7
java.target=7
rzymek
  • 8,644
  • 2
  • 43
  • 56
  • 1
    YES! edit ant.properties to get rid of this nightmare of a timethief bug. Other advices in this thread did not work here. Thanks! – carl Jan 26 '15 at 16:36
17

Solved it if anyone else is stuck on this one. I had to change <import file="${sdk.dir}/tools/ant/build.xml"/> file. There are properties <property name="java.target" value="1.5" /> <property name="java.source" value="1.5" /> and the values should be changed to 1.7

Heisenberg
  • 3,113
  • 3
  • 26
  • 52
6

Heisenberg's solution is correct (kudos and +1...) but not clean: you don't have to change the master build.xml file (bad!), what you need is to add the lines he suggested:

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

right before the line

<import file="${sdk.dir}/tools/ant/build.xml" />

in the local build.xml file, and the default options will be overridden.

Hope it helps!

Rick77
  • 3,083
  • 24
  • 40
  • Did not help for my Android project in Netbeans on Win 8.1 (I tried to restart machine). However, when I follow rzymek advice and change ant.properties, then everything is ok. – carl Jan 26 '15 at 16:32
0

Just to clarify, I changed my ant.properties as follows:

java.target=1.7
java.source=1.7

Making changes in build.xml before the above suggested line didn't work for me for some reason.

SparkyNZ
  • 5,784
  • 6
  • 37
  • 71