Skip to content

Commit

Permalink
Merge pull request #2136 from OneSignal/fix/minification_missing_stubs
Browse files Browse the repository at this point in the history
[Fix] "could not be instantiated" exception when; some modules are omitted AND android.enableR8.fullMode=true
  • Loading branch information
jkasten2 authored Jun 27, 2024
2 parents 08c0f30 + 61590d2 commit 96459e9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
4 changes: 3 additions & 1 deletion OneSignalSDK/onesignal/core/consumer-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

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

-keep class ** implements com.onesignal.common.modules.IModule { *; }
-keepclassmembers @com.onesignal.core.internal.minification.KeepStub class * { <init>(...); }

-keep class ** implements com.onesignal.common.modules.IModule { *; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.onesignal.core.internal.minification

/**
* Purpose: Use on stub classes that are expected to always exists when
* aggressive minification is enabled on the app.
* - Such as android.enableR8.fullMode.
*/
annotation class KeepStub
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.onesignal.inAppMessages.internal

import com.onesignal.core.internal.minification.KeepStub
import com.onesignal.inAppMessages.IInAppMessageClickListener
import com.onesignal.inAppMessages.IInAppMessageLifecycleListener
import com.onesignal.inAppMessages.IInAppMessagesManager

/**
* The misconfigured IAMManager is an implementation of [IInAppMessagesManager] that warns the user they
* have not included the appropriate IAM module.
* The misconfigured IAMManager is an implementation of [IInAppMessagesManager]
* that warns the dev they have not included the appropriate IAM module.
*/
@KeepStub
internal class MisconfiguredIAMManager : IInAppMessagesManager {
override var paused: Boolean
get() = throw EXCEPTION
Expand Down Expand Up @@ -35,7 +37,7 @@ internal class MisconfiguredIAMManager : IInAppMessagesManager {
override fun removeClickListener(listener: IInAppMessageClickListener) = throw EXCEPTION

companion object {
private val EXCEPTION: Throwable get() =
private val EXCEPTION get() =
Exception(
"Must include gradle module com.onesignal:InAppMessages in order to use this functionality!",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.onesignal.location.internal

import com.onesignal.core.internal.minification.KeepStub
import com.onesignal.location.ILocationManager

/**
* The misconfigured IAMManager is an implementation of [ILocationManager] that warns the user they
* The misconfigured IAMManager is an implementation of [ILocationManager] that warns the dev they
* have not included the appropriate location module.
*/
@KeepStub
internal class MisconfiguredLocationManager : ILocationManager {
override var isShared: Boolean
get() = throw EXCEPTION
set(value) = throw EXCEPTION

override suspend fun requestPermission(): Boolean = throw EXCEPTION
override suspend fun requestPermission() = throw EXCEPTION

companion object {
private val EXCEPTION = Exception("Must include gradle module com.onesignal:Location in order to use this functionality!")
private val EXCEPTION get() = Exception("Must include gradle module com.onesignal:Location in order to use this functionality!")
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.onesignal.notifications.internal

import com.onesignal.core.internal.minification.KeepStub
import com.onesignal.notifications.INotificationClickListener
import com.onesignal.notifications.INotificationLifecycleListener
import com.onesignal.notifications.INotificationsManager
import com.onesignal.notifications.IPermissionObserver

/**
* The misconfigured NotificationsManager is an implementation of [INotificationsManager] that warns the user they
* have not included the appropriate notifications module.
* The misconfigured NotificationsManager is an implementation of
* [INotificationsManager] that warns the dev they have not included the
* appropriate notifications module.
*/
@KeepStub
internal class MisconfiguredNotificationsManager : INotificationsManager {
override val permission: Boolean
override val permission
get() = throw EXCEPTION
override val canRequestPermission: Boolean
override val canRequestPermission
get() = throw EXCEPTION

override suspend fun requestPermission(fallbackToSettings: Boolean): Boolean = throw EXCEPTION
override suspend fun requestPermission(fallbackToSettings: Boolean) = throw EXCEPTION

override fun removeNotification(id: Int) = throw EXCEPTION

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

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

0 comments on commit 96459e9

Please sign in to comment.