Skip to content

Commit c406795

Browse files
authored
fix: suppress logger crash on armeabi devices (#516)
1 parent c8ecff1 commit c406795

3 files changed

Lines changed: 68 additions & 11 deletions

File tree

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.customer.reactnative.sdk.logging
22

3+
import android.os.Build
4+
import android.util.Log
35
import com.facebook.react.bridge.ReactApplicationContext
46
import io.customer.reactnative.sdk.NativeCustomerIOLoggingSpec
57
import io.customer.reactnative.sdk.util.onlyForLegacyArch
@@ -13,23 +15,78 @@ class NativeCustomerIOLoggingModule(
1315
) : NativeCustomerIOLoggingSpec(reactContext) {
1416
override fun getName(): String = NativeCustomerIOLoggingModuleImpl.NAME
1517

18+
// true if the app is currently running under armeabi/armeabi-v7a ABIs.
19+
// We check only the first ABI in SUPPORTED_ABIS because the first one is most preferred ABI.
20+
private val isABIArmeabi: Boolean by lazy {
21+
Build.SUPPORTED_ABIS?.firstOrNull()
22+
?.lowercase()
23+
?.contains("armeabi") == true
24+
}
25+
26+
/**
27+
* Executes the given block and logs any uncaught exceptions using Android logger to protect
28+
* against unexpected crashes and failures.
29+
*/
30+
private fun runWithTryCatch(action: () -> Unit) {
31+
try {
32+
action()
33+
} catch (ex: Exception) {
34+
// Use Android logger to avoid cyclic calls from internal SDK logging
35+
Log.e("[CIO]", "Error in NativeCustomerIOLoggingModule: ${ex.message}", ex)
36+
}
37+
}
38+
39+
/**
40+
* Executes the given action only if the current ABI supports it.
41+
* Skips execution on armeabi/armeabi-v7a to prevent C++ crashes on unsupported architectures.
42+
*/
43+
private fun runOnSupportedAbi(action: () -> Unit) {
44+
runWithTryCatch {
45+
if (isABIArmeabi) {
46+
// Skip execution on armeabi-v7a to avoid known native (C++) crashes on unsupported ABIs.
47+
// This ensures stability on lower-end or legacy devices by preventing risky native calls.
48+
return@runWithTryCatch
49+
}
50+
51+
action()
52+
}
53+
}
54+
1655
override fun initialize() {
17-
super.initialize()
18-
NativeCustomerIOLoggingModuleImpl.setLogEventEmitter { data ->
19-
emitOnCioLogEvent(data)
56+
runWithTryCatch {
57+
super.initialize()
58+
if (isABIArmeabi) {
59+
Log.i(
60+
"[CIO]",
61+
"Native logging is disabled on armeabi/armeabi-v7a ABI to avoid native crashes (Supported ABIs: ${Build.SUPPORTED_ABIS?.joinToString()})"
62+
)
63+
}
64+
runOnSupportedAbi {
65+
NativeCustomerIOLoggingModuleImpl.setLogEventEmitter { data ->
66+
emitOnCioLogEvent(data)
67+
}
68+
}
2069
}
2170
}
2271

2372
override fun invalidate() {
24-
NativeCustomerIOLoggingModuleImpl.invalidate()
25-
super.invalidate()
73+
runOnSupportedAbi {
74+
NativeCustomerIOLoggingModuleImpl.invalidate()
75+
}
76+
runWithTryCatch {
77+
super.invalidate()
78+
}
2679
}
2780

2881
override fun addListener(eventName: String?) {
29-
onlyForLegacyArch("addListener")
82+
runOnSupportedAbi {
83+
onlyForLegacyArch("addListener")
84+
}
3085
}
3186

3287
override fun removeListeners(count: Double) {
33-
onlyForLegacyArch("removeListeners")
88+
runOnSupportedAbi {
89+
onlyForLegacyArch("removeListeners")
90+
}
3491
}
3592
}

example/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)