1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flutter 2系からFlutter 3系へ Android ビルドエラー

Posted at

[ エラー文 ]

abstract and does not implement abstract member public abstract fun error(p0: String, p1: String?, p2: Any?): Unit defined in io.flutter.plugin.common.MethodChannel.Result

[ エラーコード ]

android/app/src/main/kotlin/XXXX/MainActivity.kt

private fun onDataUpdated(type: String) {
        channel.invokeMethod("onDataUpdated", type, object : MethodChannel.Result {
            override fun success(result: Any?) {
                Log.d("Android", "result = $result")
            }
            override fun error(errorCode: String?, errorMessage: String?, errorDetails: Any?) {
                Log.d("Android", "$errorCode, $errorMessage, $errorDetails")
            }
            override fun notImplemented() {
                Log.d("Android", "notImplemented")
            }
        })
    }

override fun error()でエラーが発生していました。

[ 修正 ]

FlutterSecureStoragePlugin.java
static class MethodResultWrapper implements Result {

    private final Result methodResult;
    private final Handler handler = new Handler(Looper.getMainLooper());

    MethodResultWrapper(Result methodResult) {
        this.methodResult = methodResult;
    }

    @Override
    public void success(final Object result) {
        handler.post(() -> methodResult.success(result));
    }

    @Override
    public void error(@NonNull final String errorCode, final String errorMessage, final Object errorDetails) {
        handler.post(() -> methodResult.error(errorCode, errorMessage, errorDetails));
    }

    @Override
    public void notImplemented() {
        handler.post(methodResult::notImplemented);
    }
}

void errorの第一引数がNonNullになっています。
しかしoverride fun error(errorCode: String?, errorMessage: String?, errorDetails: Any?)の第一引数がerrorCode: String?になっています。

android/app/src/main/kotlin/XXXX/MainActivity.kt

private fun onDataUpdated(type: String) {
           //省略
            override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
                Log.d("Android", "$errorCode, $errorMessage, $errorDetails")
            }
            //省略
        })
    }

これで無事ビルドが通りました!

[ 最後に ]

誰かのお役に立てば幸いです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?