Android 在此进程com.viainno.homego中未初始化Flatter默认FirebaseApp。确保首先调用FirebaseApp.initializeApp(上下文)
更新2020/12/11 问题解决了。 出现此问题是因为我在插件中编辑了清单Android 在此进程com.viainno.homego中未初始化Flatter默认FirebaseApp。确保首先调用FirebaseApp.initializeApp(上下文),android,firebase,flutter,firebase-cloud-messaging,Android,Firebase,Flutter,Firebase Cloud Messaging,更新2020/12/11 问题解决了。 出现此问题是因为我在插件中编辑了清单 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tungwang.tappayflutterplugin"> <!-- <application--> <!-- xmlns:tools="htt
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tungwang.tappayflutterplugin">
<!-- <application-->
<!-- xmlns:tools="http://schemas.android.com/tools"-->
<!-- tools:node="replace"-->
<!-- />-->
</manifest>
这是我的应用程序级别build.gradle
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"
//FCM
// Add the google services classpath
classpath 'com.google.gms:google-services:4.3.2'
}
}
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
}
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.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.viainno.homego"
minSdkVersion 18
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.android.support:multidex:1.0.3'
}
//FCM
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
您试图在不初始化Firebase的情况下获取其实例。在尝试获取Firebase实例之前,请添加
FirebaseApp.initialize()
。您好!谢谢你的回复。我尝试过这个,但我得到了“Firebase尚未正确初始化。您是否已将“google services.json”文件添加到项目中?”这真的很奇怪。您不介意共享您的dart代码吗?当然。哪一部分?我发现如果我删除我创建的这个插件(),错误就会消失。但是我“必须”在我的应用程序中使用这个插件。我解决了这个问题。谢谢
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.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.viainno.homego"
minSdkVersion 18
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.android.support:multidex:1.0.3'
}
//FCM
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'