请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

registrarFor方法找不到

图片描述
我这个activity默认重写的是configureFlutterEngine方法不是oncreate方法,而且下面的registrarFor方法也提示不存在

正在回答

1回答

CrazyCodeBoy 2020-01-15 20:50:21

Flutter 版本不对应导致的:

//将:
package org.devio.fluttertrip;

import android.os.Bundle;

import org.devio.flutter.plugin.asr.AsrPlugin;
import org.devio.flutter.splashscreen.SplashScreen;

import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this,true);
        super.onCreate(savedInstanceState);
        GeneratedPluginRegistrant.registerWith(this);
        registerSelfPlugin();
    }

    private void registerSelfPlugin() {
        AsrPlugin.registerWith(registrarFor("org.devio.flutter.plugin.asr.AsrPlugin"));
    }
}
//改成
package org.devio.fluttertrip;

import android.os.Bundle;

import org.devio.flutter.plugin.asr.AsrPlugin;
import org.devio.flutter.splashscreen.SplashScreen;

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
        //flutter sdk >= v1.12.13+hotfix.5 时使用下面方法注册自定义plugin
        ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
        AsrPlugin.registerWith(shimPluginRegistry.registrarFor("org.devio.flutter.plugin.asr.AsrPlugin"));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this, true);
        super.onCreate(savedInstanceState);
    }
}

即可。

1 回复 有任何疑惑可以回复我~
  • 提问者 慕粉1156554542 #1
    非常感谢!
    回复 有任何疑惑可以回复我~ 2020-01-16 20:02:20
  • 这种写法也报错:flutter 版本1.17.2
    W/FlutterEnginePluginRegistry(23034): Attempted to register plugin (io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry$ShimRegistrarAggregate@ea8d42f) but it was already registered with this FlutterEngine (io.flutter.embedding.engine.FlutterEngine@9e2da3c).
    回复 有任何疑惑可以回复我~ 2020-06-06 16:26:54
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信