Skip to content

Commit b1aa75d

Browse files
authored
chore: [SDK-4192] downgrade Kotlin from 2.2.0 to 1.9.25 (#2601)
1 parent 1bc6dc4 commit b1aa75d

11 files changed

Lines changed: 124 additions & 127 deletions

File tree

OneSignalSDK/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414
huaweiAgconnectVersion = '1.9.1.304'
1515
huaweiHMSPushVersion = '6.3.0.304'
1616
huaweiHMSLocationVersion = '4.0.0.300'
17-
kotlinVersion = '2.2.0'
17+
kotlinVersion = '1.9.25'
1818
dokkaVersion = '1.9.10'
1919
coroutinesVersion = '1.7.3'
2020
kotestVersion = '5.8.0'

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/debug/internal/crash/OtelIntegrationTest.kt

Lines changed: 101 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -35,133 +35,128 @@ private infix fun <T> T.shouldBeOneOf(expected: List<T>) {
3535

3636
@RobolectricTest
3737
@Config(sdk = [Build.VERSION_CODES.O])
38-
class OtelIntegrationTest : FunSpec({
39-
var appContext: Context? = null
40-
var sharedPreferences: SharedPreferences? = null
41-
42-
beforeAny {
43-
if (appContext == null) {
44-
appContext = ApplicationProvider.getApplicationContext()
45-
sharedPreferences = appContext!!.getSharedPreferences(PreferenceStores.ONESIGNAL, Context.MODE_PRIVATE)
38+
class OtelIntegrationTest : FunSpec() {
39+
private lateinit var appContext: Context
40+
private lateinit var sharedPreferences: SharedPreferences
41+
42+
init {
43+
beforeAny {
44+
if (!::appContext.isInitialized) {
45+
appContext = ApplicationProvider.getApplicationContext()
46+
sharedPreferences = appContext.getSharedPreferences(PreferenceStores.ONESIGNAL, Context.MODE_PRIVATE)
47+
}
4648
}
47-
}
4849

49-
beforeEach {
50-
// Ensure sharedPreferences is initialized
51-
if (sharedPreferences == null) {
52-
appContext = ApplicationProvider.getApplicationContext()
53-
sharedPreferences = appContext!!.getSharedPreferences(PreferenceStores.ONESIGNAL, Context.MODE_PRIVATE)
54-
}
55-
// Clear and set up SharedPreferences with test data
56-
sharedPreferences!!.edit().clear().commit()
57-
58-
// Set up ConfigModelStore data
59-
val configModel = JSONObject().apply {
60-
put(ConfigModel::appId.name, "test-app-id")
61-
put(ConfigModel::pushSubscriptionId.name, "test-subscription-id")
62-
val remoteLoggingParams = JSONObject().apply {
63-
put("logLevel", "ERROR")
50+
beforeEach {
51+
if (!::sharedPreferences.isInitialized) {
52+
appContext = ApplicationProvider.getApplicationContext()
53+
sharedPreferences = appContext.getSharedPreferences(PreferenceStores.ONESIGNAL, Context.MODE_PRIVATE)
54+
}
55+
sharedPreferences.edit().clear().commit()
56+
57+
val configModel = JSONObject().apply {
58+
put(ConfigModel::appId.name, "test-app-id")
59+
put(ConfigModel::pushSubscriptionId.name, "test-subscription-id")
60+
val remoteLoggingParams = JSONObject().apply {
61+
put("logLevel", "ERROR")
62+
}
63+
put(ConfigModel::remoteLoggingParams.name, remoteLoggingParams)
64+
}
65+
val configArray = JSONArray().apply {
66+
put(configModel)
6467
}
65-
put(ConfigModel::remoteLoggingParams.name, remoteLoggingParams)
66-
}
67-
val configArray = JSONArray().apply {
68-
put(configModel)
69-
}
7068

71-
// Set up IdentityModelStore data
72-
val identityModel = JSONObject().apply {
73-
put(IdentityConstants.ONESIGNAL_ID, "test-onesignal-id")
74-
}
75-
val identityArray = JSONArray().apply {
76-
put(identityModel)
77-
}
69+
val identityModel = JSONObject().apply {
70+
put(IdentityConstants.ONESIGNAL_ID, "test-onesignal-id")
71+
}
72+
val identityArray = JSONArray().apply {
73+
put(identityModel)
74+
}
7875

79-
sharedPreferences.edit()
80-
.putString(PreferenceOneSignalKeys.MODEL_STORE_PREFIX + configNameSpace, configArray.toString())
81-
.putString(PreferenceOneSignalKeys.MODEL_STORE_PREFIX + identityNameSpace, identityArray.toString())
82-
.putString(PreferenceOneSignalKeys.PREFS_OS_INSTALL_ID, "test-install-id")
83-
.commit()
84-
}
76+
sharedPreferences.edit()
77+
.putString(PreferenceOneSignalKeys.MODEL_STORE_PREFIX + configNameSpace, configArray.toString())
78+
.putString(PreferenceOneSignalKeys.MODEL_STORE_PREFIX + identityNameSpace, identityArray.toString())
79+
.putString(PreferenceOneSignalKeys.PREFS_OS_INSTALL_ID, "test-install-id")
80+
.commit()
81+
}
8582

86-
afterEach {
87-
sharedPreferences!!.edit().clear().commit()
88-
}
83+
afterEach {
84+
sharedPreferences.edit().clear().commit()
85+
}
8986

90-
test("AndroidOtelPlatformProvider should provide correct Android values") {
91-
val provider = createAndroidOtelPlatformProvider(appContext!!)
87+
test("AndroidOtelPlatformProvider should provide correct Android values") {
88+
val provider = createAndroidOtelPlatformProvider(appContext)
9289

93-
provider.shouldBeInstanceOf<IOtelPlatformProvider>()
94-
provider.sdkBase shouldBe "android"
95-
provider.appPackageId shouldBe appContext!!.packageName // Use actual package name from context
96-
provider.osName shouldBe "Android"
97-
provider.deviceManufacturer shouldBe Build.MANUFACTURER
98-
provider.deviceModel shouldBe Build.MODEL
99-
provider.osVersion shouldBe Build.VERSION.RELEASE
100-
provider.osBuildId shouldBe Build.ID
90+
provider.shouldBeInstanceOf<IOtelPlatformProvider>()
91+
provider.sdkBase shouldBe "android"
92+
provider.appPackageId shouldBe appContext.packageName
93+
provider.osName shouldBe "Android"
94+
provider.deviceManufacturer shouldBe Build.MANUFACTURER
95+
provider.deviceModel shouldBe Build.MODEL
96+
provider.osVersion shouldBe Build.VERSION.RELEASE
97+
provider.osBuildId shouldBe Build.ID
10198

102-
runBlocking {
103-
provider.getInstallId() shouldNotBe null
99+
runBlocking {
100+
provider.getInstallId() shouldNotBe null
101+
}
104102
}
105-
}
106103

107-
test("AndroidOtelPlatformProvider should provide per-event values") {
108-
val provider = createAndroidOtelPlatformProvider(appContext!!)
104+
test("AndroidOtelPlatformProvider should provide per-event values") {
105+
val provider = createAndroidOtelPlatformProvider(appContext)
109106

110-
provider.appId shouldBe "test-app-id"
111-
provider.onesignalId shouldBe "test-onesignal-id"
112-
provider.pushSubscriptionId shouldBe "test-subscription-id"
113-
provider.appState shouldBeOneOf listOf("foreground", "background", "unknown")
114-
(provider.processUptime > 0) shouldBe true
115-
provider.currentThreadName shouldBe Thread.currentThread().name
116-
}
107+
provider.appId shouldBe "test-app-id"
108+
provider.onesignalId shouldBe "test-onesignal-id"
109+
provider.pushSubscriptionId shouldBe "test-subscription-id"
110+
provider.appState shouldBeOneOf listOf("foreground", "background", "unknown")
111+
(provider.processUptime > 0) shouldBe true
112+
provider.currentThreadName shouldBe Thread.currentThread().name
113+
}
117114

118-
test("AndroidOtelLogger should delegate to Logging") {
119-
val logger = AndroidOtelLogger()
115+
test("AndroidOtelLogger should delegate to Logging") {
116+
val logger = AndroidOtelLogger()
120117

121-
logger.shouldBeInstanceOf<com.onesignal.otel.IOtelLogger>()
122-
// Should not throw
123-
logger.debug("test")
124-
logger.info("test")
125-
logger.warn("test")
126-
logger.error("test")
127-
}
118+
logger.shouldBeInstanceOf<com.onesignal.otel.IOtelLogger>()
119+
logger.debug("test")
120+
logger.info("test")
121+
logger.warn("test")
122+
logger.error("test")
123+
}
128124

129-
test("OtelFactory should create crash handler with Android provider") {
130-
val provider = createAndroidOtelPlatformProvider(appContext!!)
131-
val logger = AndroidOtelLogger()
125+
test("OtelFactory should create crash handler with Android provider") {
126+
val provider = createAndroidOtelPlatformProvider(appContext)
127+
val logger = AndroidOtelLogger()
132128

133-
val handler = OtelFactory.createCrashHandler(provider, logger)
129+
val handler = OtelFactory.createCrashHandler(provider, logger)
134130

135-
handler shouldNotBe null
136-
handler.shouldBeInstanceOf<IOtelCrashHandler>()
137-
handler.initialize() // Should not throw
138-
}
131+
handler shouldNotBe null
132+
handler.shouldBeInstanceOf<IOtelCrashHandler>()
133+
handler.initialize()
134+
}
139135

140-
test("OneSignalCrashHandlerFactory should create working crash handler") {
141-
// Note: OneSignalCrashHandlerFactory may need to be updated to use the new approach
142-
// For now, we'll test the direct creation
143-
val provider = createAndroidOtelPlatformProvider(appContext!!)
144-
val logger = AndroidOtelLogger()
145-
val handler = OtelFactory.createCrashHandler(provider, logger)
136+
test("OneSignalCrashHandlerFactory should create working crash handler") {
137+
val provider = createAndroidOtelPlatformProvider(appContext)
138+
val logger = AndroidOtelLogger()
139+
val handler = OtelFactory.createCrashHandler(provider, logger)
146140

147-
handler shouldNotBe null
148-
handler.shouldBeInstanceOf<IOtelCrashHandler>()
149-
handler.initialize() // Should not throw
150-
}
141+
handler shouldNotBe null
142+
handler.shouldBeInstanceOf<IOtelCrashHandler>()
143+
handler.initialize()
144+
}
151145

152-
test("AndroidOtelPlatformProvider should provide crash storage path") {
153-
val provider = createAndroidOtelPlatformProvider(appContext!!)
146+
test("AndroidOtelPlatformProvider should provide crash storage path") {
147+
val provider = createAndroidOtelPlatformProvider(appContext)
154148

155-
provider.crashStoragePath.contains("onesignal") shouldBe true
156-
provider.crashStoragePath.contains("otel") shouldBe true
157-
provider.crashStoragePath.contains("crashes") shouldBe true
158-
provider.minFileAgeForReadMillis shouldBe 5000L
159-
}
149+
provider.crashStoragePath.contains("onesignal") shouldBe true
150+
provider.crashStoragePath.contains("otel") shouldBe true
151+
provider.crashStoragePath.contains("crashes") shouldBe true
152+
provider.minFileAgeForReadMillis shouldBe 5000L
153+
}
160154

161-
test("AndroidOtelPlatformProvider should handle remote logging config") {
162-
val provider = createAndroidOtelPlatformProvider(appContext!!)
155+
test("AndroidOtelPlatformProvider should handle remote logging config") {
156+
val provider = createAndroidOtelPlatformProvider(appContext)
163157

164-
provider.remoteLogLevel shouldBe "ERROR"
165-
provider.appIdForHeaders shouldBe "test-app-id"
158+
provider.remoteLogLevel shouldBe "ERROR"
159+
provider.appIdForHeaders shouldBe "test-app-id"
160+
}
166161
}
167-
})
162+
}

OneSignalSDK/onesignal/otel/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ android {
3636

3737
kotlinOptions {
3838
jvmTarget = '1.8'
39-
freeCompilerArgs += ['-module-name', namespace]
39+
freeCompilerArgs += ['-module-name', namespace, '-Xskip-metadata-version-check']
4040
}
4141
}
4242

examples/build.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ In MainViewModel.kt, implement observers:
154154
11. **Triggers Section** (Add/Add Multiple/Remove Selected/Clear All - IN MEMORY ONLY)
155155
12. **Track Event Section** (Track Event with JSON validation)
156156
13. **Location Section** (Location Shared toggle, Prompt Location button)
157-
14. **Next Activity Button**
157+
14. **Next Screen Button**
158158

159159
### Prompt 2.1 - App Section
160160

@@ -374,12 +374,12 @@ Location Section:
374374
- PROMPT LOCATION button
375375
```
376376

377-
### Prompt 2.14 - Secondary Activity
377+
### Prompt 2.14 - Secondary Screen
378378

379379
```
380-
Secondary Activity (launched by "Next Activity" button at bottom of main screen):
381-
- Activity title: "Secondary Activity"
382-
- Page content: centered text "Secondary Activity" using headlineMedium style
380+
Secondary Screen (launched by "Next Screen" button at bottom of main screen):
381+
- Screen title: "Secondary Screen"
382+
- Page content: centered text "Secondary Screen" using headlineMedium style
383383
- Simple screen, no additional functionality needed
384384
```
385385

@@ -650,7 +650,7 @@ Enable Jetpack Compose in the project:
650650
651651
build.gradle.kts (app):
652652
- buildFeatures { compose = true }
653-
- composeOptions { kotlinCompilerExtensionVersion = "1.5.10" }
653+
- composeOptions { kotlinCompilerExtensionVersion = "1.5.15" }
654654
655655
Dependencies (via BOM):
656656
- composeBom = "2024.02.00"

examples/demo/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Send a named **event** with optional JSON properties for advanced analytics.
145145
### Location
146146
Toggle **location sharing** on or off and **prompt** for location permission.
147147

148-
### Secondary Activity
148+
### Secondary Screen
149149
Navigate to a second screen with buttons to **simulate a crash** (`RuntimeException`) and **simulate an ANR** (10-second main-thread block) — useful for testing crash and ANR reporting.
150150

151151
### Log Viewer

examples/demo/app/build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
plugins {
22
id("com.android.application")
33
id("kotlin-android")
4-
id("org.jetbrains.kotlin.plugin.compose") version "2.2.0"
54
}
65

7-
// Keep IDE sync stable even if root extra properties are unavailable.
8-
val kotlinVersion: String = rootProject.findProperty("kotlinVersion") as? String ?: "2.2.0"
6+
val kotlinVersion: String = rootProject.findProperty("kotlinVersion") as? String ?: "1.9.25"
97

108
// Apply GMS or Huawei plugin based on build variant
119
// Check at configuration time, not when task graph is ready
@@ -37,6 +35,10 @@ android {
3735
compose = true
3836
}
3937

38+
composeOptions {
39+
kotlinCompilerExtensionVersion = "1.5.15"
40+
}
41+
4042
flavorDimensions += "default"
4143

4244
productFlavors {

examples/demo/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</intent-filter>
6363
</activity>
6464

65-
<!-- Secondary Activity -->
65+
<!-- Secondary Screen -->
6666
<activity
6767
android:name=".ui.secondary.SecondaryActivity"
6868
android:exported="false" />

examples/demo/app/src/main/java/com/onesignal/sdktest/ui/main/MainScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ fun MainScreen(viewModel: MainViewModel) {
263263

264264
Spacer(modifier = Modifier.height(8.dp))
265265

266-
// === NEXT ACTIVITY BUTTON ===
266+
// === NEXT SCREEN BUTTON ===
267267
PrimaryButton(
268-
text = "NEXT ACTIVITY",
268+
text = "NEXT SCREEN",
269269
onClick = {
270270
context.startActivity(Intent(context, SecondaryActivity::class.java))
271271
}

examples/demo/app/src/main/java/com/onesignal/sdktest/ui/secondary/SecondaryActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SecondaryActivity : ComponentActivity() {
4242
Scaffold(
4343
topBar = {
4444
CenterAlignedTopAppBar(
45-
title = { Text("Secondary Activity", color = Color.White) },
45+
title = { Text("Secondary Screen", color = Color.White) },
4646
navigationIcon = {
4747
IconButton(onClick = { finish() }) {
4848
Icon(
@@ -67,7 +67,7 @@ class SecondaryActivity : ComponentActivity() {
6767
verticalArrangement = Arrangement.Center
6868
) {
6969
Text(
70-
text = "Secondary Activity",
70+
text = "Secondary Screen",
7171
style = MaterialTheme.typography.headlineMedium
7272
)
7373

examples/demo/app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105
<!-- Send In-App Message -->
106106
<string name="send_in_app_message">Send In-App Message</string>
107107

108-
<!-- Next Activity -->
109-
<string name="next_activity">NEXT ACTIVITY</string>
110-
<string name="secondary_activity">Secondary Activity</string>
108+
<!-- Next Screen -->
109+
<string name="next_activity">NEXT SCREEN</string>
110+
<string name="secondary_activity">Secondary Screen</string>
111111

112112
<!-- Dialog -->
113113
<string name="external_user_id">External User Id</string>

0 commit comments

Comments
 (0)