Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow appcompat version to be configurable #1208

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/templates/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports.prepare = function (cordovaProject, options) {
const targetSdkVersion = this._config.getPreference('android-targetSdkVersion', 'android');
const isGradlePluginKotlinEnabled = this._config.getPreference('GradlePluginKotlinEnabled', 'android');
const gradlePluginKotlinCodeStyle = this._config.getPreference('GradlePluginKotlinCodeStyle', 'android');
const androidXAppCompatVersion = this._config.getPreference('AndroidXAppCompatVersion', 'android');

const gradlePropertiesUserConfig = {};
if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion;
Expand All @@ -71,6 +72,10 @@ module.exports.prepare = function (cordovaProject, options) {
gradlePropertiesUserConfig['kotlin.code.style'] = gradlePluginKotlinCodeStyle || 'official';
}

if (androidXAppCompatVersion) {
gradlePropertiesUserConfig.cdvAndroidXAppCompatVersion = androidXAppCompatVersion;
}

const gradlePropertiesParser = new GradlePropertiesParser(this.locations.root);
gradlePropertiesParser.configure(gradlePropertiesUserConfig);

Expand Down
10 changes: 9 additions & 1 deletion bin/templates/project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ ext {
cdvBuildArch = null
}

// Sets the default cdvAndroidXAppCompatVersion to the given value.
if (!project.hasProperty('cdvAndroidXAppCompatVersion')) {
cdvAndroidXAppCompatVersion = null
}

// Plugin gradle extensions can append to this to have code run at the end.
cdvPluginPostBuildExtras = []
}
Expand Down Expand Up @@ -185,6 +190,8 @@ ext.cdvTargetSdkVersion = cdvTargetSdkVersion == null ? defaultTargetSdkVersion

ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)

ext.cdvAndroidXAppCompatVersion = cdvAndroidXAppCompatVersion == null ? defaultAndroidXAppCompatVersion : cdvAndroidXAppCompatVersion

def computeBuildTargetName(debugBuild) {
def ret = 'assemble'
if (cdvBuildMultipleApks && cdvBuildArch) {
Expand Down Expand Up @@ -219,6 +226,7 @@ task cdvPrintProps {
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
println('cdvBuildArch=' + cdvBuildArch)
println('computedVersionCode=' + android.defaultConfig.versionCode)
println('cdvAndroidXAppCompatVersion=' + cdvAndroidXAppCompatVersion)
android.productFlavors.each { flavor ->
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
}
Expand Down Expand Up @@ -339,7 +347,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.appcompat:appcompat:$cdvAndroidXAppCompatVersion"

if (cdvHelpers.getConfigPreference('GradlePluginKotlinEnabled', 'false').toBoolean()) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
1 change: 1 addition & 0 deletions bin/templates/project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ allprojects {
defaultMinSdkVersion=22 //Integer - Minimum requirement is Android 5.1
defaultTargetSdkVersion=30 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=30 //Integer - We ALWAYS compile with the latest by default
defaultAndroidXAppCompatVersion="1.2.0" //String - We ALWAYS compile with the latest stable by default
}
}

Expand Down
9 changes: 8 additions & 1 deletion framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ ext {
} else {
cdvMinSdkVersion = 22; // current Cordova's default
}

if (project.hasProperty('cdvAndroidXAppCompatVersion')) {
cdvAndroidXAppCompatVersion = cdvAndroidXAppCompatVersion
println '[Cordova] cdvAndroidXAppCompatVersion is overridden, try it at your own risk.'
} else {
cdvAndroidXAppCompatVersion = "1.2.0"; // current Cordova's default
}
}

buildscript {
Expand Down Expand Up @@ -123,7 +130,7 @@ task sourcesJar(type: Jar) {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.appcompat:appcompat:$cdvAndroidXAppCompatVersion"
}

artifacts {
Expand Down