mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-23 00:00:09 +08:00
feat!: unify & fix gradle library/tooling overrides (#1212)
* enhancement: Control SDK versions and other default projects in one place * fix: target/compile sdk usage * refactor: cleanup gradle process * chore: cleanup and remove unused changes * chore: remove more unneeded FILE_PATH * chore: fix lint error * revert change intended to be part of a different PR * chore: apply changes to revert to fit new changes * fix: Ensure proper types * breaking: Removed TempateFile class * Replaced the one and only usage of it with the properties-parser editor. * Breaking change because we are converting a method into an asynchronous method. * refactor: Use the sync version of properties editor * Gh 1178 fix sdk use gradlearg fix (#2) * fix: readd gradleArg support * fix: variable name * refactor: remove unused mock variables * Update bin/templates/cordova/lib/builders/ProjectBuilder.js * Update bin/lib/create.js * fix: const naming (review suggestion) * fix: use defaults for framework building * chore: apply review suggestion * chore: rename config.json & defaults.json (review suggestions) * refactor: updateUserProjectGradleConfig method * refactor: minor changes in updateUserProjectGradleConfig * refactor: major changes in updateUserProjectGradleConfig * fix: wrong handling of missing preferences * fix: usage of undefined this * fix(create.spec): mocking of getPreference * test(check_reqs): reduce diff size * refactor: add wrapper to load gradle config defaults * fix(check_reqs): get_target * Reads default SDK from default gradle config now * fix(check_reqs.spec): return correct types from mocks * revert to using get_target in create * fix: e2e test Co-authored-by: Erisu <ellis.bryan@gmail.com> Co-authored-by: Raphael von der Grün <raphinesse@gmail.com>
This commit is contained in:
+7
-20
@@ -18,30 +18,17 @@
|
||||
|
||||
ext {
|
||||
apply from: 'cordova.gradle'
|
||||
cdvCompileSdkVersion = privateHelpers.getProjectTarget()
|
||||
cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
|
||||
if (project.hasProperty('cdvMinSdkVersion') && cdvMinSdkVersion.isInteger()) {
|
||||
cdvMinSdkVersion = cdvMinSdkVersion as int
|
||||
println '[Cordova] cdvMinSdkVersion is overridden, try it at your own risk.'
|
||||
} 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 {
|
||||
apply from: 'cordova.gradle'
|
||||
apply from: 'repositories.gradle'
|
||||
|
||||
repositories repos
|
||||
|
||||
dependencies {
|
||||
// Android Gradle Plugin (AGP) Build Tools
|
||||
classpath 'com.android.tools.build:gradle:4.2.1'
|
||||
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
|
||||
|
||||
// @todo remove this abandoned plugin. maven-publish-plugin is now supported by Android Gradle plugin 3.6.0 and higher
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
|
||||
@@ -62,8 +49,8 @@ group = 'org.apache.cordova'
|
||||
version = '10.0.0-dev'
|
||||
|
||||
android {
|
||||
compileSdkVersion cdvCompileSdkVersion
|
||||
buildToolsVersion cdvBuildToolsVersion
|
||||
compileSdkVersion cordovaConfig.SDK_VERSION
|
||||
buildToolsVersion cordovaConfig.BUILD_TOOLS_VERSION
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
@@ -72,7 +59,7 @@ android {
|
||||
|
||||
// For the Android Cordova Lib, we allow changing the minSdkVersion, but it is at the users own risk
|
||||
defaultConfig {
|
||||
minSdkVersion cdvMinSdkVersion
|
||||
minSdkVersion cordovaConfig.MIN_SDK_VERSION
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -132,7 +119,7 @@ task sourcesJar(type: Jar) {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "androidx.appcompat:appcompat:$cdvAndroidXAppCompatVersion"
|
||||
implementation "androidx.appcompat:appcompat:${cordovaConfig.ANDROIDX_APP_COMPAT_VERSION}"
|
||||
}
|
||||
|
||||
artifacts {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"MIN_SDK_VERSION": 22,
|
||||
"SDK_VERSION": 30,
|
||||
"GRADLE_VERSION": "6.8.3",
|
||||
"BUILD_TOOLS_VERSION": "30.0.3",
|
||||
"AGP_VERSION": "4.2.1",
|
||||
"KOTLIN_VERSION": "1.4.32",
|
||||
"ANDROIDX_APP_COMPAT_VERSION": "1.2.0",
|
||||
"GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION": "4.3.5",
|
||||
"IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": false,
|
||||
"IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
import java.util.regex.Pattern
|
||||
import groovy.swing.SwingBuilder
|
||||
import io.github.g00fy2.versioncompare.Version
|
||||
|
||||
String doEnsureValueExists(filePath, props, key) {
|
||||
@@ -151,12 +150,57 @@ def doGetConfigPreference(name, defaultValue) {
|
||||
return ret
|
||||
}
|
||||
|
||||
def doApplyCordovaConfigCustomization() {
|
||||
// Apply user overide properties that comes from the "--gradleArg=-P" parameters
|
||||
if (project.hasProperty('cdvMinSdkVersion')) {
|
||||
cordovaConfig.MIN_SDK_VERSION = Integer.parseInt('' + cdvMinSdkVersion)
|
||||
}
|
||||
if (project.hasProperty('cdvSdkVersion')) {
|
||||
cordovaConfig.SDK_VERSION = Integer.parseInt('' + cdvSdkVersion)
|
||||
}
|
||||
if (project.hasProperty('cdvMaxSdkVersion')) {
|
||||
cordovaConfig.MAX_SDK_VERSION = Integer.parseInt('' + cdvMaxSdkVersion)
|
||||
}
|
||||
if (project.hasProperty('cdvBuildToolsVersion')) {
|
||||
cordovaConfig.BUILD_TOOLS_VERSION = cdvBuildToolsVersion
|
||||
}
|
||||
if (project.hasProperty('cdvAndroidXAppCompatVersion')) {
|
||||
cordovaConfig.ANDROIDX_APP_COMPAT_VERSION = cdvAndroidXAppCompatVersion
|
||||
}
|
||||
|
||||
// Ensure the latest installed build tools is selected, with or without defined override
|
||||
cordovaConfig.LATEST_INSTALLED_BUILD_TOOLS = doFindLatestInstalledBuildTools(
|
||||
cordovaConfig.BUILD_TOOLS_VERSION
|
||||
)
|
||||
}
|
||||
|
||||
// Properties exported here are visible to all plugins.
|
||||
ext {
|
||||
def defaultsFilePath = './cdv-gradle-config-defaults.json'
|
||||
def projectConfigFilePath = "$rootDir/cdv-gradle-config.json"
|
||||
def targetConfigFilePath = null
|
||||
|
||||
/**
|
||||
* Check if the project config file path exists. This file will exist if coming from CLI project.
|
||||
* If this file does not exist, falls back onto the default file.
|
||||
* This scenario can occur if building the framework's AAR package for publishing.
|
||||
*/
|
||||
if(file(projectConfigFilePath).exists()) {
|
||||
targetConfigFilePath = projectConfigFilePath
|
||||
} else {
|
||||
targetConfigFilePath = defaultsFilePath
|
||||
}
|
||||
|
||||
def jsonFile = new File(targetConfigFilePath)
|
||||
cordovaConfig = new groovy.json.JsonSlurper().parseText(jsonFile.text)
|
||||
|
||||
// Apply Gradle Properties
|
||||
doApplyCordovaConfigCustomization()
|
||||
|
||||
// These helpers are shared, but are not guaranteed to be stable / unchanged.
|
||||
privateHelpers = {}
|
||||
privateHelpers.getProjectTarget = { doGetProjectTarget() }
|
||||
privateHelpers.findLatestInstalledBuildTools = { doFindLatestInstalledBuildTools('19.1.0') }
|
||||
privateHelpers.applyCordovaConfigCustomization = { doApplyCordovaConfigCustomization() }
|
||||
privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }
|
||||
privateHelpers.extractStringFromManifest = { name -> doExtractStringFromManifest(name) }
|
||||
privateHelpers.ensureValueExists = { filePath, props, key -> doEnsureValueExists(filePath, props, key) }
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Indicates whether an apk should be generated for each density.
|
||||
split.density=false
|
||||
# Project target.
|
||||
target=android-14
|
||||
apk-configurations=
|
||||
@@ -3,4 +3,3 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# GENERATED FILE! DO NOT EDIT!
|
||||
|
||||
# This file was originally created by the Android Tools, but is now
|
||||
# used by cordova-android to manage the project configuration.
|
||||
|
||||
@@ -5,7 +7,6 @@
|
||||
split.density=false
|
||||
|
||||
# Project target.
|
||||
target=android-30
|
||||
apk-configurations=
|
||||
renderscript.opt.level=O0
|
||||
android.library=true
|
||||
|
||||
Reference in New Issue
Block a user