Skip to content

Commit 5cabcbe

Browse files
jushgithub-actions[bot]
authored andcommitted
Upgrade Gradle and AGP (#4703)
[MAPSAND-1709](https://mapbox.atlassian.net/browse/MAPSAND-1709) Changes in this PR: - The Gradle wrapper is now 8.11.1 - Instead of each project having its Gradle wrapper related files we now use soft links to the `platform/android/gradle*`. Except `maps-android` because it uses the public one (`maps-android/mapbox-maps-android`). - Upgrade AGP to 8.10.1 - Each module package name is now defined in the build Gradle file `namespace` property. - Android target SDK is now 33 for common - Maven publication now uses `android.publishing {..}` to produce the javadocs and source jars. Applicable to gl-native and common (maps-android already did it) - Align the Gradle properties related to JVM configuration. Ideally the `gradle.properties` of each Android project would be linked to a common one (in `<root>/platform/android`) but we can't because each of them needs to define a slightly different `mapbox.mapboxSdkRoot` relative path in it 😞 cc @mapbox/gl-native cc @mapbox/maps-android cc @mapbox/core-sdk cc @mapbox/sdk-ci cc @mapbox/3d-live-navigation [MAPSAND-1709]: https://mapbox.atlassian.net/browse/MAPSAND-1709?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ cc @mapbox/navnative cc @mapbox/search-sdk-native cc @mapbox/nav-core-sdk GitOrigin-RevId: f7c432c98282c3b7d4d05e1d81582da65eb9b541
1 parent ae41621 commit 5cabcbe

File tree

15 files changed

+104
-59
lines changed

15 files changed

+104
-59
lines changed

android-auto-app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
versionName = "0.1.0"
1515
multiDexEnabled = true
1616
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
17-
testInstrumentationRunnerArguments(mapOf("clearPackageData" to "true"))
17+
testInstrumentationRunnerArguments["clearPackageData"] = "true"
1818
}
1919

2020
compileOptions {

app/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ android {
3939
versionName = project.property("TEST_APP_VERSION_NAME") as String
4040
multiDexEnabled = true
4141
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
42-
testInstrumentationRunnerArguments += mapOf("clearPackageData" to "true")
42+
testInstrumentationRunnerArguments["clearPackageData"] = "true"
4343
ndk {
4444
val abi: String =
4545
if (System.getenv("ANDROID_ABI") != null) System.getenv("ANDROID_ABI") else ""
@@ -80,6 +80,7 @@ android {
8080

8181
buildFeatures {
8282
viewBinding = true
83+
buildConfig = true
8384
}
8485

8586
testOptions {

compose-app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
versionName = "0.1.0"
1616
multiDexEnabled = true
1717
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18-
testInstrumentationRunnerArguments(mapOf("clearPackageData" to "true"))
18+
testInstrumentationRunnerArguments["clearPackageData"] = "true"
1919
vectorDrawables {
2020
useSupportLibrary = true
2121
}

extension-style-app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
versionName = "0.1.0"
1616
multiDexEnabled = true
1717
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18-
testInstrumentationRunnerArguments(mapOf("clearPackageData" to "true"))
18+
testInstrumentationRunnerArguments["clearPackageData"] = "true"
1919
}
2020

2121
compileOptions {

gradle.properties

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,30 @@ TEST_APP_VERSION_NAME=0.1.0
99
# any settings specified in this file.
1010
# For more details on how to configure your build environment visit
1111
# http://www.gradle.org/docs/current/userguide/build_environment.html
12+
1213
# Specifies the JVM arguments used for the daemon process.
1314
# The setting is particularly useful for tweaking memory settings.
14-
org.gradle.jvmargs=-Xmx12g -XX:MaxPermSize=1024m -XX:+UseParallelGC
15+
# Ensure important default jvmargs aren't overwritten. See https://github.com/gradle/gradle/issues/19750
16+
#
17+
# For more information about how Gradle memory options were chosen:
18+
# - Metaspace See https://www.jasonpearson.dev/metaspace-in-jvm-builds/
19+
# - SoftRefLRUPolicyMSPerMB would default to 1000 which with a 4gb heap translates to ~51 minutes.
20+
# A value of 1 means ~4 seconds before SoftRefs can be collected, which means its realistic to
21+
# collect them as needed during a build that should take seconds to minutes.
22+
# - CodeCache normally defaults to a very small size. Increasing it from platform defaults of 32-48m
23+
# because of how many classes can be loaded into memory and then cached as native compiled code
24+
# for a small speed boost.
25+
# - Increased stack size (Xss) fixes StackOverFlow during javadoc generation
26+
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=1 -XX:ReservedCodeCacheSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx16g -Xms4g -Xss4m
27+
28+
# For more information about how Kotlin Daemon memory options were chosen:
29+
# - Kotlin JVM args only inherit Xmx, ReservedCodeCache, and MaxMetaspace. Since we are specifying
30+
# other args we need to specify all of them here.
31+
# - We're using the Kotlin Gradle Plugin's default value for ReservedCodeCacheSize, if we do not then
32+
# the Gradle JVM arg value for ReservedCodeCacheSize will be used.
33+
kotlin.daemon.jvmargs=-Dfile.encoding=UTF-8 -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=1 -XX:ReservedCodeCacheSize=320m -XX:+HeapDumpOnOutOfMemoryError -Xmx16g -Xms4g
34+
35+
1536
# When configured, Gradle will run in incubating parallel mode.
1637
# This option should only be used with decoupled projects. More details, visit
1738
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
@@ -20,16 +41,15 @@ org.gradle.jvmargs=-Xmx12g -XX:MaxPermSize=1024m -XX:+UseParallelGC
2041
# Android operating system, and which are packaged with your app's APK
2142
# https://developer.android.com/topic/libraries/support-library/androidx-rn
2243
android.useAndroidX=true
23-
# Automatically convert third-party libraries to use AndroidX
24-
android.enableJetifier=false
2544
# Kotlin code style for this project: "official" or "obsolete":
2645
kotlin.code.style=official
27-
# Work around Jetifier can't handle multi-release jars
28-
# https://github.com/bcgit/bc-java/issues/762
29-
# https://issuetracker.google.com/issues/172784894
30-
# android.jetifier.blacklist=bcprov-jdk15on
31-
android.jetifier.ignorelist=bcprov-jdk15on
3246
# Internal build flag to build from source.
3347
buildFromSource=false
3448
# Disable ksp incremental feature due to ksp bug in https://github.com/google/ksp/issues/1280
35-
ksp.incremental=false
49+
ksp.incremental=false
50+
51+
android.nonTransitiveRClass=false
52+
#android.nonFinalResIds=false
53+
54+
# Enable caching between builds.
55+
org.gradle.caching=true

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ exampleCompileSdkVersion = "34"
1515

1616
# Plugins
1717
pluginJacoco = "0.8.12"
18-
pluginGradle = "7.4.2"
18+
pluginGradle = "8.10.1"
1919
pluginLicense = "0.9.0"
2020
pluginMapboxAccessToken = "0.4.0"
2121
pluginMapboxSdkRegistry = "1.3.3"
2222
pluginMapboxSdkVersions = "1.1.3"
23-
pluginMapboxNdk = "0.1.0"
23+
pluginMapboxNdk = "0.2.0"
2424
pluginTaskTree = "2.1.0"
2525
pluginPlayPublisher = "3.7.0"
2626
pluginGradleVersions = "0.42.0"
@@ -64,7 +64,7 @@ googleCarAppLibrary = "1.2.0"
6464
kotlinCoroutines = "1.6.1"
6565
junit = "4.13.2"
6666
mockk = "1.13.5"
67-
robolectric = "4.9.2"
67+
robolectric = "4.10.3"
6868
robolectricEgl = "gl1.1-android-2.1_r1"
6969
lint = "30.4.2"
7070
hamcrest = "2.1"

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip

mapbox-convention-plugin/build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ gradlePlugin {
4141

4242
kotlin {
4343
explicitApi()
44-
}
45-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
46-
kotlinOptions {
47-
kotlinOptions.allWarningsAsErrors = true
44+
compilerOptions {
45+
allWarningsAsErrors = true
4846
}
4947
}
5048

mapbox-convention-plugin/src/main/kotlin/com/mapbox/maps/gradle/plugins/extensions/MapboxJacocoExtension.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public abstract class MapboxJacocoExtension @Inject constructor(objects: ObjectF
9292

9393
private fun Project.configureJacocoForVariant(variant: Variant) {
9494
val variantName = variant.name
95-
val capitalizedVariant = variantName.capitalize(Locale.ROOT)
95+
val capitalizedVariant = variantName.replaceFirstChar { it.uppercase(Locale.ROOT) }
9696
val testTaskName = "test${capitalizedVariant}UnitTest"
97-
val reportTaskName = "jacoco${testTaskName.capitalize(Locale.ROOT)}Report"
97+
val reportTaskName = "jacoco${testTaskName.replaceFirstChar { it.uppercase(Locale.ROOT) }}Report"
9898

9999
tasks.register<JacocoReport>(reportTaskName) {
100100
dependsOn(testTaskName)
@@ -118,10 +118,10 @@ public abstract class MapboxJacocoExtension @Inject constructor(objects: ObjectF
118118
)
119119
}
120120

121-
val javaClasses = fileTree("$buildDir/intermediates/javac/$variantName") {
121+
val javaClasses = fileTree(layout.buildDirectory.dir("intermediates/javac/$variantName")) {
122122
exclude(this@MapboxJacocoExtension.excludes)
123123
}
124-
val kotlinClasses = fileTree("$buildDir/tmp/kotlin-classes/$variantName") {
124+
val kotlinClasses = fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/$variantName")) {
125125
exclude(this@MapboxJacocoExtension.excludes)
126126
}
127127

@@ -137,7 +137,7 @@ public abstract class MapboxJacocoExtension @Inject constructor(objects: ObjectF
137137
)
138138

139139
executionData.setFrom(
140-
fileTree(buildDir) {
140+
fileTree(layout.buildDirectory) {
141141
include(
142142
"jacoco/$testTaskName.exec",
143143
"outputs/unit_test_code_coverage/${variantName}UnitTest/$testTaskName.exec"

mapbox-convention-plugin/src/main/kotlin/com/mapbox/maps/gradle/plugins/extensions/MapboxLibraryExtension.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.maps.gradle.plugins.extensions
22

3+
import com.android.build.api.variant.LibraryAndroidComponentsExtension
34
import com.android.build.gradle.LibraryExtension
45
import com.mapbox.maps.gradle.plugins.internal.getVersionCatalog
56
import com.mapbox.maps.gradle.plugins.internal.newInstance
@@ -10,6 +11,7 @@ import org.gradle.api.model.ObjectFactory
1011
import org.gradle.api.provider.Property
1112
import org.gradle.kotlin.dsl.property
1213
import javax.inject.Inject
14+
import com.android.build.api.dsl.LibraryExtension as ApiLibraryExtension
1315

1416
public abstract class MapboxLibraryExtension @Inject constructor(objects: ObjectFactory) :
1517
MapboxDependenciesExtension(objects) {
@@ -53,11 +55,15 @@ public abstract class MapboxLibraryExtension @Inject constructor(objects: Object
5355

5456
override fun applyTo(project: Project) {
5557
project.applyRequiredPlugins()
56-
val libraryExtension = project.extensions.getByType(LibraryExtension::class.java)
5758
super.applyTo(project)
58-
libraryExtension.configurePublicResource(project)
59-
libraryExtension.setMinCompileSdkVersion(project)
60-
dokka.applyTo(project, libraryExtension)
59+
60+
val androidComponentsExtension = project.extensions.getByType(LibraryAndroidComponentsExtension::class.java)
61+
androidComponentsExtension.finalizeDsl { libraryExtension: ApiLibraryExtension ->
62+
libraryExtension.enableBuildConfig()
63+
libraryExtension.configurePublicResource(project)
64+
libraryExtension.setMinCompileSdkVersion(project)
65+
}
66+
dokka.applyTo(project, project.extensions.getByType(LibraryExtension::class.java))
6167
// we allow to disable jApiCmp so first we have to evaluate
6268
project.afterEvaluate {
6369
if (jApiCmpEnabledProperty.getOrElse(true)) {
@@ -81,14 +87,14 @@ public abstract class MapboxLibraryExtension @Inject constructor(objects: Object
8187
}
8288
}
8389

84-
private fun LibraryExtension.configurePublicResource(project: Project) {
90+
private fun ApiLibraryExtension.configurePublicResource(project: Project) {
8591
sourceSets.all {
8692
// limit amount of exposed library resources
8793
res.srcDir("${project.projectDir}/src/$name/res-public")
8894
}
8995
}
9096

91-
private fun LibraryExtension.setMinCompileSdkVersion(project: Project) {
97+
private fun ApiLibraryExtension.setMinCompileSdkVersion(project: Project) {
9298
val androidMinCompileSdkVersion =
9399
project.getVersionCatalog().findVersion("androidMinCompileSdkVersion")
94100
if (androidMinCompileSdkVersion.isPresent) {
@@ -98,4 +104,8 @@ private fun LibraryExtension.setMinCompileSdkVersion(project: Project) {
98104
} else {
99105
project.logger.warn("androidMinCompileSdkVersion not found in versions catalog, skip setting minCompileSdkVersion..")
100106
}
107+
}
108+
109+
private fun ApiLibraryExtension.enableBuildConfig() {
110+
buildFeatures.buildConfig = true
101111
}

0 commit comments

Comments
 (0)