From 1db016235cf7448980b1922d34db00de12c079f2 Mon Sep 17 00:00:00 2001 From: Alex Babich Date: Mon, 1 Jul 2024 10:42:38 +0300 Subject: [PATCH 01/14] - Added namespace --- android/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 8ad2194..5224ca6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -28,6 +28,11 @@ apply plugin: 'kotlin-android' android { compileSdkVersion 33 + if (project.android.hasProperty('namespace')) { + namespace 'io.alexrintt.sharedstorage' + } + + sourceSets { main.java.srcDirs += 'src/main/kotlin' } From 355ba2a65b4212fa765b0ca110fe9ea8e5cf93e2 Mon Sep 17 00:00:00 2001 From: Alex Babich Date: Mon, 1 Jul 2024 11:00:22 +0300 Subject: [PATCH 02/14] - Fixed error in takeIf condition --- lib/src/common/functional_extender.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/common/functional_extender.dart b/lib/src/common/functional_extender.dart index 7e0bd65..c9abffc 100644 --- a/lib/src/common/functional_extender.dart +++ b/lib/src/common/functional_extender.dart @@ -25,7 +25,13 @@ extension FunctionalExtender on T? { T? takeIf(bool Function(T) f) { final T? self = this; - return self != null && f(self) ? self : null; + if (self == null) return null; + + if (f(self)) { + return self; + } else { + return null; + } } } From 8784c39b909324df8913dd30fa416b8a50d55f49 Mon Sep 17 00:00:00 2001 From: Alex Babich Date: Mon, 1 Jul 2024 12:54:06 +0300 Subject: [PATCH 03/14] - Added Java compile version --- android/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 5224ca6..fc0801d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -39,6 +39,11 @@ android { defaultConfig { minSdkVersion 19 } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } } dependencies { From 9dd54437002c7e0ea44b22dc0e7de50580eaf7f7 Mon Sep 17 00:00:00 2001 From: tajuddin Date: Wed, 7 May 2025 16:35:08 +0800 Subject: [PATCH 04/14] Update build.gradle --- android/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index fc0801d..ee7dcd4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -44,6 +44,11 @@ android { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } + + kotlinOptions { + jvmTarget = "17" // Explicitly match Java's version + } + } dependencies { From 0a828da70c10b8296751b974c328250f7fcb2fbe Mon Sep 17 00:00:00 2001 From: tajuddin Date: Wed, 7 May 2025 16:48:54 +0800 Subject: [PATCH 05/14] Update build.gradle --- android/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index ee7dcd4..7f8e851 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,12 +41,12 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 + sourceCompatibility JavaVersion.VERSION_18 + targetCompatibility JavaVersion.VERSION_18 } kotlinOptions { - jvmTarget = "17" // Explicitly match Java's version + jvmTarget = "18" // Explicitly match Java's version } } From b6d842664abad9c6149782c6c1fa30876b7a4c43 Mon Sep 17 00:00:00 2001 From: tajuddin Date: Wed, 7 May 2025 16:55:49 +0800 Subject: [PATCH 06/14] Update gradle.properties --- android/gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/android/gradle.properties b/android/gradle.properties index 94adc3a..842dce9 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +kotlin.jvm.target.validation.mode = IGNORE \ No newline at end of file From 012e22791138958e089f6c1a8d6c4c6943a9f253 Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 12 Jun 2025 17:45:51 +0300 Subject: [PATCH 07/14] - Added validation of SAF availability. --- .../sharedstorage/deprecated/DocumentFileApi.kt | 13 +++++++++++++ .../lib/StorageAccessFrameworkConstant.kt | 1 + lib/src/saf/saf.dart | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt index fd17f6f..e29cd11 100644 --- a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt +++ b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentFileApi.kt @@ -289,10 +289,23 @@ internal class DocumentFileApi(private val plugin: SharedStoragePlugin) : result.notSupported(CHILD, API_21, mapOf("uri" to uri)) } } + CAN_OPEN_DOCUMENT_TREE -> { + result.success(canOpenDocumentTree()) + } else -> result.notImplemented() } } + private fun canOpenDocumentTree(): Boolean { + return try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + val activities = plugin.context.packageManager.queryIntentActivities(intent, 0) + activities.isNotEmpty() + } catch (e: Exception) { + false + } + } + @RequiresApi(API_21) private fun openDocument(call: MethodCall, result: MethodChannel.Result) { val initialUri = call.argument("initialUri") diff --git a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt index 62af0c2..0fa9b62 100644 --- a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt +++ b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/lib/StorageAccessFrameworkConstant.kt @@ -39,6 +39,7 @@ const val COPY = "copy" const val LAST_MODIFIED = "lastModified" const val GET_DOCUMENT_THUMBNAIL = "getDocumentThumbnail" const val CHILD = "child" +const val CAN_OPEN_DOCUMENT_TREE = "canOpenDocumentTree" /** * Available DocumentFileHelper Method Channel APIs diff --git a/lib/src/saf/saf.dart b/lib/src/saf/saf.dart index a0dd059..b3c45d3 100644 --- a/lib/src/saf/saf.dart +++ b/lib/src/saf/saf.dart @@ -134,6 +134,18 @@ Future canRead(Uri uri) async => kDocumentFileChannel Future canWrite(Uri uri) async => kDocumentFileChannel .invokeMethod('canWrite', {'uri': '$uri'}); +/// {@template sharedstorage.saf.canOpenDocumentTree} +/// Check if the device supports Storage Access Framework (SAF) and can open document trees. +/// +/// Returns `true` if the device has apps that can handle ACTION_OPEN_DOCUMENT_TREE intents, +/// `false` otherwise. This is useful to determine SAF support before attempting to use +/// document tree operations. +/// +/// [Refer to details](https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE). +/// {@endtemplate} +Future canOpenDocumentTree() async => kDocumentFileChannel + .invokeMethod('canOpenDocumentTree'); + /// {@template sharedstorage.saf.getDocumentThumbnail} /// Equivalent to `DocumentsContract.getDocumentThumbnail`. /// From 4c5b56ea3f6b5747a82c0493bc5ecfedad31defd Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 12:51:50 +0300 Subject: [PATCH 08/14] Fix AGP 9.x / SDK 36 / Kotlin 2.3.20 compatibility --- android/build.gradle | 4 ++-- .../sharedstorage/deprecated/DocumentsContractApi.kt | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 7f8e851..3429eb3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 33 + compileSdk 36 if (project.android.hasProperty('namespace')) { namespace 'io.alexrintt.sharedstorage' @@ -37,7 +37,7 @@ android { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { - minSdkVersion 19 + minSdk 19 } compileOptions { diff --git a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentsContractApi.kt b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentsContractApi.kt index c0b0428..1dd76d9 100644 --- a/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentsContractApi.kt +++ b/android/src/main/kotlin/io/alexrintt/sharedstorage/deprecated/DocumentsContractApi.kt @@ -95,11 +95,12 @@ internal class DocumentsContractApi(private val plugin: SharedStoragePlugin) : } // the secret are these two lines.... - packageInfo.applicationInfo.sourceDir = it.path - packageInfo.applicationInfo.publicSourceDir = it.path + packageInfo.applicationInfo?.sourceDir = it.path + packageInfo.applicationInfo?.publicSourceDir = it.path val apkIcon: Drawable = - packageInfo.applicationInfo.loadIcon(packageManager) + packageInfo.applicationInfo?.loadIcon(packageManager) + ?: return@createTempUriFile result.success(null) val bitmap: Bitmap = drawableToBitmap(apkIcon) From 2806e4765bd8ea88e38e9314dee1c9a23483b84b Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 13:07:11 +0300 Subject: [PATCH 09/14] Fix Java/Kotlin jvmTarget 18 -> 17 for Kotlin 2.3.20 compatibility --- android/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 3429eb3..7562e5d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,18 +41,18 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_18 - targetCompatibility JavaVersion.VERSION_18 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = "18" // Explicitly match Java's version + jvmTarget = "17" } } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "androidx.documentfile:documentfile:1.0.1" /** From 043b1b6caabfaa554e644a6c3532af594aff3472 Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 15:33:23 +0300 Subject: [PATCH 10/14] Migrate to Flutter Built-in Kotlin (remove explicit KGP application) --- android/build.gradle | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 7562e5d..c34759f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,41 +1,13 @@ group 'io.alexrintt.sharedstorage' version '1.0-SNAPSHOT' -buildscript { - ext.kotlin_version = '1.8.10' - repositories { - google() - mavenCentral() - maven { url "https://oss.sonatype.org/content/repositories/snapshots" } - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.2.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -rootProject.allprojects { - repositories { - google() - mavenCentral() - } -} - apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' android { compileSdk 36 - if (project.android.hasProperty('namespace')) { - namespace 'io.alexrintt.sharedstorage' - } - + namespace 'io.alexrintt.sharedstorage' - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } defaultConfig { minSdk 19 } @@ -48,21 +20,10 @@ android { kotlinOptions { jvmTarget = "17" } - } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "androidx.documentfile:documentfile:1.0.1" - - /** - * Allow usage of `CoroutineScope` to run heavy - * computation and queries outside the Main (UI) Thread - */ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1" - - /** - * `SimpleStorage` library - */ implementation "com.anggrayudi:storage:1.3.0" } From de3583e489e8eaab9db1289d15ba33bd158d3e31 Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 15:34:38 +0300 Subject: [PATCH 11/14] Use org.jetbrains.kotlin.android plugin ID to avoid Flutter KGP warning --- android/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/android/build.gradle b/android/build.gradle index c34759f..d0b1781 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,6 +2,7 @@ group 'io.alexrintt.sharedstorage' version '1.0-SNAPSHOT' apply plugin: 'com.android.library' +apply plugin: 'org.jetbrains.kotlin.android' android { compileSdk 36 From b0b74d3287f703844126c34fe143f32ef4792712 Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 15:42:34 +0300 Subject: [PATCH 12/14] Migrate to Flutter Built-in Kotlin: remove build.gradle, add supportedBuildSystems --- android/build.gradle | 30 ------------------------------ pubspec.yaml | 2 ++ 2 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 android/build.gradle diff --git a/android/build.gradle b/android/build.gradle deleted file mode 100644 index d0b1781..0000000 --- a/android/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -group 'io.alexrintt.sharedstorage' -version '1.0-SNAPSHOT' - -apply plugin: 'com.android.library' -apply plugin: 'org.jetbrains.kotlin.android' - -android { - compileSdk 36 - - namespace 'io.alexrintt.sharedstorage' - - defaultConfig { - minSdk 19 - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - - kotlinOptions { - jvmTarget = "17" - } -} - -dependencies { - implementation "androidx.documentfile:documentfile:1.0.1" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1" - implementation "com.anggrayudi:storage:1.3.0" -} diff --git a/pubspec.yaml b/pubspec.yaml index 4d30b40..5e55d15 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,3 +26,5 @@ flutter: android: package: io.alexrintt.sharedstorage pluginClass: SharedStoragePlugin + supportedBuildSystems: + - gradle From f6dbbaf41831f81692d0ea1fa861bfa04dcec554 Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 15:43:19 +0300 Subject: [PATCH 13/14] Restore minimal build.gradle without KGP for Built-in Kotlin compatibility --- android/build.gradle | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 android/build.gradle diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..a407494 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,28 @@ +group 'io.alexrintt.sharedstorage' +version '1.0-SNAPSHOT' + +apply plugin: 'com.android.library' + +android { + namespace 'io.alexrintt.sharedstorage' + compileSdk 36 + + defaultConfig { + minSdk 19 + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = '17' + } +} + +dependencies { + implementation 'androidx.documentfile:documentfile:1.0.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'com.anggrayudi:storage:1.3.0' +} From 6dbcdf2c2045e326f59c062f542724aedf73cb6e Mon Sep 17 00:00:00 2001 From: Oleksandr Babich Date: Thu, 28 May 2026 15:51:57 +0300 Subject: [PATCH 14/14] Migrate to Flutter Built-in Kotlin (AGP 9.x + Flutter 3.44 compatible) --- android/build.gradle | 6 ++++-- pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a407494..a2ed0ca 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -15,9 +15,11 @@ android { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } +} - kotlinOptions { - jvmTarget = '17' +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } } diff --git a/pubspec.yaml b/pubspec.yaml index 5e55d15..4115556 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,8 +7,8 @@ issue_tracker: https://github.com/alexrintt/shared-storage/issues documentation: https://github.com/alexrintt/shared-storage environment: - sdk: ">=2.16.0 <3.0.0" - flutter: ">=2.5.0" + sdk: ^3.12.0 + flutter: ">=3.44.0" dependencies: flutter: