question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling peripheral(advertisement) never completes in a shared module targetting Android

See original GitHub issue

We 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:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
HarrisonOfTheNorthcommented, Jun 17, 2022

@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!

1reaction
HarrisonOfTheNorthcommented, Jun 17, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bluetooth permissions - Android Developers
System permissions dialog, asking the user to grant an app permission to discover, advertise, and connect to nearby devices. If your app targets...
Read more >
The Ultimate Guide to Android Bluetooth Low Energy
The most common behavior is that when a BLE device is connected to a central, it'll stop advertising as a peripheral because it's...
Read more >
Privacy‐preserving targeted mobile advertising: requirements ...
Therefore, a third-party permission framework is still necessary for a large number of devices that cannot be updated to Android 6.0. Second, ...
Read more >
Digital Marketing | The Complete Google Ads Masterclass ...
Let's Build a Successful Google Ads Strategy Together, Step by Step! In The Complete Google Ads Masterclass (Former Google AdWords) you'll learn to...
Read more >
UM1718 User manual - STM32CubeMX for STM32 ...
Easy microcontroller configuration (pins, clock tree, peripherals, middleware) and generation of the corresponding initialization C code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found