Skip to content

Commit 96459e9

Browse files
authored
Merge pull request #2136 from OneSignal/fix/minification_missing_stubs
[Fix] "could not be instantiated" exception when; some modules are omitted AND android.enableR8.fullMode=true
2 parents 08c0f30 + 61590d2 commit 96459e9

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

OneSignalSDK/onesignal/core/consumer-rules.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
-keepclassmembers class com.onesignal.common.** { *; }
1616

17-
-keep class ** implements com.onesignal.common.modules.IModule { *; }
17+
-keepclassmembers @com.onesignal.core.internal.minification.KeepStub class * { <init>(...); }
18+
19+
-keep class ** implements com.onesignal.common.modules.IModule { *; }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.onesignal.core.internal.minification
2+
3+
/**
4+
* Purpose: Use on stub classes that are expected to always exists when
5+
* aggressive minification is enabled on the app.
6+
* - Such as android.enableR8.fullMode.
7+
*/
8+
annotation class KeepStub

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/inAppMessages/internal/MisconfiguredIAMManager.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.onesignal.inAppMessages.internal
22

3+
import com.onesignal.core.internal.minification.KeepStub
34
import com.onesignal.inAppMessages.IInAppMessageClickListener
45
import com.onesignal.inAppMessages.IInAppMessageLifecycleListener
56
import com.onesignal.inAppMessages.IInAppMessagesManager
67

78
/**
8-
* The misconfigured IAMManager is an implementation of [IInAppMessagesManager] that warns the user they
9-
* have not included the appropriate IAM module.
9+
* The misconfigured IAMManager is an implementation of [IInAppMessagesManager]
10+
* that warns the dev they have not included the appropriate IAM module.
1011
*/
12+
@KeepStub
1113
internal class MisconfiguredIAMManager : IInAppMessagesManager {
1214
override var paused: Boolean
1315
get() = throw EXCEPTION
@@ -35,7 +37,7 @@ internal class MisconfiguredIAMManager : IInAppMessagesManager {
3537
override fun removeClickListener(listener: IInAppMessageClickListener) = throw EXCEPTION
3638

3739
companion object {
38-
private val EXCEPTION: Throwable get() =
40+
private val EXCEPTION get() =
3941
Exception(
4042
"Must include gradle module com.onesignal:InAppMessages in order to use this functionality!",
4143
)
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.onesignal.location.internal
22

3+
import com.onesignal.core.internal.minification.KeepStub
34
import com.onesignal.location.ILocationManager
45

56
/**
6-
* The misconfigured IAMManager is an implementation of [ILocationManager] that warns the user they
7+
* The misconfigured IAMManager is an implementation of [ILocationManager] that warns the dev they
78
* have not included the appropriate location module.
89
*/
10+
@KeepStub
911
internal class MisconfiguredLocationManager : ILocationManager {
1012
override var isShared: Boolean
1113
get() = throw EXCEPTION
1214
set(value) = throw EXCEPTION
1315

14-
override suspend fun requestPermission(): Boolean = throw EXCEPTION
16+
override suspend fun requestPermission() = throw EXCEPTION
1517

1618
companion object {
17-
private val EXCEPTION = Exception("Must include gradle module com.onesignal:Location in order to use this functionality!")
19+
private val EXCEPTION get() = Exception("Must include gradle module com.onesignal:Location in order to use this functionality!")
1820
}
1921
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/notifications/internal/MisconfiguredNotificationsManager.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package com.onesignal.notifications.internal
22

3+
import com.onesignal.core.internal.minification.KeepStub
34
import com.onesignal.notifications.INotificationClickListener
45
import com.onesignal.notifications.INotificationLifecycleListener
56
import com.onesignal.notifications.INotificationsManager
67
import com.onesignal.notifications.IPermissionObserver
78

89
/**
9-
* The misconfigured NotificationsManager is an implementation of [INotificationsManager] that warns the user they
10-
* have not included the appropriate notifications module.
10+
* The misconfigured NotificationsManager is an implementation of
11+
* [INotificationsManager] that warns the dev they have not included the
12+
* appropriate notifications module.
1113
*/
14+
@KeepStub
1215
internal class MisconfiguredNotificationsManager : INotificationsManager {
13-
override val permission: Boolean
16+
override val permission
1417
get() = throw EXCEPTION
15-
override val canRequestPermission: Boolean
18+
override val canRequestPermission
1619
get() = throw EXCEPTION
1720

18-
override suspend fun requestPermission(fallbackToSettings: Boolean): Boolean = throw EXCEPTION
21+
override suspend fun requestPermission(fallbackToSettings: Boolean) = throw EXCEPTION
1922

2023
override fun removeNotification(id: Int) = throw EXCEPTION
2124

@@ -36,6 +39,6 @@ internal class MisconfiguredNotificationsManager : INotificationsManager {
3639
override fun removeClickListener(listener: INotificationClickListener) = throw EXCEPTION
3740

3841
companion object {
39-
private val EXCEPTION = Exception("Must include gradle module com.onesignal:Notification in order to use this functionality!")
42+
private val EXCEPTION get() = Exception("Must include gradle module com.onesignal:Notification in order to use this functionality!")
4043
}
4144
}

0 commit comments

Comments
 (0)