invertase / flutterfire_cli

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

fix(android): another `build.gradle` change in latest flutter (>=3.16.5) when running `flutter create <project>` #254

Closed russellwheatley closed 5 months ago

russellwheatley commented 5 months ago

Description

fixes https://github.com/invertase/flutterfire_cli/issues/251

there are now 2 legacy ways to update the gradle configuration and the latest Flutter version requires updating the settings.gradle file rather than android/build.gradle which you can read more about here. I've refactored the gradle writing to make it clearer what is being updated. Hence why there is now an enum for each different gradle configuration.

I've tested against all three types. At the moment, the CI only tests against the latest and perhaps if there is a bigger use case, I will test against legacy Flutter versions which create different gradle configurations.

Below are the results of running flutterfire configure --yes --project=project-id --platforms=android against all 3 different gradle configurations:

Legacy gradle configuration 1

android/app/build.gradle:

apply plugin: 'com.android.application'  
// START: FlutterFire Configuration  
apply plugin: 'com.google.gms.google-services'  
apply plugin: 'com.google.firebase.crashlytics'  
// END: FlutterFire Configuration  
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android/build.gradle:

dependencies {  
    // START: FlutterFire Configuration  
    classpath 'com.google.gms:google-services:4.3.15'  
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'  
    // END: FlutterFire Configuration  
    classpath 'com.android.tools.build:gradle:8.1.2'  
}

Legacy gradle configuration 2

android/build.gradle:

    dependencies {
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:perf-plugin:1.4.1'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        // END: FlutterFire Configuration
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

android/app/build.gradle:

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

Latest Flutter version >= 3.16.5

android/app/build.gradle:

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

android/settings.gradle:

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:perf-plugin" version "1.4.1" apply false
    id "com.google.firebase:firebase-crashlytics-gradle" version "2.8.1" apply false
    // END: FlutterFire Configuration
}

Type of Change