Skip to content

Colota - Android GPS Location tracker

refactor(android): clear deprecation warnings in app code and build.gradle (#1009)

Max Dietrich3d56451552a6
diff --git a/apps/mobile/android/app/build.gradle b/apps/mobile/android/app/build.gradle
index bbc4144b..bb305147 100644
--- a/apps/mobile/android/app/build.gradle
+++ b/apps/mobile/android/app/build.gradle
@@ -78,7 +78,7 @@ def isHermesEnabled = project.findProperty('hermesEnabled') == 'true'
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'
android {
- ndkVersion rootProject.ext.ndkVersion
+ ndkVersion = rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion
@@ -89,7 +89,7 @@ android {
includeInBundle = false
}
- namespace "com.Colota"
+ namespace = "com.Colota"
defaultConfig {
applicationId "com.Colota"
minSdkVersion rootProject.ext.minSdkVersion
@@ -137,14 +137,14 @@ android {
buildTypes {
debug {
- signingConfig signingConfigs.debug
+ signingConfig = signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
- signingConfig signingConfigs.release
+ signingConfig = signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
- shrinkResources false // Disabled for reproducible builds
+ shrinkResources = false // Disabled for reproducible builds
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
@@ -172,8 +172,8 @@ android {
abi {
reset()
// Disable ABI splits for bundle tasks (AABs handle this natively)
- enable !gradle.startParameter.taskNames.any { it.toLowerCase().contains("bundle") }
- universalApk false
+ enable = !gradle.startParameter.taskNames.any { it.toLowerCase().contains("bundle") }
+ universalApk = false
include "arm64-v8a", "armeabi-v7a", "x86_64", "x86"
}
}
diff --git a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt
index 31a5d335..3d71e298 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt
@@ -147,7 +147,7 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :
private inline fun emit(event: String, build: WritableMap.() -> Unit): Boolean {
val context = reactContextRef.get() ?: return false
- if (!context.hasActiveCatalystInstance()) return false
+ if (!context.hasActiveReactInstance()) return false
return try {
val params = Arguments.createMap().apply(build)
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
diff --git a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServicePackage.kt b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServicePackage.kt
index c79069d1..77e58481 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServicePackage.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServicePackage.kt
@@ -18,7 +18,10 @@ class LocationServicePackage : ReactPackage {
/**
* Registers the Native Modules provided by this package.
+ * Stays on the legacy ReactPackage path: BaseReactPackage creates modules lazily, and
+ * LocationServiceModule must hold the context before the service emits.
*/
+ @Suppress("OVERRIDE_DEPRECATION")
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf(
LocationServiceModule(reactContext),
diff --git a/apps/mobile/android/app/src/main/java/com/colota/util/ApplicationLogging.kt b/apps/mobile/android/app/src/main/java/com/colota/util/ApplicationLogging.kt
index f4ff387d..a4e158c6 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/util/ApplicationLogging.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/util/ApplicationLogging.kt
@@ -38,11 +38,13 @@ object FileLoggerInitializer {
}
/** Logs the actual `onTrimMemory` pressure levels (RUNNING_* and COMPLETE). Skips
- * UI_HIDDEN / BACKGROUND / MODERATE since those fire on every backgrounding. */
+ * UI_HIDDEN / BACKGROUND / MODERATE since those fire on every backgrounding.
+ * Android stops sending these levels from API 34, so it logs on Android 13 and below only. */
object MemoryPressureLogger {
private const val TAG = "MainApp"
+ @Suppress("DEPRECATION")
fun log(level: Int) {
val name = when (level) {
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL -> "RUNNING_CRITICAL"
diff --git a/apps/mobile/android/app/src/test/java/com/Colota/bridge/LocationServiceModuleTest.kt b/apps/mobile/android/app/src/test/java/com/Colota/bridge/LocationServiceModuleTest.kt
index ca207491..46903493 100644
--- a/apps/mobile/android/app/src/test/java/com/Colota/bridge/LocationServiceModuleTest.kt
+++ b/apps/mobile/android/app/src/test/java/com/Colota/bridge/LocationServiceModuleTest.kt
@@ -43,7 +43,6 @@ import java.util.concurrent.TimeUnit
* - Conditional service action dispatch (triggerProfileRecheck, refreshNotificationIfTracking)
* - CRUD side effects (cache invalidation + recheck triggers)
*/
-@Suppress("DEPRECATION")
class LocationServiceModuleTest {
private lateinit var mockContext: ReactApplicationContext
@@ -53,7 +52,7 @@ class LocationServiceModuleTest {
fun setUp() {
mockEmitter = mockk(relaxed = true)
mockContext = mockk(relaxed = true) {
- every { hasActiveCatalystInstance() } returns true
+ every { hasActiveReactInstance() } returns true
every { getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) } returns mockEmitter
}
@@ -123,8 +122,8 @@ class LocationServiceModuleTest {
}
@Test
- fun `sendLocationEvent returns false when no active catalyst`() {
- every { mockContext.hasActiveCatalystInstance() } returns false
+ fun `sendLocationEvent returns false when no active react instance`() {
+ every { mockContext.hasActiveReactInstance() } returns false
assertFalse(LocationServiceModule.sendLocationEvent(mockLocation(), 85, 2))
}
@@ -159,8 +158,8 @@ class LocationServiceModuleTest {
}
@Test
- fun `sendTrackingStoppedEvent returns false when no catalyst`() {
- every { mockContext.hasActiveCatalystInstance() } returns false
+ fun `sendTrackingStoppedEvent returns false when no active react instance`() {
+ every { mockContext.hasActiveReactInstance() } returns false
assertFalse(LocationServiceModule.sendTrackingStoppedEvent("reason"))
}
@@ -290,8 +289,8 @@ class LocationServiceModuleTest {
}
@Test
- fun `sendAutoExportEvent returns false when no catalyst`() {
- every { mockContext.hasActiveCatalystInstance() } returns false
+ fun `sendAutoExportEvent returns false when no active react instance`() {
+ every { mockContext.hasActiveReactInstance() } returns false
assertFalse(LocationServiceModule.sendAutoExportEvent(true, "file.csv", 10, null))
}
@@ -312,8 +311,8 @@ class LocationServiceModuleTest {
}
@Test
- fun `sendPauseZoneEvent returns false when no catalyst`() {
- every { mockContext.hasActiveCatalystInstance() } returns false
+ fun `sendPauseZoneEvent returns false when no active react instance`() {
+ every { mockContext.hasActiveReactInstance() } returns false
assertFalse(LocationServiceModule.sendPauseZoneEvent(true, "Office"))
}
@@ -340,8 +339,8 @@ class LocationServiceModuleTest {
}
@Test
- fun `sendChargingStateEvent returns false when no catalyst`() {
- every { mockContext.hasActiveCatalystInstance() } returns false
+ fun `sendChargingStateEvent returns false when no active react instance`() {
+ every { mockContext.hasActiveReactInstance() } returns false
assertFalse(LocationServiceModule.sendChargingStateEvent(true))
}