Skip to content

Commit 5047adf

Browse files
Merge pull request #19 from mufassalhussain/master
Fix Android compatibility issues after Flutter 3.29.0 upgrade
2 parents a52e62e + b4277d2 commit 5047adf

10 files changed

Lines changed: 86 additions & 110 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.7.0
2+
* Fix Android compatibility issues after Flutter 3.29.0 upgrade (Thanks to [mufassalhussain](https://github.com/mufassalhussain), PR[#19](https://github.com/javaherisaber/open_filex/pull/19))
3+
14
## 4.6.0
25
* Fix platform errors for linux, windows, web, macos on Flutter 3.27+ (Thanks to [Xavier H.](https://github.com/xvrh), PR[#17](https://github.com/javaherisaber/open_filex/pull/17))
36

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:7.3.1'
11+
classpath 'com.android.tools.build:gradle:8.1.0'
1212
}
1313
}
1414

android/src/main/java/com/crazecoder/openfile/OpenFilePlugin.java

Lines changed: 49 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,72 @@
3939
import java.io.IOException;
4040
import java.util.Map;
4141

42-
43-
/**
44-
* OpenFilePlugin
45-
*/
4642
public class OpenFilePlugin implements MethodCallHandler
4743
, FlutterPlugin
4844
, ActivityAware
4945
, PluginRegistry.RequestPermissionsResultListener
5046
, PluginRegistry.ActivityResultListener {
51-
/**
52-
* Plugin registration.
53-
*/
54-
private @Nullable
55-
FlutterPluginBinding flutterPluginBinding;
5647

48+
private @Nullable FlutterPluginBinding flutterPluginBinding;
5749
private Context context;
5850
private Activity activity;
5951
private MethodChannel channel;
60-
61-
6252
private Result result;
6353
private String filePath;
6454
private String typeString;
65-
6655
private boolean isResultSubmitted = false;
6756

6857
private static final int REQUEST_CODE = 33432;
6958
private static final int RESULT_CODE = 0x12;
7059
private static final String TYPE_STRING_APK = "application/vnd.android.package-archive";
7160

72-
@Deprecated
73-
public static void registerWith(PluginRegistry.Registrar registrar) {
74-
OpenFilePlugin plugin = new OpenFilePlugin();
75-
plugin.activity = registrar.activity();
76-
plugin.context = registrar.context();
77-
plugin.channel = new MethodChannel(registrar.messenger(), "open_file");
78-
plugin.channel.setMethodCallHandler(plugin);
79-
registrar.addRequestPermissionsResultListener(plugin);
80-
registrar.addActivityResultListener(plugin);
61+
@Override
62+
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
63+
this.flutterPluginBinding = binding;
64+
context = flutterPluginBinding.getApplicationContext();
65+
setup();
66+
}
67+
68+
private void setup() {
69+
if (flutterPluginBinding != null) {
70+
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "open_file");
71+
channel.setMethodCallHandler(this);
72+
}
73+
}
74+
75+
@Override
76+
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
77+
if (channel != null) {
78+
channel.setMethodCallHandler(null);
79+
channel = null;
80+
}
81+
this.flutterPluginBinding = null;
82+
}
83+
84+
@Override
85+
public void onAttachedToActivity(ActivityPluginBinding binding) {
86+
activity = binding.getActivity();
87+
binding.addRequestPermissionsResultListener(this);
88+
binding.addActivityResultListener(this);
89+
}
90+
91+
@Override
92+
public void onDetachedFromActivityForConfigChanges() {
93+
onDetachedFromActivity();
94+
}
95+
96+
@Override
97+
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
98+
onAttachedToActivity(binding);
99+
}
100+
101+
@Override
102+
public void onDetachedFromActivity() {
103+
if (channel != null) {
104+
channel.setMethodCallHandler(null);
105+
channel = null;
106+
}
107+
activity = null;
81108
}
82109

83110
private boolean hasPermission(String permission) {
@@ -395,56 +422,4 @@ private void result(int type, String message) {
395422
isResultSubmitted = true;
396423
}
397424
}
398-
399-
@Override
400-
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
401-
this.flutterPluginBinding = binding;
402-
context = flutterPluginBinding.getApplicationContext();
403-
setup();
404-
}
405-
406-
private void setup() {
407-
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "open_file");
408-
channel.setMethodCallHandler(this);
409-
}
410-
411-
@Override
412-
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
413-
if (channel == null) {
414-
// Could be on too low of an SDK to have started listening originally.
415-
return;
416-
}
417-
418-
channel.setMethodCallHandler(null);
419-
channel = null;
420-
this.flutterPluginBinding = null;
421-
}
422-
423-
@Override
424-
public void onAttachedToActivity(ActivityPluginBinding binding) {
425-
setup();
426-
activity = binding.getActivity();
427-
binding.addRequestPermissionsResultListener(this);
428-
binding.addActivityResultListener(this);
429-
}
430-
431-
@Override
432-
public void onDetachedFromActivityForConfigChanges() {
433-
onDetachedFromActivity();
434-
}
435-
436-
@Override
437-
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
438-
onAttachedToActivity(binding);
439-
}
440-
441-
@Override
442-
public void onDetachedFromActivity() {
443-
if (channel == null) {
444-
return;
445-
}
446-
channel.setMethodCallHandler(null);
447-
channel = null;
448-
activity = null;
449-
}
450-
}
425+
}

example/android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ GeneratedPluginRegistrant.java
1111
key.properties
1212
**/*.keystore
1313
**/*.jks
14+
.cxx/

example/android/app/build.gradle

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
id "dev.flutter.flutter-gradle-plugin"
5+
}
6+
17
def localProperties = new Properties()
28
def localPropertiesFile = rootProject.file('local.properties')
39
if (localPropertiesFile.exists()) {
@@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
612
}
713
}
814

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
1415
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
1516
if (flutterVersionCode == null) {
1617
flutterVersionCode = '1'
@@ -21,11 +22,8 @@ if (flutterVersionName == null) {
2122
flutterVersionName = '1.0'
2223
}
2324

24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
2825
android {
26+
namespace "com.example.example"
2927
compileSdkVersion 34
3028
ndkVersion flutter.ndkVersion
3129

@@ -67,5 +65,4 @@ flutter {
6765
}
6866

6967
dependencies {
70-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
7168
}

example/android/build.gradle

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
buildscript {
2-
ext.kotlin_version = '1.6.21'
3-
repositories {
4-
google()
5-
mavenCentral()
6-
maven { url "https://maven.google.com" }
7-
}
8-
9-
dependencies {
10-
classpath 'com.android.tools.build:gradle:7.3.1'
11-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12-
}
13-
}
14-
151
allprojects {
162
repositories {
173
google()

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip

example/android/settings.gradle

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
include ':app'
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4-
def properties = new Properties()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
511

6-
assert localPropertiesFile.exists()
7-
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
17+
}
818

9-
def flutterSdkPath = properties.getProperty("flutter.sdk")
10-
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11-
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.1.0" apply false
22+
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
23+
}
24+
25+
include ":app"

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
sdk: flutter
1313
open_filex:
1414
path: ../
15-
permission_handler: ^10.3.0
15+
permission_handler: ^11.4.0
1616

1717
dev_dependencies:
1818
flutter_test:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: open_filex
22
description: A plug-in that can call native APP to open files with string result in flutter, support iOS(UTI) / android(intent) / PC(ffi) / web(dart:html)
3-
version: 4.6.0
3+
version: 4.7.0
44
homepage: https://github.com/javaherisaber/open_file
55

66
dependencies:

0 commit comments

Comments
 (0)