invertase / flutterfire_cli

A CLI to help with using FlutterFire in your Flutter applications.
Apache License 2.0
164 stars 47 forks source link

[bug]: App does not run after configuration using flutterfire #307

Open muezz opened 3 weeks ago

muezz commented 3 weeks ago

Is there an existing issue for this?

CLI Version

1.0.0

Firebase Tools version

13.10.2

Flutter Doctor Output

[!] Flutter (Channel stable, 3.22.0, on macOS 14.4.1 23E224 darwin-arm64, locale en-PK)
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.5.0-155.0.dev/libexec/bin/dart, which is not
      inside your current Flutter SDK checkout at /Users/abdulmuezz/Documents/flutter. Consider adding
      /Users/abdulmuezz/Documents/flutter/bin to the front of your path.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.89.1)
[✓] Connected device (5 available)
[✓] Network resources

! Doctor found issues in 1 category.

Description

After configuring my app with firebase using flutterfire, I get an error in my app/build.gradle file

Steps to reproduce

  1. Run flutterfire configure --project=my-project
  2. Run flutter run
  3. See error:
    
    FAILURE: Build failed with an exception.

BUILD FAILED in 690ms Running Gradle task 'assembleDebug'... 1,156ms Error: Gradle task assembleDebug failed with exit code 1



### Expected behavior

The app should run fine as it does if I revert the changes made by the configure command.

### Screenshots

### This was added by the flutterfire extension:
<img width="1229" alt="image" src="https://github.com/invertase/flutterfire_cli/assets/100420605/f59efeaa-435c-407f-8d28-18b36b8d60fb">

### Additional context and comments

_No response_
russellwheatley commented 3 weeks ago

Please post both build.gradle files. android/build.gradle and android/app/build.gradle. Thanks 👍

muezz commented 3 weeks ago

Hey @russellwheatley, Here is my project level build.gradle:

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

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

This is my app level build.gradle:

plugins {
    id "com.android.application"
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    // END: FlutterFire Configuration
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

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

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

android {
    namespace "app.iuhabit"
    compileSdk 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        coreLibraryDesugaringEnabled true
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        applicationId "app.iuhabit"
        minSdkVersion 24
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }

    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.release
            ndk {
                debugSymbolLevel 'FULL'
                abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'
            }
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}
muezz commented 3 weeks ago

@russellwheatley Did you get a chance to take a look at this?

russellwheatley commented 3 weeks ago

Hey @muezz, could you also post your settings.gradle file as well, please? I should've said that in the original post, sorry 😓

muezz commented 3 weeks ago

@russellwheatley Here it is:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '7.3.0' apply false
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"
hussain-mustafa990 commented 6 days ago

I was also facing this issue. I fixed the issue by adding.

id "com.google.gms.google-services" version "4.4.0" apply false
id "com.google.firebase.firebase-perf" version "1.4.2" apply false
id "com.google.firebase.crashlytics" version "2.9.9" apply false

To the plugins section in my settings.gradle file.

The complete settings.gradle file is as follows:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '8.2.2' apply false
    id "org.jetbrains.kotlin.android" version "2.0.0" apply false
    // START: FlutterFire Configuration
    id "com.google.gms.google-services" version "4.4.0" apply false
    id "com.google.firebase.firebase-perf" version "1.4.2" apply false
    id "com.google.firebase.crashlytics" version "2.9.9" apply false
    // END: FlutterFire Configuration
}

include ":app"

Although I expected the flutterfire confiure command to do this for me.

muezz commented 6 days ago

@hussain-mustafa990 I fixed this by creating a new project and adding all of my dependencies and then running the flutterfire CLI command along with pod install.