将firebase_messaging插件添加到android上的flutter项目中可阻止应用正常启动

时间:2019-07-11 09:11:57

标签: android firebase flutter firebase-cloud-messaging

我正在开发一个Flutter应用程序,除了推送通知外,大部分都已完成。在pubspec.yaml中添加firebase_messaging插件并按照android的设置过程进行操作时,该应用会停止启动,并且不会出现任何错误。只是等待完成安装。

App从开发之初就迁移到android x,并且其他firebase插件已在使用中并且工作正常。在不同的物理设备和仿真器上进行了测试,均存在相同的问题。每次构建前都要进行干净的运行。 我确定安装程序有问题或与其他插件发生冲突,但未给出任何错误。 pubspec.yaml

environment:
  sdk: ">=2.2.2 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  #cupertino_icons: ^0.1.2
  http: ^0.12.0+1
  #shared_preferences: ^0.5.1+1
  rxdart: ^0.21.0
  carousel_slider: ^1.1.0
  google_maps_flutter: ^0.4.0
  url_launcher: ^5.0.2
  firebase_core: ^0.3.1+1
  firebase_auth: ^0.8.3
  firebase_dynamic_links: ^0.2.1
  flutter_secure_storage: ^3.2.1+1
  corsac_jwt: ^0.1.2
  intl_translation: ^0.17.4
  connectivity: ^0.4.3+1
  flutter_svg: ^0.13.0+2
  #flutter_statusbarcolor: ^0.1.0
  google_sign_in: ^4.0.1+3
  flutter_facebook_login: ^2.0.0
  country_code_picker: ^1.1.5
  webview_flutter: ^0.3.7+1
  #permission_handler: '^3.1.0'
  #notification_permissions: ^0.3.1
  auto_size_text: ^1.1.2
  launch_review: ^1.0.1
  qr_flutter: ^2.0.0
  geolocator: '^5.0.0'
  flare_flutter: ^1.5.2
  package_info: ^0.4.0+4
  pin_code_text_field: ^1.3.6
  meta: ^1.1.6
  platform: ^2.2.0
  firebase_messaging: ^5.1.0

dev_dependencies:
  flutter_launcher_icons: 0.6.1
  flutter_test:
    sdk: flutter

/android/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
        // classpath 'com.google.gms:google-services:4.2.0'
    }
}

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.gradle

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 = '19'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '2.0.17'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "app.flutter.test"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        //// for relases
        //release {
        //   signingConfig signingConfigs.release

        //     minifyEnabled true
        //    useProguard true

        //    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'


        //}
        //// for debugging
         release{
             signingConfig signingConfigs.debug
        }


    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    // implementation 'com.google.firebase:firebase-messaging:18.0.0'
}

apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin

终端输出

Launching lib/main.dart on ONE A2001 in debug mode...
Initializing gradle...                                              0.6s
Resolving dependencies...                                           3.5s
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        20.2s
Built android\build\app\outputs\apk\debug\app-debug.apk.
Installing android\build\app\outputs\apk\app.apk...                28.7s

flutter doctor -v(唯一的android许可证,它永远也不会生效)

[√] Flutter (Channel stable, v1.7.8+hotfix.3, on Microsoft Windows [Version 10.0.17763.557], locale en-GB)
    • Flutter version 1.7.8+hotfix.3 at C:\Users\ricardo\flutter
    • Framework revision b712a172f9 (2 days ago), 2019-07-09 13:14:38 -0700
    • Engine revision 54ad777fd2
    • Dart version 2.4.0

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\ricardo\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    X Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.

[√] Android Studio (version 3.4)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin version 37.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] VS Code (version 1.35.1)
    • VS Code at C:\Users\ricardo\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.2.0

[√] Connected device (1 available)
    • ONE A2001 • 47fc4070 • android-arm64 • Android 6.0.1 (API 23)

! Doctor found issues in 1 category.

1 个答案:

答案 0 :(得分:0)

您尝试 运行flutter doctor - android-licenses制作android许可证。那里有一个问题。

最新版本firebase_messaging 5.1.0

Firebase Messaging Example,这是如果代码中有错误的实现示例 希望对您有帮助