Flutter

flutter Class 'SoundStreamPlugin' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult

닥치고개발 2023. 3. 11. 00:13
728x90

flutter에서 sound_stream: ^0.3.0 추가한후에 아래와 같은 안드로이드 빌드 오류가 발생했다.

Androd에서 코드만 수정해주면 된다.

Class 'SoundStreamPlugin' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult

  • 실기기에서 동작했으며, 아래와 같이 오류 코드 발생
Launching lib/main.dart on SM G998N in debug mode...
Running Gradle task 'assembleDebug'...
e: /Users/qualson/.pub-cache/hosted/pub.dev/sound_stream-0.3.0/android/src/main/kotlin/vn/casperpas/sound_stream/SoundStreamPlugin.kt: (45, 8): Class 'SoundStreamPlugin' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult(p0: Int, p1: Array<(out) String!>, p2: IntArray): Boolean defined in io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener
e: /Users/qualson/.pub-cache/hosted/pub.dev/sound_stream-0.3.0/android/src/main/kotlin/vn/casperpas/sound_stream/SoundStreamPlugin.kt: (182, 5): 'onRequestPermissionsResult' overrides nothing

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sound_stream:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
Exception: Gradle task assembleDebug failed with exit code 1

해결책

  • 오류에 나와있는 아래 경로 파일을 열어서 아래와 같이 수정한다.
  • grantResults: IntArray? 옵셔널로 되어있는 것을 ?를 지운다.
  • /Users/qualson/.pub-cache/hosted/pub.dev/sound_stream-0.3.0/android/src/main/kotlin/vn/casperpas/sound_stream/SoundStreamPlugin.kt

문제가 발생하는 코드 (수정전)

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?,
                                            grantResults: IntArray?): Boolean {
        when (requestCode) {
            audioRecordPermissionCode -> {
                if (grantResults != null) {
                    permissionToRecordAudio = grantResults.isNotEmpty() &&
                            grantResults[0] == PackageManager.PERMISSION_GRANTED
                }
                completeInitializeRecorder()
                return true
            }
        }
        return false
    }

문제가 발생하는 코드 (수정후)

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>,
                                            grantResults: IntArray): Boolean {
        when (requestCode) {
            audioRecordPermissionCode -> {
                if (grantResults != null) {
                    permissionToRecordAudio = grantResults.isNotEmpty() &&
                            grantResults[0] == PackageManager.PERMISSION_GRANTED
                }
                completeInitializeRecorder()
                return true
            }
        }
        return false
    }
728x90