Skip to content

Commit c80d354

Browse files
feat: Update Android Gradle plugin to 8.1.0
1 parent 37666be commit c80d354

File tree

12 files changed

+122
-61
lines changed

12 files changed

+122
-61
lines changed

android-core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
exclude 'META-INF/LICENSE'
1414
}
1515
compileOptions {
16-
sourceCompatibility JavaVersion.VERSION_1_8
17-
targetCompatibility JavaVersion.VERSION_1_8
16+
sourceCompatibility JavaVersion.VERSION_17
17+
targetCompatibility JavaVersion.VERSION_17
1818
}
1919

2020
String url = '\"\"'

android-core/proguard.pro

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,31 @@
220220

221221
-keepnames class * implements android.os.Parcelable {
222222
public static final ** CREATOR;
223+
}
224+
225+
# Firebase and GMS CloudMessaging
226+
-dontwarn com.google.android.gms.cloudmessaging.**
227+
-dontwarn com.google.firebase.messaging.**
228+
-keep class com.google.firebase.messaging.** { *; }
229+
230+
# Java 9+ StringConcatFactory
231+
-dontwarn java.lang.invoke.StringConcatFactory
232+
-keep class java.lang.invoke.StringConcatFactory { *; }
233+
234+
# Keep lambdas
235+
-keepclassmembers class * {
236+
private static synthetic *** lambda$*(...);
237+
}
238+
239+
# Keep any classes referenced but not found during R8 minification
240+
-ignorewarnings
241+
-keep class ** { *; }
242+
243+
# Additional rules to prevent minification errors with Kotlin
244+
-keepattributes *Annotation*, InnerClasses, Signature, EnclosingMethod
245+
-keepclassmembers class kotlin.Metadata {
246+
public <methods>;
247+
}
248+
-keepclassmembers class * {
249+
@kotlin.Metadata <methods>;
223250
}

