如何解决在Android上缺少MissingPluginException在通道plugins.flutter.io/firebase_core上未找到方法Firebase#initializeCore的实现
在Flutter代码中调用Firebase.initializeApp()
时,出现上述错误。
我在这里关注了文档:https://firebase.flutter.dev/docs
这是我的pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_core: ^0.5.0
cloud_firestore: ^0.14.0
firebase_auth: ^0.18.0
fl_chart: ^0.11.0
snapping_sheet: ^2.0.0
flutter_svg: ^0.18.0
flutter_redux: ^0.6.0
strings: ^0.1.2
random_string: ^2.1.0
redux_thunk: ^0.3.0
# firebase_crashlytics: ^0.1.4+1
dotted_line: ^2.0.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
这是我的颤动代码:
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
final store = Store<AppState>(AppState.reducer,initialState: AppState.initial(),middleware: [thunkMiddleware]);
runApp(
FutureBuilder(
future: Firebase.initializeApp(),builder: (context,snapshot) {
// Check for errors
if (snapshot.hasError) {
log(snapshot.error.toString());
return Container(color: Colors.red);
}
// Once complete,show your application
if (snapshot.connectionState == ConnectionState.done) {
return StoreProvider<AppState>(
store: store,child: MoollaApp(store: store),);
}
// Otherwise,show something whilst waiting for initialization to complete
return Container(color: Colors.green);
},),);
}
这是我的.gradle(应用程序)文件的相关部分:
plugins {
id "com.android.application"
id "com.google.gms.google-services"
id "kotlin-android"
id "kotlin-android-extensions"
}
这是我的项目gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-alpha07'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
和我的Application类扩展名:
class MyApp : FlutterApplication() {
override fun onCreate() {
super.onCreate()
}
}
据我所知,根据文档,我已正确完成了所有操作。
解决方法
将 minifyEnabled 和 shrinkResources 设置为 false 可以修复它,但为什么呢?我不知道。如果有人知道,请写评论。
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
shrinkResources false
}
}
,
在遇到这个问题后,我最终意识到该错误非常模糊,并不一定意味着 firebase_core
存在问题,而是任何 Firebase 插件都可能存在问题。因此,为了缩小问题的范围,我分别检查了每个 firebase 导入,并在 Pubspec.yaml 文件中将其注释掉并运行它(同时注释掉了我项目中使用该导入的所有代码),直到我找到了哪个包导致了问题。
对我来说,我只有在 iOS 上运行时才会遇到这个问题。结果证明 firebase_messaging
是罪魁祸首,它是我添加到 iOS AppDelegate 的代码,用于处理最新版本的 firebase_messaging
插件不再需要的消息。
不仔细检查整个项目就很难确切地说出问题所在,但是这里有一些措施可能会解决问题。
- 运行
flutter doctor
并确认一切正常。 - 先运行
flutter clean
,然后运行flutter pub get
。
如果您仍然收到相同的错误,则可能是在编辑其中一个配置文件时出错了。
- 将您的android / app / main / AndroidManifest.xml与以前的工作版本进行比较(特别是确保您不会意外删除任何
<meta-data />
标签,因为这样做会导致上述错误。 - 对android / build.gradle和android / app / build.gradle做同样的事情。
我开始了一个新项目,并确保进行更改:
classpath 'com.android.tools.build:gradle:4.2.0-alpha07'
至正式支持的版本:3.5.0
不确定是否需要降级,因为正如我所说,我重新启动了一个全新的项目,并且可能有其他影响。
我还向Google提交了一张票证,将来可能会对其他人有所帮助: https://github.com/FirebaseExtended/flutterfire/issues/3212#issuecomment-675407420
,我对该问题进行了一些研究,发现了一个打开和关闭的 issue,商定的解决方案是简单地创建一个新的 Flutter 应用程序并一个接一个地移植您的依赖项和文件。 虽然这对我来说不是一个可行的解决方案,但运行
flutter clean
然后
flutter pub get
似乎解决了这个问题。到目前为止,我不确定到底是什么包导致了这个问题,但在我的部署中我有
google_sign_in: ^4.5.5
firebase_core: ^1.2.0
firebase_auth: ^1.2.0
仅。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。