Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample Code in README Causes Crash on Android #147

Open
jarvislin opened this issue Jan 14, 2025 · 0 comments
Open

Sample Code in README Causes Crash on Android #147

jarvislin opened this issue Jan 14, 2025 · 0 comments

Comments

@jarvislin
Copy link

Hi folks,

I copied the sample code from the README and implemented it in my Compose Multiplatform project. While the code runs smoothly on iOS, it causes the Android app to crash at runtime.

Version:

dev.icerock.moko:permissions-compose:0.18.1

Code snippet:

@Composable
fun Sample() {
    val factory: PermissionsControllerFactory = rememberPermissionsControllerFactory()
    val controller: PermissionsController = remember(factory) { factory.createPermissionsController() }
    val coroutineScope: CoroutineScope = rememberCoroutineScope()
    
    Button(
        onClick = {
            coroutineScope.launch {
                controller.providePermission(Permission.RECORD_AUDIO)
            }
        }
    ) {
        Text(text = "give permissions")
    }
}

Steps to reproduce:

  1. Copy the above sample code.
  2. Add the code to a Compose Multiplatform project.
  3. Run the app on an Android device.
  4. Click on the button.

Expected behavior:

The sample code should work as intended on both iOS and Android without issues.

Actual behavior:

iOS: The app runs as expected.
Android: The app crashes at runtime.

Error log:

java.lang.IllegalStateException: activityResultLauncher is null, `bind` function was never called, consider calling permissionsController.bind(activity) or BindEffect(permissionsController) in the composable function, check the documentation for more info: https://github.com/icerockdev/moko-permissions/blob/master/README.md
                                                                                                    	at dev.icerock.moko.permissions.PermissionsControllerImpl.awaitActivityResultLauncher(PermissionsControllerImpl.kt:129)
                                                                                                    	at dev.icerock.moko.permissions.PermissionsControllerImpl.access$awaitActivityResultLauncher(PermissionsControllerImpl.kt:34)

Please let me know if additional logs or information are needed to help resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant