运行此命令时出现这些错误
flutter run --flavor development -t lib/config/main_development.dart --verbose-system-logs
错误:Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@b5226bb) but could not find and invoke the GeneratedPluginRegistrant.
E/flutter (28896): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel flutter_stetho)
flutter 医生输出:➜ flutter doctor -v
[✓] Flutter (Channel master, 1.20.0-8.0.pre.22, on Mac OS X 10.14.6 18G3020, locale en)
• Flutter version 1.20.0-8.0.pre.22 at /Users/vedantrathore/tools/flutter
• Framework revision 61a04b1551 (11 hours ago), 2020-07-09 15:52:19 +0800
• Engine revision 0ec6f6c3f2
• Dart version 2.9.0 (build 2.9.0-20.0.dev 06cb010247)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/vedantrathore/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.46.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.12.1
[✓] Connected device (1 available)
• GM1901 (mobile) • 192.168.29.75:5555 • android-arm64 • Android 10 (API 29)
• No issues found!
这是我的 app/build.gradle 文件def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.habitwave"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
}
debug{
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "flutter-flavours"
productFlavors{
development{
dimension "flutter-flavours"
versionNameSuffix "-dev"
}
staging{
dimension "flutter-flavours"
versionNameSuffix "-stg"
}
production{
dimension "flutter-flavours"
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
我正在尝试使用flutter_secure_storage包,因此我必须将minSdkVersion设置为18并使用Proguard规则来避免multiDex(因为这需要minSdkVersion 21)我尝试过的解决方案:
flutter clean
, 卸载应用程序, 清除 ~/.pub-cache
编辑 :
我通过深入研究解决了这个问题,并在 Android Studio 中打开了应用程序,进入了 Flutter 实现 Activity 并设置了一个断点,它尝试注册插件,然后当我运行应用程序时,我发现错误是 FacebookSdk 是'没有初始化。我正在使用 pub.dev/packages/flutter_facebook_login 包并忘记了 android 初始化。可以改进错误处理以适应这些场景
最佳答案
今天我面临同样的问题。我认为这与此有关:
https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration
(这可能只是临时解决方案)
我将注册人回信给我的MainActivity.kt
- 如果你的类(class)是空的,它可能会有所帮助
package your.package.name
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
关于android - Flutter:尝试向 FlutterEngine 自动注册插件,但找不到并调用 GeneratedPluginRegistrant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62821618/