【问题标题】:Firebase implementation in flutter issues颤振问题中的 Firebase 实施
【发布时间】:2020-01-25 18:49:42
【问题描述】:

在我的颤振项目中实施 firebase 时遇到很多问题,由于 gradle 错误,我不得不从 4.3 恢复到 4.2。现在将它加载到我的模拟器上需要很长时间,我切换到实际设备但安装不会打开。最近有人在颤振项目中实现了firebase消息传递吗?我即将放弃使用它的整个想法。

我已将所需的行添加到 build.gradle 和 app/build.gradle 以及我的 yaml 文件中,仅此而已。

【问题讨论】:

  • 我也遇到了一些问题,所以我只使用了 gradle 3.3.0 版本
  • 我可以通过从我的 yaml 文件中删除 firebase_core 来修复它
  • 您是只是接收通知,还是也从应用程序发送通知?我也在尝试从应用程序发送。
  • 如果我想从应用程序发送它,我会在 firebase 上创建一个函数,当应用程序通过 HTTP 请求请求它时会处理它。

标签: firebase flutter dart


【解决方案1】:

从今天开始(2019 年 9 月 27 日 20:00 UTC,因为颤振构建可能随时中断),我已经让它工作了,我会告诉你我的构建中有什么以便让它工作(评论有点太长了)。我已经测试过它可以在 iOS 和 Android 上运行,并且可以正确构建以供发布。

首先切换到flutter主频道flutter channel master。这是为了修复一个 gradle appbundle 命名问题。

pubspec.yaml

dependencies:
  firebase_messaging: ^5.1.6

android/build.gradle(注意gradle版本的变化)

buildscript {
    ext.kotlin_version = '1.3.41'
    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.2'
    }
}

android/gradle.properties(AndroidX 的更改)

android.enableJetifier=true
android.useAndroidX=true

android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

android/app/build.gradle

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.0.0'
}

apply plugin: 'com.google.gms.google-services'

在同一文件中,确保在 defaultConfig 部分中您已将 testInstrumentationRunner 更改如下:

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

android/app/src/main/AndroidManifest.xml

<intent-filter>
  <action android:name="FLUTTER_NOTIFICATION_CLICK" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

确保您已将 google-services.json 添加到 android/app 文件夹。我假设在某些时候这一切都会得到很好的记录,但目前它有点狂野。

【讨论】:

    猜你喜欢
    • 2020-08-03
    • 2021-12-16
    • 1970-01-01
    • 2020-06-06
    • 2022-10-04
    • 2021-03-22
    • 2021-11-16
    • 2021-05-05
    • 2022-01-12
    相关资源
    最近更新 更多