从今天开始(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 文件夹。我假设在某些时候这一切都会得到很好的记录,但目前它有点狂野。