Mathieu C么t茅
09/10/2024, 12:04 PM2.0.0
where some of our `addEventListener`/`removeEventListener` that are coming from an external definition (IMA SDK or FreeWheel SDK mapping) are removed at transpilation from Kotlin to JS and replaced by a throwLinkageError
with message:
Function 'addEventListener' can not be called: No function found for symbol 'googleima/Google.Ima.AdsLoader.addEventListener|addEventListener(kotlin.String;kotlin.Function1<kotlin.Nothing?,kotlin.Unit>;kotlin.Boolean){}[0]'
It only occurs on transpilation following code modification within the class that uses the external definition mapping, and disappear following these 2 steps: a clean up (gradle intensifies clean and a removal of the kotlin-js-store
folders) and a simple new line added to the current code base.
It is very strange, we cannot for the love of god isolate it to a simple test projet, it only do that within our huge code base. Any idea if this is known or if there is a possible workaround?
P.S.: attached more details in 馃У 馃憠Mathieu C么t茅
09/10/2024, 12:04 PMpackage googleima
@JsName("google")
external object Google {
@JsName("ima")
object Ima {
class AdsRequest {
var adTagUrl: String?
var vastLoadTimeout: Double?
fun setAdWillAutoPlay(value: Boolean)
fun setAdWillPlayMuted(value: Boolean)
}
class AdsManager {
fun addEventListener(event: String, callback: (event: dynamic) -> Unit, useCapture: Boolean = definedExternally)
fun removeEventListener(event: String, callback: (event: dynamic) -> Unit)
}
}
}
Mathieu C么t茅
09/10/2024, 12:05 PMMathieu C么t茅
09/10/2024, 12:06 PMMathieu C么t茅
09/10/2024, 12:08 PMprivate var onAdStartedReference: ((event: Google.Ima.AdEvent) -> Unit)? = null
private fun setUpAdsManagerEventListeners(adsManager: Google.Ima.AdsManager) {
onAdStartedReference = { onAdStarted(it) }
adsManager.addEventListener(Google.Ima.AdEvent.Type.STARTED, onAdStartedReference!!)
}
private fun removeAdsManagerEventListeners(adsManager: Google.Ima.AdsManager) {
onAdStartedReference?.let { adsManager.removeEventListener(Google.Ima.AdEvent.Type.STARTED, it) }
}
private fun onAdStarted(event: Google.Ima.AdEvent) {
}
Edoardo Luppi
09/10/2024, 5:13 PMMathieu C么t茅
09/10/2024, 5:52 PMturansky
09/11/2024, 11:04 AMdynamic
usage from callbacks 馃槈turansky
09/11/2024, 11:06 AMdynamic
in externals.
In most cases Any?
is what you need instead.Mathieu C么t茅
09/11/2024, 5:29 PMEdoardo Luppi
09/11/2024, 5:30 PMMathieu C么t茅
09/11/2024, 5:31 PMEdoardo Luppi
09/11/2024, 5:32 PMMathieu C么t茅
09/11/2024, 5:32 PMMathieu C么t茅
09/11/2024, 6:12 PMprivate fun onAdError(event: Any) {
val errorEvent = event as Google.Ima.AdErrorEvent
}
Edoardo Luppi
09/11/2024, 6:14 PMevent
be better typed, or is Any
the only way to do it?Mathieu C么t茅
09/11/2024, 6:21 PMprivate var onFreeWheelRequestCompleteReference: ((event: FreeWheel.SDK.RequestCompleteEvent) -> Unit)? = null
private var onFreeWheelSlotStartedReference: ((event: FreeWheel.SDK.SlotEvent) -> Unit)? = null
private var onFreeWheelSlotEndedReference: ((event: FreeWheel.SDK.SlotEvent) -> Unit)? = null
Because of this, I was using dynamic in the external definition. Using Any now, forces us to do the cast as mentioned above.
These 2 types are objects like this:
object RequestCompleteEvent {
val type: String
val target: Context
val success: Boolean
}
object SlotEvent {
val type: String
val target: Context
val slot: Slot
}
Edoardo Luppi
09/11/2024, 6:22 PMonAdError
called?Mathieu C么t茅
09/11/2024, 6:23 PMMathieu C么t茅
09/11/2024, 6:24 PMobject AdErrorEvent {
fun getError(): AdError
fun getUserRequestContext(): Any
}
object AdEvent {
val type: String
fun getAd(): Ad?
fun getAdData(): AdData?
}
Edoardo Luppi
09/11/2024, 6:28 PMEdoardo Luppi
09/11/2024, 6:29 PMEdoardo Luppi
09/11/2024, 6:34 PMturansky
09/11/2024, 6:35 PMEdoardo Luppi
09/11/2024, 6:36 PMMathieu C么t茅
09/11/2024, 7:08 PMMathieu C么t茅
09/11/2024, 7:42 PM