google_ml_kit_flutter icon indicating copy to clipboard operation
google_ml_kit_flutter copied to clipboard

Unable to build TextRecognition in release mode on Android when targeting API 34 without adding all langages

Open Tom3652 opened this issue 2 years ago • 16 comments

PLEASE FILL THIS before submitting your issue. We have noticed that many people do NOT know how to report an issue, please follow this guide to report your issue, otherwise we wont be able to help you.

NOTE: Did you try our example app? If not, then stop try our example app and try to reproduce with it? If your app is failing and not the example app then it might be something related to your app. If the example app also fails then it is more likely for us to help you.

Title: In a few words summarize your issue. This is a short title.

Describe the bug

As the title said :

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/foxtom/StudioProjects/myapp/build/app/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions$Builder (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions$Builder (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions$Builder (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions$Builder (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))
Missing class com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions (referenced from: com.google.mlkit.vision.text.TextRecognizer com.google_mlkit_text_recognition.TextRecognizer.initialize(io.flutter.plugin.common.MethodCall))

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 30s

To Reproduce

Use targetSdkVersion 34 in your app/build.gradle file and run flutter build apk

NOTE: Did you try our example app? If not, then stop try our example app and try to reproduce with it? If your app is failing and not the example app then it might be something related to your app. If the example app also fails then it is more likely for us to help you.

Expected behavior

The app should build without requiring to add :

implementation 'com.google.mlkit:text-recognition-chinese:16.0.0'
    implementation 'com.google.mlkit:text-recognition-devanagari:16.0.0'
    implementation 'com.google.mlkit:text-recognition-japanese:16.0.0'
    implementation 'com.google.mlkit:text-recognition-korean:16.0.0'

Note : adding the above lines allow me to build with API 34, but also add an extra 30MB size to the app that i don't need.

Platform (please complete the following information):

  • OS: Android 10
  • Device: Motorola
  • Flutter/Dart Version : 3.13.5
  • Plugin version : google_mlkit_text_recognition: 0.10.0

Tom3652 avatar Sep 23 '23 15:09 Tom3652

I'm getting this one too. Using latest version 0.11.1

IAmJulianAcosta avatar Nov 05 '23 14:11 IAmJulianAcosta

@Tom3652 Adding the following to /android/app/proguard-rules.pro fixed the error for me:

-dontwarn com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions
-dontwarn com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions
-dontwarn com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions
-dontwarn com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions

IAmJulianAcosta avatar Nov 05 '23 15:11 IAmJulianAcosta

finding a solution to this. 💡

bensonarafat avatar Nov 08 '23 17:11 bensonarafat

@IAmJulianAcosta thanks this is working !

Tom3652 avatar Nov 10 '23 20:11 Tom3652

@IAmJulianAcosta While I appreciate your fix, I was wondering what this does? Why are there suddenly missing files and why do we need to manually add those lines to this file? Is this safe? Can we revert this in the future? What is this all about?

gerken-tss avatar Jan 25 '24 16:01 gerken-tss

@gerken-tss I don't remember where did I get it, IIRC, what it does is telling the compiler? that it's fine if it doesn't find the files so the build doesn't break

IAmJulianAcosta avatar Feb 28 '24 16:02 IAmJulianAcosta

Is there an alternative solution?

keezysilencer avatar Dec 27 '24 04:12 keezysilencer

Faced this issue. Without adding those languages it should compile. For now adding the dontwarn in progruard works, but we do need a fix for this.

arnabonetraker avatar Jan 06 '25 05:01 arnabonetraker

after applying @IAmJulianAcosta 's steps, it still gave the error for me. Adding minifyEnabled true and proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' inside android>buildTypes>release fixed it!

android {
  buildTypes {
          release {
              // TODO: Add your own signing config for the release build.
              // Signing with the debug keys for now, so `flutter run --release` works.
              signingConfig = signingConfigs.debug
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
}

Rea-Mart avatar Jan 06 '25 07:01 Rea-Mart

this wasted my whole day, still wont get fixes :()

fisforfaheem avatar Mar 12 '25 21:03 fisforfaheem

@Tom3652 Adding the following to /android/app/proguard-rules.pro fixed the error for me:

-dontwarn com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions
-dontwarn com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions
-dontwarn com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions
-dontwarn com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions$Builder
-dontwarn com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions

finding a solution to this. 💡

houssamaziez avatar Apr 05 '25 14:04 houssamaziez

Whe. Will this be fixed automatic

fisforfaheem avatar Apr 05 '25 14:04 fisforfaheem

Image

fisforfaheem avatar May 04 '25 20:05 fisforfaheem

@Tom3652 I add implementation("com.google.mlkit:text-recognition-chinese:16.0.0") implementation("com.google.mlkit:text-recognition-devanagari:16.0.0") implementation("com.google.mlkit:text-recognition-japanese:16.0.0") implementation("com.google.mlkit:text-recognition-korean:16.0.0") above lines in build.gradle.kts and make apk like "flutter build apk --release". Apk size is 106MB. What do you think is it really big??

nouman-6 avatar Jul 02 '25 04:07 nouman-6