简体   繁体   中英

I can't launch app on my physical device after connecting my Flutter app to Firebase

I am new to Flutter and Firebase. My problem is that I was able to run my Flutter app on my physical device to test the ui perfectly fine but after I connected it to Firebase and tried to launch the app like I used it to do before, it will just run the gradle task 'assemble debug' for less than a minute and terminate without sending any kind of feedback or error.

I followed this and that's how my build.gradle file look like:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.12'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and that's my build.gradle file in the app directory :

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.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.sabra.cadre_permanence_marjane"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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"
}

Also I tried changing the package_name in each member of the client array in the google-services.json file to match (tell me if I shouldn't have done that) and checked if Flutter recognize my device just in case:

command prompt: flutter devices

Steps to follow: (Recommended to try in Android Studio)

  1. After connecting to firebase, add the google-services.json file under android->app folder.
  2. Check if there is any file named '[project_name]_android.iml' or not under android folder.
  3. if not, make a file under the android folder named '[project_name]_android.iml'.
  4. Copy-paste the following code under that file.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Dart SDK" level="project" />
  </component>
</module>
  1. Close all files that open in IDE.
  2. Go to any build.gradle file(project level or app level).
  3. When you open that file, you will see a banner at the top of the file. Notice at the right side of the banner. You will see an option 'Open for Editing in Android Studio'. Click that option.
  4. A Permission will asked by Android Studio to open a new window. Give Permission to open as 'New Window'.
  5. Wait until "Gradle Build" operation is completed. You can see progress at the bottom of the newly opened window.
  6. After complete Progress close the new window.
  7. flutter clean
  8. flutter pub get
  9. run the project.

Have fun. Thank you.

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