Skip to content

Commit c447d32

Browse files
authored
chore: Update to Android Gradle Plugin 8.3.2 and SDK 34 (#314)
Upgraded Android Gradle Plugin, Gradle wrapper, and dexcount plugin versions. Migrated all modules to use compileSdk 34 and targetSdk 34, added namespace declarations, and updated build configuration to match latest Gradle and Android standards. Improved build script structure and fixed deprecation warnings for Gradle tasks. **Requirements** - [ ] I have added test coverage for new or changed functionality - [ ] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [ ] I have validated my changes against all supported platform versions **Related issues** - **Describe the solution you've provided** Upgrade gradle from 7.3.3 version to 8.5.0 **Additional context** I wanted to build the project to check something, but I was asked to upgrade the gradle version to 8.x.x and I thought it was a good idea to push the change. I haven't tested it extensively since this is out of the scope of my tickets, but it seems to work correctly. @tanderson-ld check it a bit more before approve it please. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Upgrade build system to Gradle 8.5/AGP 8.3.2 and migrate all modules to compile/target SDK 34 with namespace and modern Gradle/Android DSL updates, plus test/proguard tweaks and a receiver fix for Android 13+. > > - **Build system**: > - Upgrade Gradle wrapper to `8.5`, Android Gradle Plugin to `8.3.2`, dexcount to `4.0.0`, and Nexus Publish plugin to `1.3.0`. > - Refactor root `build.gradle`: use `base.archivesName`, centralize Android config via `BaseExtension`, enable deprecation checks, and add test JVM `--add-opens`. > - **Android SDK/config**: > - Migrate all modules to `compileSdk`/`targetSdk` `34`, add `namespace`, switch to new `minSdk`/`compileSdk` DSLs, remove `buildToolsVersion`. > - Update manifests and activities (add `android:exported` where needed); switch to new `packaging { resources { excludes } }` and `publishing { singleVariant("release") }`. > - **Javadoc & publishing**: > - Rewrite Javadoc/sources tasks using lazy task registration; add Android boot classpath and BuildConfig generation deps; update artifact publication to new APIs. > - **Testing & dependencies**: > - Bump AndroidX test libraries and orchestrator; add ProGuard rules in `example` and `contract-tests`; exclude `error_prone_annotations` to avoid dexing issues. > - **Runtime**: > - On Android 13+, register connectivity `BroadcastReceiver` with `Context.RECEIVER_NOT_EXPORTED` in `AndroidPlatformState`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit cd3320f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2 parents 15bf67c + cd3320f commit c447d32

File tree

14 files changed

+113
-71
lines changed

14 files changed

+113
-71
lines changed

build.gradle

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import java.time.Duration
2+
import com.android.build.gradle.BaseExtension
23

34
// Top-level build file where you can add configuration options common to all sub-projects/modules.
45

@@ -8,11 +9,11 @@ buildscript {
89
google()
910
}
1011
dependencies {
11-
classpath('com.android.tools.build:gradle:7.1.1')
12+
classpath('com.android.tools.build:gradle:8.3.2')
1213

1314
// For displaying method/field counts when building with Gradle:
1415
// https://github.com/KeepSafe/dexcount-gradle-plugin
15-
classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.1.0")
16+
classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:4.0.0")
1617

1718
// NOTE: Do not place your application dependencies here; they belong
1819
// in the individual module build.gradle files
@@ -21,13 +22,15 @@ buildscript {
2122

2223
plugins {
2324
id("java")
24-
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
25+
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
2526
}
2627

2728
// Must be specified in root project for the gradle nexus publish plugin.
2829
group = "com.launchdarkly"
29-
// Specified in the root project so Releaser's `publish-dry-run.sh` can see it in `./gradlew properties`
30-
archivesBaseName = 'launchdarkly-android-client-sdk'
30+
base {
31+
// Specified in the root project so Releaser's `publish-dry-run.sh` can see it in `./gradlew properties`
32+
archivesName = "launchdarkly-android-client-sdk"
33+
}
3134
// Specified in gradle.properties
3235
version = version
3336

@@ -41,21 +44,13 @@ allprojects {
4144
}
4245
}
4346

44-
subprojects {
45-
afterEvaluate {
46-
configure(android.lintOptions) {
47-
abortOnError = false
48-
}
49-
configure(android.compileOptions) {
47+
def configureAndroidModule(Project project) {
48+
project.extensions.configure(BaseExtension) { androidExt ->
49+
androidExt.lint { abortOnError = false }
50+
androidExt.compileOptions {
5051
sourceCompatibility = JavaVersion.VERSION_1_8
5152
targetCompatibility = JavaVersion.VERSION_1_8
5253
}
53-
gradle.projectsEvaluated {
54-
tasks.withType(JavaCompile) {
55-
// enable deprecation checks
56-
options.compilerArgs << "-Xlint:deprecation"
57-
}
58-
}
5954
}
6055
}
6156

@@ -68,3 +63,20 @@ nexusPublishing {
6863
}
6964
}
7065
}
66+
67+
subprojects { subproject ->
68+
plugins.withId("com.android.application") {
69+
configureAndroidModule(subproject)
70+
}
71+
plugins.withId("com.android.library") {
72+
configureAndroidModule(subproject)
73+
}
74+
tasks.withType(JavaCompile).configureEach {
75+
// enable deprecation checks
76+
options.compilerArgs += "-Xlint:deprecation"
77+
}
78+
tasks.withType(Test).configureEach {
79+
// Allow EasyMock/CGLIB to use reflection on Java base classes when running on newer JDKs.
80+
jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED"]
81+
}
82+
}

contract-tests/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ plugins {
55
}
66

77
android {
8-
compileSdkVersion(30)
9-
buildToolsVersion = "30.0.3"
8+
namespace "com.launchdarkly.sdktest"
9+
compileSdk = 34
1010

1111
defaultConfig {
1212
applicationId = "com.launchdarkly.sdktest"
13-
minSdkVersion(21)
14-
targetSdkVersion(30)
13+
minSdk = 21
14+
targetSdk = 34
1515
versionCode = 1
1616
versionName = "1.0"
1717
}

contract-tests/proguard-rules.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Allow compile-time-only error-prone annotations to be stripped without breaking shrink.
2+
-dontwarn com.google.errorprone.annotations.**

contract-tests/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.launchdarkly.sdktest">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
65
<uses-permission android:name="android.permission.INTERNET" />

example/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ plugins {
55
}
66

77
android {
8-
compileSdkVersion(30)
9-
buildToolsVersion = "30.0.3"
8+
namespace "com.launchdarkly.example"
9+
compileSdk = 34
1010

1111
defaultConfig {
1212
applicationId = "com.launchdarkly.example"
13-
minSdkVersion(21)
14-
targetSdkVersion(30)
13+
minSdk = 21
14+
targetSdk = 34
1515
versionCode = 1
1616
versionName = "1.0"
1717
}
1818

1919
buildTypes {
2020
release {
2121
minifyEnabled = true
22+
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
2223
}
2324
}
2425
}

example/proguard-rules.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Allow compile-time-only error-prone annotations to be stripped without breaking shrink.
2+
-dontwarn com.google.errorprone.annotations.**
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.launchdarkly.example">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<uses-permission android:name="android.permission.INTERNET" />
65
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
76

87
<application android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme">
9-
<activity android:name=".MainActivity">
8+
<activity
9+
android:name=".MainActivity"
10+
android:exported="true">
1011
<intent-filter>
1112
<action android:name="android.intent.action.MAIN" />
1213

@@ -15,4 +16,4 @@
1516
</activity>
1617
</application>
1718

18-
</manifest>
19+
</manifest>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Jan 11 09:20:17 PST 2018
1+
#Tue Nov 25 16:57:24 ART 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip

launchdarkly-android-client-sdk/build.gradle

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ group = "com.launchdarkly"
1010
version = version
1111

1212
android {
13-
compileSdkVersion(30)
14-
buildToolsVersion = "30.0.3"
13+
namespace "com.launchdarkly.sdk.android"
14+
compileSdk = 34
1515

1616
defaultConfig {
17-
minSdkVersion(21)
18-
targetSdkVersion(30)
17+
minSdk = 21
18+
targetSdk = 34
1919
// at some point between android gradle 3.1.0 and 4.x.x the versionName field in this dsl
2020
// stopped generating the BuildConfig::VERSION_NAME field in the end java
2121
// classpath. put this here to bring back that field
@@ -33,8 +33,18 @@ android {
3333
execution = "ANDROIDX_TEST_ORCHESTRATOR"
3434
}
3535

36-
packagingOptions {
37-
exclude("META-INF/**")
36+
buildFeatures {
37+
buildConfig = true
38+
}
39+
40+
publishing {
41+
singleVariant("release")
42+
}
43+
44+
packaging {
45+
resources {
46+
excludes += ["META-INF/**"]
47+
}
3848
}
3949

4050
useLibrary("android.test.runner")
@@ -100,45 +110,56 @@ dependencies {
100110
androidTestImplementation("com.squareup.okhttp3:mockwebserver:${versions.okhttp}")
101111
androidTestImplementation(project(":shared-test-code"))
102112

103-
androidTestImplementation("androidx.test:core:1.4.0")
104-
androidTestImplementation("androidx.test:runner:1.4.0")
105-
androidTestImplementation("androidx.test:rules:1.4.0")
106-
androidTestImplementation("androidx.test.ext:junit:1.1.3")
113+
androidTestImplementation("androidx.test:core:1.5.0")
114+
androidTestImplementation("androidx.test:runner:1.5.2")
115+
androidTestImplementation("androidx.test:rules:1.5.0")
116+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
107117
androidTestImplementation("org.easymock:easymock:4.3")
108118

109-
androidTestUtil("androidx.test:orchestrator:1.4.1")
119+
androidTestUtil("androidx.test:orchestrator:1.4.2")
110120
}
111121

112-
task javadoc(type: Javadoc) {
122+
def androidJavadoc = tasks.register("javadoc", Javadoc) {
113123
// Include SDK sources
114124
source android.sourceSets.main.java.srcDirs
115125
// Include common library sources
116126
source configurations.commonDoc.collect { zipTree(it) }
117127
source "$buildDir/generated/source"
128+
// Ensure generated BuildConfig is present before javadoc runs.
129+
dependsOn("generateDebugBuildConfig", "generateReleaseBuildConfig")
118130

119131
include("**/*.java")
120132

121-
// Include classpaths for dependencies
122-
afterEvaluate {
133+
if (options instanceof StandardJavadocDocletOptions) {
134+
options.source = "8"
135+
}
136+
137+
doFirst {
138+
// Include classpaths for dependencies
123139
classpath += files(android.libraryVariants.collect { variant ->
124140
variant.javaCompileProvider.get().classpath.files
125141
})
142+
// Add Android boot classpath for references to Android OS classes.
143+
def bootClasspath = files(android.bootClasspath)
144+
classpath += bootClasspath
145+
if (options instanceof StandardJavadocDocletOptions) {
146+
options.bootClasspath = bootClasspath.files.toList()
147+
}
126148
}
127149
// Include classpath for commonClasses configuration so Javadoc won't complain about java-sdk-common classes that
128150
// internally reference Jackson, which we don't use directly
129151
classpath += project.files(configurations.commonClasses.resolve())
130-
// Add Android boot classpath for references to Android OS classes.
131-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
132152
}
133153

134-
task sourcesJar(type: Jar) {
135-
classifier = "sources"
154+
def sourcesJar = tasks.register("sourcesJar", Jar) {
155+
archiveClassifier.set("sources")
136156
from android.sourceSets.main.java.srcDirs
137157
}
138158

139-
task javadocJar(type: Jar, dependsOn: javadoc) {
140-
classifier = "javadoc"
141-
from javadoc.destinationDir
159+
def javadocJar = tasks.register("javadocJar", Jar) {
160+
dependsOn(androidJavadoc)
161+
archiveClassifier.set("javadoc")
162+
from(androidJavadoc.map { it.destinationDir })
142163
}
143164

144165
tasks.withType(Javadoc) {
@@ -152,19 +173,20 @@ tasks.withType(Javadoc) {
152173
}
153174

154175
artifacts {
155-
archives sourcesJar, javadocJar
176+
add("archives", sourcesJar.get())
177+
add("archives", javadocJar.get())
156178
}
157179

158180
afterEvaluate {
159181
publishing {
160182
publications {
161183
release(MavenPublication) {
162-
from components.release
184+
from components["release"]
163185

164186
artifactId = "launchdarkly-android-client-sdk"
165187

166-
artifact(sourcesJar)
167-
artifact(javadocJar)
188+
artifact(sourcesJar.get())
189+
artifact(javadocJar.get())
168190

169191
pom {
170192
name = "LaunchDarkly SDK for Android"

launchdarkly-android-client-sdk/src/androidTest/AndroidManifest.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.launchdarkly.sdk.android">
4-
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
54
<uses-permission android:name="android.permission.INTERNET" />
65
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
76
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
@@ -18,4 +17,4 @@
1817
android:name="androidx.test.runner.AndroidJUnitRunner"
1918
android:targetPackage="com.launchdarkly.sdk.android" />
2019

21-
</manifest>
20+
</manifest>

0 commit comments

Comments
 (0)