From 56959e1492e72270422532a95630a4b8aa5f643c Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Sat, 18 Nov 2023 09:42:16 -0800 Subject: [PATCH] fix: make gradle dependencies use implementation instead of compile compile is deprecated in gradle 7+, and users have had to explicitly add the android.arrimplementation build hint for the ZBarScanner library to force it to include via implementation. This change makes implementation the default behaviour when using gradle 6+, but with the ability to override for a particular library using the new android.arrcompile build hint which works the same way as the android.arrimplementation build hint. --- .../builders/AndroidGradleBuilder.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 849a1e3fd5..78bf1903b0 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 @@ -105,6 +105,9 @@ public File getGradleProjectDirectory() { // which is necessary to support Push on the latest Android devices. private boolean newFirebaseMessaging = false; + // A flag to indicate whether we should use 'implementation' or 'compile' for dependencies + private boolean useArrImplementation = false; + public static final String[] ANDROID_PERMISSIONS = new String[]{ "android.permission.ACCESS_BACKGROUND_LOCATION", "android.permission.ACCESS_CHECKIN_PROPERTIES", @@ -895,6 +898,7 @@ public boolean build(File sourceZip, final BuildRequest request) throws BuildExc gradlePluginVersion = "3.0.1"; } } else { + useArrImplementation = true; gradlePluginVersion = "4.1.1"; } } @@ -992,8 +996,11 @@ public boolean build(File sourceZip, final BuildRequest request) throws BuildExc } if (file.getName().endsWith(".aar")) { String name = file.getName().substring(0, file.getName().lastIndexOf(".")); - if(request.getArg("android.arrimplementation", "").contains( - name)) { + boolean arrCompileLib = request.getArg("android.arrcompile", "").contains( + name); + boolean arrImplementationLib = request.getArg("android.arrimplementation", "").contains( + name); + if(!arrCompileLib && (useArrImplementation || arrImplementationLib)) { aarDependencies += " implementation(name:'" + name + "', ext:'aar')\n"; } else { aarDependencies += " compile(name:'" + name + "', ext:'aar')\n"; @@ -1275,7 +1282,7 @@ public void usesClassMethod(String cls, String method) { if (useFCM) { String compile = "compile"; - if (useAndroidX) { + if (useAndroidX || useArrImplementation) { compile = "implementation"; } if (!googleServicesJson.exists()) { @@ -3266,7 +3273,7 @@ public void usesClassMethod(String cls, String method) { String additionalDependencies = request.getArg("gradleDependencies", ""); if (facebookSupported) { String compile = "compile"; - if (useAndroidX) { + if (useAndroidX || useArrImplementation) { compile = "implementation"; } minSDK = maxInt("15", minSDK); @@ -3282,7 +3289,7 @@ public void usesClassMethod(String cls, String method) { } } String compile = "compile"; - if (useAndroidX) { + if (useAndroidX || useArrImplementation) { compile = "implementation"; } if (legacyGplayServicesMode) { @@ -3442,7 +3449,7 @@ public void usesClassMethod(String cls, String method) { } } - String supportV4Default = " compile 'com.android.support:support-v4:23.+'"; + String supportV4Default; compileSdkVersion = maxPlatformVersion; String supportLibVersion = maxPlatformVersion; @@ -3483,7 +3490,7 @@ public void usesClassMethod(String cls, String method) { gradlePropertiesObject.put("android.enableAapt2", "false"); } if (!useAndroidX) { - supportV4Default = " compile 'com.android.support:support-v4:"+supportLibVersion+".+'\n implementation 'com.android.support:appcompat-v7:"+supportLibVersion+".+'\n"; + supportV4Default = " " + compile + " 'com.android.support:support-v4:"+supportLibVersion+".+'\n implementation 'com.android.support:appcompat-v7:"+supportLibVersion+".+'\n"; } else { String appCompatVersionDefault = "1.0.0"; if (useGradle8) {