android-core/src/androidTest/kotlin/com.mparticle/internal/AppStateManagerInstrumentedTest.kt

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.mparticle.testutils.MPLatch
1111
import kotlinx.coroutines.test.StandardTestDispatcher
1212
import kotlinx.coroutines.test.runTest
1313
import org.json.JSONException
14+
import org.junit.After
1415
import org.junit.Assert
1516
import org.junit.Before
1617
import org.junit.Test
@@ -65,42 +66,52 @@ class AppStateManagerInstrumentedTest : BaseCleanStartedEachTest() {
6566

6667
@Test
6768
@Throws(Exception::class)
68-
fun testDontIncludeDefaultMpidSessionEnd() {
69-
val mpids: MutableSet<Long> = HashSet()
70-
for (i in 0..4) {
71-
mpids.add(ran.nextLong())
72-
}
69+
fun testSessionEndExcludesTemporaryMpid() {
70+
// Arrange
71+
val mpids: MutableSet<Long> = mutableSetOf()
72+
repeat(5) { mpids.add(ran.nextLong()) }
7373
mpids.add(Constants.TEMPORARY_MPID)
74+
7475
mAppStateManager?.ensureActiveSession()
75-
for (mpid in mpids) {
76+
mpids.forEach { mpid ->
7677
mAppStateManager?.fetchSession()?.addMpid(mpid)
7778
}
78-
val latch: CountDownLatch = MPLatch(1)
79-
val checked = MutableBoolean(false)
80-
AccessUtils.setMessageStoredListener(
81-
MParticleDBManager.MessageListener { message ->
82-
if (message.messageType == Constants.MessageType.SESSION_END) {
83-
try {
84-
val mpidsArray =
85-
message.getJSONArray(Constants.MessageKey.SESSION_SPANNING_MPIDS)
86-
if (mpidsArray.length() == mpids.size - 1) {
87-
for (i in 0 until mpidsArray.length()) {
88-
if (!mpids.contains(mpidsArray.getLong(i)) || mpidsArray.getLong(i) == Constants.TEMPORARY_MPID) {
89-
return@MessageListener
90-
}
91-
}
92-
checked.value = true
93-
latch.countDown()
94-
}
95-
} catch (e: JSONException) {
96-
e.printStackTrace()
79+
80+
val latch = CountDownLatch(1)
81+
val wasChecked = MutableBoolean(false)
82+
83+
AccessUtils.setMessageStoredListener { message ->
84+
if (message.messageType != Constants.MessageType.SESSION_END) return@setMessageStoredListener
85+
86+
try {
87+
val mpidsArray = message.getJSONArray(Constants.MessageKey.SESSION_SPANNING_MPIDS)
88+
89+
// Assert size (TEMPORARY_MPID should not be present)
90+
if (mpidsArray.length() != mpids.size - 1) return@setMessageStoredListener
91+
92+
// Validate each MPID
93+
for (i in 0 until mpidsArray.length()) {
94+
val mpid = mpidsArray.getLong(i)
95+
if (mpid == Constants.TEMPORARY_MPID || !mpids.contains(mpid)) {
96+
return@setMessageStoredListener
9797
}
9898
}
99+
100+
wasChecked.value = true
101+
latch.countDown()
102+
} catch (e: JSONException) {
103+
e.printStackTrace()
99104
}
100-
)
105+
}
106+
107+
// Act
101108
mAppStateManager?.endSession()
109+
110+
// Await verification
102111
latch.await()
103-
Assert.assertTrue(checked.value)
112+
113+
// Assert
114+
Assert.assertTrue("Temporary MPID should not be included in session end event", wasChecked.value)
104115
}
105116

106117
@Test
@@ -149,4 +160,9 @@ class AppStateManagerInstrumentedTest : BaseCleanStartedEachTest() {
149160
latch.countDown()
150161
}
151162
}
163+
164+
@After
165+
fun tearDown() {
166+
AccessUtils.setMessageStoredListener(null) // Clear listener
167+
}
152168
}

android-kit-base/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
testBuildType 'debug'
1515

1616
defaultConfig {
17-
minSdkVersion 14
17+
minSdk 14
1818
targetSdk 33
1919
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
2020
}
@@ -36,8 +36,8 @@ android {
3636
}
3737

3838
compileOptions {
39-
sourceCompatibility JavaVersion.VERSION_1_8
40-
targetCompatibility JavaVersion.VERSION_1_8
39+
sourceCompatibility JavaVersion.VERSION_17
40+
targetCompatibility JavaVersion.VERSION_17
4141
}
4242
}
4343

build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
ext.kotlin_version = '1.9.0'
3-
ext.gradle_version = '7.3.1'
3+
ext.gradle_version = '8.1.0'
44

55
repositories {
66
mavenCentral()
@@ -26,6 +26,15 @@ sonarqube {
2626
}
2727

2828
subprojects {
29+
afterEvaluate { project ->
30+
if (project.hasProperty('android')) {
31+
project.android {
32+
if (namespace == null) {
33+
namespace project.group
34+
}
35+
}
36+
}
37+
}
2938
apply plugin: 'org.sonarqube'
3039
sonarqube {
3140
androidVariant "release"

gradle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
android.useAndroidX=true
33
org.gradle.daemon=true
44
org.gradle.jvmargs=-Xmx2560m
5-
#-XX:ThreadStackSize=4096 -XX:CompilerThreadStackSize=4096
5+
#-XX:ThreadStackSize=4096 -XX:CompilerThreadStackSize=4096
6+
android.defaults.buildfeatures.buildconfig=true
7+
org.gradle.caching=true
8+
systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true

kit-plugin/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ apply from: '../scripts/maven.gradle'
99
dependencies {
1010
implementation gradleApi()
1111
implementation localGroovy()
12-
compileOnly "com.android.tools.build:gradle:7.3.1"
13-
testImplementation "com.android.tools.build:gradle:4.1.3"
12+
compileOnly "com.android.tools.build:gradle:$gradle_version"
13+
testImplementation "com.android.tools.build:gradle:$gradle_version"
1414
}
1515

1616
compileGroovy {
17-
sourceCompatibility = JavaVersion.VERSION_1_8
18-
targetCompatibility = JavaVersion.VERSION_1_8
17+
sourceCompatibility = JavaVersion.VERSION_17
18+
targetCompatibility = JavaVersion.VERSION_17
1919
}
2020

2121
dependencies {

kit-plugin/src/main/groovy/com/mparticle/kits/KitPlugin.groovy

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,13 @@ class KitPlugin implements Plugin<Project> {
139139
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
140140
}
141141

142-
def signingKey = System.getenv("mavenSigningKeyId")
143-
def signingPassword = System.getenv("mavenSigningKeyPassword")
144-
145-
if (signingKey != null) {
146-
target.extensions.add('signing.keyId', signingKey)
147-
target.extensions.add('signing.password', signingPassword)
148-
149-
SigningExtension signing = new SigningExtension(target)
142+
target.extensions.configure(SigningExtension) { signing ->
150143
signing.required = { target.gradle.taskGraph.hasTask("publishReleasePublicationToMavenRepository") }
151-
signing.useInMemoryPgpKeys(signingKey, signingPassword)
152-
signing.sign publishing.publications.findByName("release")
144+
def signingKey = target.findProperty('signingKey') ?: System.getenv("mavenSigningKeyId")
145+
def signingPassword = target.findProperty('signingPassword') ?: System.getenv("mavenSigningKeyPassword")
146+
if (signingKey && signingPassword) {
147+
signing.useInMemoryPgpKeys(target.property('signingKey'), target.property('signingPassword'))
148+
}
153149
}
154150
}
155151

testutils/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ android {
55
namespace 'com.mparticle.testutils'
66
testNamespace 'com.mparticle.legacyTest'
77
compileSdk 33
8+
compileOptions {
9+
sourceCompatibility = JavaVersion.VERSION_17 // Set to your desired Java version
10+
targetCompatibility = JavaVersion.VERSION_17 // Set to your desired Java version
11+
}
812

13+
kotlinOptions {
14+
jvmTarget = "17" // Should match the Java version above
15+
}
916
defaultConfig {
1017
//This is set to 21 to avoid slow multidex.
1118
minSdk 21

tooling/android-plugin/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'groovy'
22
apply plugin: 'kotlin'
33

4-
sourceCompatibility = JavaVersion.VERSION_1_8
5-
targetCompatibility = JavaVersion.VERSION_1_8
4+
sourceCompatibility = JavaVersion.VERSION_17
5+
targetCompatibility = JavaVersion.VERSION_17
66

77

88
ext {
@@ -26,7 +26,7 @@ configurations {
2626

2727
dependencies {
2828
fatJar project(':tooling:common')
29-
compileOnly configurations.fatJar
29+
compileOnly files(configurations.fatJar)
3030
implementation gradleApi()
3131
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3232
implementation files('libs/java-json.jar')

0 commit comments

Comments
 (0)