【问题标题】:flutter MissingPluginException颤振 MissingPluginException
【发布时间】:2021-04-11 16:20:57
【问题描述】:

MissingPluginException(MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实现

我正在尝试在 Flutter 应用程序中连接到 firebase。这是什么错误? 我用 vs 代码开发 这是我的代码

    **main.dart**
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:mybagapp/src/app.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(App());
}


    **main.dart**
    import 'package:firebase_core/firebase_core.dart';
    import 'package:flutter/material.dart';
    import 'package:mybagapp/src/app.dart';
    
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp();
      runApp(App());
    }

    **android/build.grader**
    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.4'
        }
    }

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

**android/app/build.grade**
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'
}

    enter code here

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'  // Google Services plugin
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    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.julow.mybagapp"
        minSdkVersion 21
        targetSdkVersion 29
        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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

**pubspec.yaml**
dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.0
  firebase_core: ^0.5.3
  cloud_firestore: ^0.14.4

我确实清理过它没有用

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    试试这个,卸载应用=>flutter clean =>重新运行

    【讨论】:

      【解决方案2】:

      每次在 pubspec.yaml 中包含任何新插件时:

      1. 在您的设备或模拟器(如果存在)中终止已构建的应用程序
      2. 颤振干净
      3. 颤振构建

      【讨论】:

        【解决方案3】:

        当我为 firebase 或 sharedPerferences 添加新插件时,我多次遇到这个问题,我只需重新运行项目就解决了这个问题

        flutter run
        

        如果这不能解决您的问题,请使用

        flutter clean
        
        flutter run
        

        【讨论】:

          猜你喜欢
          • 2018-10-30
          • 1970-01-01
          • 1970-01-01
          • 2018-10-31
          • 1970-01-01
          • 1970-01-01
          • 2021-07-04
          • 2019-01-10
          • 1970-01-01
          相关资源
          最近更新 更多