From a9e038a3b29c05a06bd8eec6802b927bdd20b2d6 Mon Sep 17 00:00:00 2001 From: Blaumeise03 Date: Sun, 15 Sep 2024 14:51:11 +0200 Subject: [PATCH] Update gradle config to declarative plugin blocks See https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply --- android/app/build.gradle | 55 ++++++++++++++----- android/build.gradle | 28 +++++----- android/settings.gradle | 46 +++++++++++++--- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + 4 files changed, 95 insertions(+), 36 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 3ad413c..31ec65e 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,3 +1,31 @@ +// 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.") +// } +// + +// apply plugin: 'com.android.application' +// apply plugin: 'kotlin-android' +// apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" +// apply plugin: 'com.google.gms.google-services' // Google Services plugin +// apply plugin: 'com.google.firebase.crashlytics' + +plugins { + id 'com.android.application' + id 'kotlin-android' + id "dev.flutter.flutter-gradle-plugin" + id 'com.google.gms.google-services' // Google Services plugin + id 'com.google.firebase.crashlytics' +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,29 +34,17 @@ if (localPropertiesFile.exists()) { } } -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.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" -apply plugin: 'com.google.gms.google-services' // Google Services plugin -apply plugin: 'com.google.firebase.crashlytics' - android { - compileSdkVersion 33 + compileSdkVersion 34 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -62,10 +78,21 @@ android { } buildTypes { + /* Notes for the minifyEnable: Flutter 3.19+ does not compile with minSdkVersion <24, unless + * this option is set to true. For more information, see + * https://stackoverflow.com/a/78019688 and https://stackoverflow.com/a/78149818 + */ release { signingConfig signingConfigs.release // shrinkResources false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + //minifyEnabled true fixes this issue and allows you to use minSdkVersion 21 + minifyEnabled true + } + + debug { + //minifyEnabled true fixes this issue and allows you to use minSdkVersion 21 + minifyEnabled true } } @@ -81,6 +108,6 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.support:multidex:1.0.3' } diff --git a/android/build.gradle b/android/build.gradle index 4283407..41e4cbd 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,17 +1,17 @@ -buildscript { - ext.kotlin_version = '1.8.20' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.google.gms:google-services:4.3.14' // Google Services plugin - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2' - } -} +// buildscript { +// ext.kotlin_version = '1.8.20' +// repositories { +// google() +// mavenCentral() +// } +// +// dependencies { +// classpath 'com.android.tools.build:gradle:7.4.2' +// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" +// classpath 'com.google.gms:google-services:4.3.14' // Google Services plugin +// classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2' +// } +// } allprojects { repositories { diff --git a/android/settings.gradle b/android/settings.gradle index 44e62bc..f225213 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,11 +1,41 @@ -include ':app' +// include ':app' +// +// def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +// def properties = new Properties() +// +// assert localPropertiesFile.exists() +// localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } +// +// def flutterSdkPath = properties.getProperty("flutter.sdk") +// assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +// apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + def localPropertiesFile = new File(rootProject.projectDir, "local.properties") + localPropertiesFile.withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" + 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 "7.4.2" apply false + id "org.jetbrains.kotlin.android" version "1.8.20" apply false + id 'com.google.gms.google-services' version "4.3.1" apply false // Google Services plugin + id 'com.google.firebase.crashlytics' version "2.9.9" apply false +} + +include ":app" \ No newline at end of file diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 2085666..f24bb97 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -9,6 +9,7 @@ import file_selector_macos import firebase_analytics import firebase_core import firebase_crashlytics +import firebase_remote_config import flutter_local_notifications import package_info_plus import path_provider_foundation @@ -21,6 +22,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseAnalyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAnalyticsPlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) FLTFirebaseCrashlyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCrashlyticsPlugin")) + FLTFirebaseRemoteConfigPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseRemoteConfigPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))