invertase / flutterfire_cli

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

[bug]: latest gradle setup configuration has problems #267

Closed russellwheatley closed 6 months ago

russellwheatley commented 6 months ago

Is there an existing issue for this?

CLI Version

flutterfire_cli 0.3.0-dev.20

Firebase Tools version

latest

Flutter Doctor Output

N/A

Description

Writes google service line twice (i.e. if one is present, it will still write a second time).

Steps to reproduce

N/A

Expected behavior

Not to write again if present

Screenshots

No response

Additional context and comments

No response

skela commented 6 months ago

thx @russellwheatley was going to do it, but noticed u did it already.

russellwheatley commented 6 months ago

Could you post your gradle.settings file which allowed the google-services line to be duplicated?

russellwheatley commented 6 months ago

@skela - I have tested the settings.gradle, flutterfire configure updated it when this line was not present:

id "com.google.gms.google-services" version "4.3.15" apply false

It also recognised when the above line was present and did not write. I also tested with different version

id "com.google.gms.google-services" version "4.4.0" apply false

and it still correctly did not write when it was present in settings.gradle.

I'm going to need a copy of your settings.gradle file that duplicates the above mentioned when you run flutterfire configure.

VladyslavBilomeria commented 6 months ago

In my case, I have duplicates in the android/app/build.gradle file. I am using flavors and running this script calling the flutterfire configure command 6 times (for Debug-prod, Release-prod, Profile-prod, Debug-dev, Release-dev, Profile-dev):

Script ```bash #!/bin/sh configure_firebase_environment() { if [ $# -ne 4 ]; then echo "Need 4 arguments: firebaseProjectID, environmentName, iOSBundleId, androidPackageName" exit 1 fi project=$1 environment=$2 iosBundleId=$3 androidPackageName=$4 for prefix in "Debug" "Release" "Profile"; do echo 'yes' | flutterfire configure \ --project="$project" \ --platforms="ios,android" \ --ios-bundle-id="$iosBundleId" \ --android-package-name="$androidPackageName" \ --out=lib/environments/"$environment"/firebase_options.dart \ --android-out=/android/app/src/"$environment"/google-services.json \ --ios-out=/ios/environments/"$environment"/GoogleService-Info.plist \ --ios-build-config="$prefix"-"$environment" \ --overwrite-firebase-options \ --yes done } # Configure "prod" Firebase environment echo "Configuring \"prod\" Firebase environment..." configure_firebase_environment \ "firebaseProjectID_here" \ "prod" \ "com.example.app" \ "com.example.app" # Configure "dev" Firebase environment echo "Configuring \"dev\" Firebase environment..." configure_firebase_environment \ "firebaseProjectID_here" \ "dev" \ "com.example.app" \ "com.example.app" ```

and after that, in my android/app/build.gradle file I have 5 times of these lines:

// START: FlutterFire Configuration
id 'com.google.gms.google-services'
// END: FlutterFire Configuration

and 1 of these:

// START: FlutterFire Configuration
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
// END: FlutterFire Configuration
Initial `android/app/build.gradle` file ```gradle plugins { id "com.android.application" 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' } android { namespace "com.example.app" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "com.example.app" minSdkVersion 22 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { signingConfig signingConfigs.debug } } flavorDimensions 'app' productFlavors { prod { dimension 'app' resValue 'string', 'app_name', 'App' } dev { dimension 'app' applicationIdSuffix = '.dev' resValue 'string', 'app_name', 'App [DEV]' } } } flutter { source '../..' } dependencies {} ```
Result `android/app/build.gradle` file ```gradle plugins { id "com.android.application" // START: FlutterFire Configuration id 'com.google.gms.google-services' // END: FlutterFire Configuration // START: FlutterFire Configuration id 'com.google.gms.google-services' // END: FlutterFire Configuration // START: FlutterFire Configuration id 'com.google.gms.google-services' // END: FlutterFire Configuration // START: FlutterFire Configuration id 'com.google.gms.google-services' // END: FlutterFire Configuration // START: FlutterFire Configuration id 'com.google.gms.google-services' // END: FlutterFire Configuration // 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' } android { namespace "com.example.app" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "com.example.app" minSdkVersion 22 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { signingConfig signingConfigs.debug } } flavorDimensions 'app' productFlavors { prod { dimension 'app' resValue 'string', 'app_name', 'App' } dev { dimension 'app' applicationIdSuffix = '.dev' resValue 'string', 'app_name', 'App [DEV]' } } } flutter { source '../..' } dependencies {} ```

The result android/settings.gradle file looks correct:

Result `android/settings.gradle` file ```gradle 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-gradle-plugin" version "1.0.0" apply false } } plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "7.3.0" apply false // START: FlutterFire Configuration id "com.google.gms.google-services" version "4.3.15" apply false id "com.google.firebase.crashlytics" version "2.8.1" apply false // END: FlutterFire Configuration } include ":app" ```
skela commented 6 months ago

@russellwheatley sorry, the duplications seem to happen in the app/build.gradle file.

Steps to reproduce:

flutter create -t plugin --platforms ios,android --org com.whatever something

cd something

flutter pub add firebase_core

flutter pub add firebase_analytics

cd example

~/.pub-cache/bin/flutterfire configure

example/android/app/build.gradle now has 1 google services line in plugins.

Run the configure again:

~/.pub-cache/bin/flutterfire configure

It now has 2.

Run it again and u get 3 etc.

Contents of the example/android/settings.gradle

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
    // START: FlutterFire Configuration
    id "com.google.gms.google-services" version "4.3.15" apply false
    // END: FlutterFire Configuration
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"

Contents of example/android/app/build.gradle

plugins {
    id "com.android.application"
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // END: FlutterFire Configuration
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // END: FlutterFire Configuration
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // 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'
}

android {
    namespace "com.space.yeehaw_example"
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    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.space.yeehaw_example"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        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 {}
timmolter commented 6 months ago

This happens for me too.

barilki commented 5 months ago

please re-open: Missing google_app_id. Firebase Analytics

JgomesAT commented 5 months ago

settings.gradle is not changed when flutterfire reconfigure o flutterfire configure only the build.gradle is changed