From 05543d6dbbe80fc5ac5c5800d439395131bcb5f7 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 1 Jul 2025 23:25:40 +0300 Subject: [PATCH 1/3] Fix android build ndk version and proguard config --- android/app/build.gradle.kts | 8 +++++++- android/app/proguard-rules.pro | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 android/app/proguard-rules.pro diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 42af8a9..b9438a4 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -8,7 +8,7 @@ plugins { android { namespace = "com.gerfalcon.example.offline_menu_translator" compileSdk = flutter.compileSdkVersion - ndkVersion = flutter.ndkVersion + ndkVersion = "27.2.12479018" compileOptions { sourceCompatibility = JavaVersion.VERSION_11 @@ -32,6 +32,12 @@ android { buildTypes { release { + proguardFiles( + getDefaultProguardFile("proguard-android.txt"), + "proguard-rules.pro" + ) + isMinifyEnabled = true + isShrinkResources = true // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.getByName("debug") diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 0000000..b200949 --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Please add these rules to your existing keep rules in order to suppress warnings. +# This is generated automatically by the Android Gradle plugin. +-dontwarn com.google.mediapipe.proto.CalculatorProfileProto$CalculatorProfile +-dontwarn com.google.mediapipe.proto.GraphTemplateProto$CalculatorGraphTemplate +-dontwarn com.google.protobuf.Internal$ProtoMethodMayReturnNull +-dontwarn com.google.protobuf.Internal$ProtoNonnullApi +-dontwarn com.google.protobuf.ProtoField +-dontwarn com.google.protobuf.ProtoPresenceBits +-dontwarn com.google.protobuf.ProtoPresenceCheckedField +-dontwarn javax.lang.model.SourceVersion +-dontwarn javax.lang.model.element.Element +-dontwarn javax.lang.model.element.ElementKind +-dontwarn javax.lang.model.element.Modifier +-dontwarn javax.lang.model.type.TypeMirror +-dontwarn javax.lang.model.type.TypeVisitor +-dontwarn javax.lang.model.util.SimpleTypeVisitor8 +-dontwarn org.bouncycastle.jsse.BCSSLParameters +-dontwarn org.bouncycastle.jsse.BCSSLSocket +-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider +-dontwarn org.conscrypt.Conscrypt$Version +-dontwarn org.conscrypt.Conscrypt +-dontwarn org.conscrypt.ConscryptHostnameVerifier +-dontwarn org.openjsse.javax.net.ssl.SSLParameters +-dontwarn org.openjsse.javax.net.ssl.SSLSocket +-dontwarn org.openjsse.net.ssl.OpenJSSE \ No newline at end of file From b99fa3ee0f7b7ede66eca94224e17881198484a5 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 1 Jul 2025 23:26:16 +0300 Subject: [PATCH 2/3] fix model initialization --- lib/ui/translator_screen.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ui/translator_screen.dart b/lib/ui/translator_screen.dart index 1b3f0f7..472eb40 100644 --- a/lib/ui/translator_screen.dart +++ b/lib/ui/translator_screen.dart @@ -75,6 +75,9 @@ class _TranslatorScreenState extends State { _downloadProgress = null; }); + final path = await _downloaderDataSource.getFilePath(); + await gemma.modelManager.setModelPath(path); + _inferenceModel = await gemma.createModel( modelType: ModelType.gemmaIt, supportImage: true, From a19f188b2178c7b64aeafd1f0c83b19b764d5154 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 1 Jul 2025 23:27:01 +0300 Subject: [PATCH 3/3] add support for messages without image and prevent null exception --- lib/ui/translator_screen.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/ui/translator_screen.dart b/lib/ui/translator_screen.dart index 472eb40..bd9c9b0 100644 --- a/lib/ui/translator_screen.dart +++ b/lib/ui/translator_screen.dart @@ -328,11 +328,23 @@ class _TranslatorScreenState extends State { // 1. Create the user's message object. // Use a default prompt if the user only provides an image. - final userMessage = Message.withImage( - text: text.isNotEmpty ? text : "Please translate this menu into English.", - imageBytes: image!, + Message userMessage; + if (image == null || image.isEmpty) { + userMessage = Message.text( + text: text.isNotEmpty + ? text + : "Please translate this menu into English.", + isUser: true, + ); + } else { + userMessage = Message.withImage( + text: text.isNotEmpty + ? text + : "Please translate this menu into English.", + imageBytes: image, isUser: true, ); + } // 2. Add the user's message to the UI and clear the input fields. setState(() {