Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): replace Kt Android ext with Java equivalent for compatibility #7

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions quill_native_bridge/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ packages:
path: "../../quill_native_bridge_android"
relative: true
source: path
version: "0.0.1-dev.3"
version: "0.0.1-dev.4"
quill_native_bridge_ios:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -400,10 +400,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: e1d0cc62e65dc2561f5071fcbccecf58ff20c344f8f3dc7d4922df372a11df1f
sha256: "10169d3934549017f0ae278ccb07f828f9d6ea21573bab0fb77b0e1ef0fce454"
url: "https://pub.dev"
source: hosted
version: "5.7.1"
version: "5.7.2"
xml:
dependency: transitive
description:
Expand Down
4 changes: 4 additions & 0 deletions quill_native_bridge_android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 0.0.1-dev.4

- Fixes [build failure](https://github.com/singerdmx/flutter-quill/issues/2340) by avoiding `androidx.core.graphics.decodeBitmap` (causing compatibility issues).

## 0.0.1-dev.3

- Require `quill_native_bridge_platform_interface` minimum version `0.0.1-dev.4`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import android.net.Uri
import android.os.Build
import androidx.core.graphics.decodeBitmap
import dev.flutterquill.quill_native_bridge.generated.FlutterError
import java.io.ByteArrayOutputStream
import java.io.FileNotFoundException
Expand Down Expand Up @@ -175,7 +174,7 @@ object ClipboardReadImageHandler {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Api 29 and above (use a newer API)
val source = ImageDecoder.createSource(context.contentResolver, imageUri)
source.decodeBitmap { _, _ -> }
ImageDecoder.decodeBitmap(source)
} else {
// Backward compatibility with older versions
checkNotNull(context.contentResolver.openInputStream(imageUri)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object ClipboardWriteImageHandler {
val bitmap: Bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Api 29 and above (use a newer API)
try {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(imageBytes))
val source = ImageDecoder.createSource(imageBytes)
ImageDecoder.decodeBitmap(source)
} catch (e: Exception) {
throw FlutterError(
"INVALID_IMAGE",
Expand Down
2 changes: 1 addition & 1 deletion quill_native_bridge_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: quill_native_bridge_android
description: "Android implementation of the quill_native_bridge plugin."
version: 0.0.1-dev.3
version: 0.0.1-dev.4
homepage: https://github.com/FlutterQuill/quill-native-bridge/tree/main/quill_native_bridge_android
repository: https://github.com/FlutterQuill/quill-native-bridge/tree/main/quill_native_bridge_android
issue_tracker: https://github.com/FlutterQuill/quill-native-bridge/issues?q=is%3Aissue+is%3Aopen+label%3A%22platform-android%22
Expand Down
32 changes: 32 additions & 0 deletions quill_native_bridge_android/test/bug_fix_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';

void main() {
test(
'ensure compatibility by avoiding unresolved image decoder import (See https://github.com/singerdmx/flutter-quill/issues/2340)',
() {
// TODO: Avoid hardcoding the `dev/flutterquill/quill_native_bridge/`
// in here and in pigeons/messages.dart
final targetDirectory = Directory(
'android/src/main/kotlin/dev/flutterquill/quill_native_bridge/');

expect(targetDirectory.existsSync(), isTrue,
reason: 'Target directory does not exist: ${targetDirectory.path}');

for (final entity in targetDirectory.listSync(recursive: true)) {
if (entity is! File) {
continue;
}
final content = entity.readAsStringSync();
expect(
content.contains('import androidx.core.graphics.decodeBitmap'),
isFalse,
reason: 'Compatibility issue detected in ${entity.path}. '
'Avoid using `androidx.core.graphics.decodeBitmap`. '
'For more details, see https://github.com/FlutterQuill/quill-native-bridge/pull/7',
);
}
},
);
}