Skip to content

Commit

Permalink
fix: make gradle dependencies use implementation instead of compile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shannah committed Nov 18, 2023
1 parent 9f4729a commit 56959e1
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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";
}
}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand All @@ -3282,7 +3289,7 @@ public void usesClassMethod(String cls, String method) {
}
}
String compile = "compile";
if (useAndroidX) {
if (useAndroidX || useArrImplementation) {
compile = "implementation";
}
if (legacyGplayServicesMode) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 56959e1

Please sign in to comment.