Calling peripheral(advertisement) never completes in a shared module targetting Android
See original GitHub issueWe have quite easily passed a Kable advertisement into the Kable-supplied CoroutineScope.peripheral
extension function, with good results, in an ordinary Kotlin Multiplatform app (deploying to Android), with our successes being where we have coded such calls into the shared module of the Kotlin Multiplatform project itself.
However when we code the same calls into a module that we retrieve from mavenLocal(), it never completes.
Looking at the following:
override suspend fun getPeripheral(kableAdvertisement: com.juul.kable.Advertisement): Peripheral? {
var kableperipheral: com.juul.kable.Peripheral? = null
coroutineScope {
println("***BLE: BLESCANNER BEFORE")
val myperipheral = peripheral(kableAdvertisement)
println("***BLE: BLESCANNER AFTER 1")
kableperipheral = myperipheral
println("***BLE: BLESCANNER AFTER 2")
}
println("***BLE: BLESCANNER AFTER 3")
return kableperipheral
}
all of the println statements appear in the logcat console, doing so when we run this code in the shared module of the Kotlin Multiplatform app. (The override comes from the interface we declare as a good practice, nothing unusual here.)
However if we run this exact same code in a module that we have created separately and pulled in from mavenLocal() and also deploying to Android, the last println that actually prints in logcat is ***BLE: BLESCANNER BEFORE
We’ve tried many scope patterns and yet it continues to fail.
We’ve looked at the actual extension function within Kable itself that translates the expect call into it’s Android actual counterpart, and everything looks normal, vis-a-vis:
androidMain/…/Peripheral.kt starting at line 88:
public actual fun CoroutineScope.peripheral(
advertisement: Advertisement,
builderAction: PeripheralBuilderAction,
): Peripheral = peripheral(advertisement.bluetoothDevice, builderAction)
public fun CoroutineScope.peripheral(
bluetoothDevice: BluetoothDevice,
builderAction: PeripheralBuilderAction = {},
): Peripheral {
val builder = PeripheralBuilder()
builder.builderAction()
return AndroidPeripheral(
coroutineContext,
bluetoothDevice,
builder.transport,
builder.phy,
builder.observationExceptionHandler,
builder.onServicesDiscovered,
builder.logging,
)
}
public fun CoroutineScope.peripheral(
identifier: Identifier,
builderAction: PeripheralBuilderAction = {},
): Peripheral {
val bluetoothDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(identifier)
return peripheral(bluetoothDevice, builderAction)
}
Any ideas???
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
@twyatt Problem solved, thank you!
Your comment led to us doing a version audit of absolutely everything, and in that we picked up that where on one hand we had recently upgraded kotlin to version 1.6.21, we had left com.benasher44.uuid at version 0.4.0 and yet we needed to upgrade it to 0.4.1 for it’s version that runs on kotlin 1.6.21
Merely advancing the version from 0.4.0 to 0.4.1 solved the problem.
I am of course dismayed that ./gradlew builds did not point out this version mismatch in recent days, but given that we now realise that it wont necessarily identify version mismatches, we are adding a new version audit playbook to how we monitor versioning.
Thanks so much for your help!
@twyatt Thanks, good idea, we had this working in it’s own module in a very thorough POC a year ago, we’re just going through both the kotlin and kable updates since to see if there has been a breaking change that affects the POC build, I’ll update the issue with that investigation outcome, once done! The essential difference between the two projects is just that the POC of a year ago used DI (koin) where this one does not.