diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/AndroidGradleBuilder.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/AndroidGradleBuilder.java index 087f759bb9..c6523b425d 100644 --- a/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/AndroidGradleBuilder.java +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/AndroidGradleBuilder.java @@ -436,8 +436,19 @@ private String getGradleVersion(String gradleExe) throws Exception { private String getGradleJavaHome() throws BuildException { if (useGradle8) { String home = System.getenv("JAVA17_HOME"); + if (home == null && (home = getLocalBuilderProperties().getProperty("java17.home", null)) != null) { + if (!(new File(home)).isDirectory()) { + throw new BuildException("The java17.home property is not set to a valid directory. " + + "You have defined it in your ~/.codenameone/local.properties file, " + + "but it is not a valid directory." + ); + } + } if (home == null) { - throw new BuildException("When using gradle 8, you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK"); + throw new BuildException( + "When using gradle 8, " + + "you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK" + ); } if (!(new File(home).isDirectory())) { @@ -448,7 +459,6 @@ private String getGradleJavaHome() throws BuildException { } return System.getProperty("java.home"); } - private int parseVersionStringAsInt(String versionString) { if (versionString.indexOf(".") > 0) { try { @@ -3528,6 +3538,10 @@ public void usesClassMethod(String cls, String method) { compileSdkVersion = "33"; supportLibVersion = "28"; } + if (buildToolsVersion.startsWith("34")) { + compileSdkVersion = "34"; + supportLibVersion = "28"; + } jcenter = " google()\n" + " jcenter()\n" + diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/Executor.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/Executor.java index 39f9a210f8..7f821e127f 100644 --- a/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/Executor.java +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/Executor.java @@ -99,7 +99,7 @@ public abstract class Executor { static boolean IS_MAC; protected final Map defaultEnvironment = new HashMap(); - + private Properties localBuilderProperties; protected File codenameOneJar; @@ -2077,9 +2077,6 @@ public String xorEncode(String s) { } } - - - private ClassLoader getCodenameOneJarClassLoader() throws IOException { if (codenameOneJar == null) { throw new IllegalStateException("Must set codenameOneJar in Executor"); @@ -2087,5 +2084,35 @@ private ClassLoader getCodenameOneJarClassLoader() throws IOException { return new URLClassLoader(new URL[]{codenameOneJar.toURI().toURL()}); } + /** + * Loads global local builder properties from user's home directory. + * @return + * @throws IOException + */ + protected Properties getLocalBuilderProperties() { + if (localBuilderProperties == null) { + String sep = File.separator; + File propertiesFile = new File( + System.getProperty("user.home") + sep + ".codenameone" + sep + "local.properties" + ); + localBuilderProperties = new Properties(); + if (!propertiesFile.exists()) { + return localBuilderProperties; + } + try { + FileInputStream fis = new FileInputStream(propertiesFile); + try { + localBuilderProperties.load(fis); + } finally { + fis.close(); + } + } catch (IOException ex) { + throw new RuntimeException("Failed to load local properties", ex); + } + } + + return localBuilderProperties; + + } }