简体   繁体   中英

Adding firebase_messaging Plugin to flutter project on android stops app from launching with no error

I'm developing a flutter app with most of it done except for the push notification. When adding the firebase_messaging plugin in the pubspec.yaml and follow the setup process for android, the app stops launching with out giving any error. Just keeps on waiting to finish installation.

App migrated to android x from the start of development and other firebase plugins in use and working fine.Tested on different physical devices and emulator all with same issue. flutter clean run every time before build. I'm sure there is something wrong with the setup or a conflict with another plugin but no error is being given. 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

terminal output

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 (the only issue of android license it never and it shouldn't effect)

[√] 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.

You try run flutter doctor - android-licenses to make an android license. There is one problem there.

Lastest version firebase_messaging 5.1.0

Firebase Messaging Example this is an example of implementation if there is an error in your code I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM