From 87d0f166a219e256241fa6d76b8b927a42ec2fc1 Mon Sep 17 00:00:00 2001 From: ishaqhassan Date: Fri, 7 Mar 2025 08:10:52 +0500 Subject: [PATCH 1/2] Refactor Android Gradle build configuration to use Plugin DSL - Updates `settings.gradle` to use the declarative `pluginManagement` block for applying Flutter's Gradle plugins. - Removes the deprecated imperative `apply` method for loading plugins. - Updates `build.gradle` files to use the new plugin DSL. - Updates Gradle version to 8.7. - Updates compile and target sdk versions to be flutter's ones. - Removes deprecated `registerWith` method in `OpenFilePlugin`. --- .../crazecoder/openfile/OpenFilePlugin.java | 11 ------- example/android/app/build.gradle | 25 +++++++--------- example/android/build.gradle | 17 +---------- .../gradle/wrapper/gradle-wrapper.properties | 4 +-- example/android/settings.gradle | 30 ++++++++++++++----- 5 files changed, 35 insertions(+), 52 deletions(-) diff --git a/android/src/main/java/com/crazecoder/openfile/OpenFilePlugin.java b/android/src/main/java/com/crazecoder/openfile/OpenFilePlugin.java index 7bc3787c..e65a60b6 100644 --- a/android/src/main/java/com/crazecoder/openfile/OpenFilePlugin.java +++ b/android/src/main/java/com/crazecoder/openfile/OpenFilePlugin.java @@ -69,17 +69,6 @@ public class OpenFilePlugin implements MethodCallHandler private static final int RESULT_CODE = 0x12; private static final String TYPE_STRING_APK = "application/vnd.android.package-archive"; - @Deprecated - public static void registerWith(PluginRegistry.Registrar registrar) { - OpenFilePlugin plugin = new OpenFilePlugin(); - plugin.activity = registrar.activity(); - plugin.context = registrar.context(); - plugin.channel = new MethodChannel(registrar.messenger(), "open_file"); - plugin.channel.setMethodCallHandler(plugin); - registrar.addRequestPermissionsResultListener(plugin); - registrar.addActivityResultListener(plugin); - } - private boolean hasPermission(String permission) { return ContextCompat.checkSelfPermission(activity, permission) == PermissionChecker.PERMISSION_GRANTED; } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 49b26506..a264013d 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +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()) { @@ -6,10 +12,6 @@ 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) { @@ -21,13 +23,10 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 34 + compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion + namespace "com.example.example" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -48,7 +47,7 @@ android { // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. minSdkVersion flutter.minSdkVersion - targetSdkVersion 34 + compileSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } @@ -64,8 +63,4 @@ android { flutter { source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} +} \ No newline at end of file diff --git a/example/android/build.gradle b/example/android/build.gradle index 0441e394..8f31e8ca 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,22 +1,7 @@ -buildscript { - ext.kotlin_version = '1.6.21' - repositories { - google() - mavenCentral() - maven { url "https://maven.google.com" } - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() mavenCentral() - maven { url "https://maven.google.com" } } } @@ -30,4 +15,4 @@ subprojects { tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index cc5527d7..ca244fa2 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Fri Mar 07 07:40:16 PKT 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bcf..d67f36eb 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +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 + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -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" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "8.5.0" apply false + id "org.jetbrains.kotlin.android" version "2.0.10" apply false +} + +include ":app" From 4f2a23494a1726f215cf2be25226f679d6420c04 Mon Sep 17 00:00:00 2001 From: ishaqhassan Date: Fri, 7 Mar 2025 08:15:02 +0500 Subject: [PATCH 2/2] Update permission_handler dependency to version 11.4.0 in example pubspec.yaml --- example/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ca73f166..d530a2bb 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: sdk: flutter open_filex: path: ../ - permission_handler: ^10.3.0 + permission_handler: ^11.4.0 dev_dependencies: flutter_test: