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

http requests fail with cronetHttpNoPlay=true with error java.lang.ClassNotFoundException #1179

Open
dreautall opened this issue Apr 19, 2024 · 8 comments · May be fixed by #1204
Open

http requests fail with cronetHttpNoPlay=true with error java.lang.ClassNotFoundException #1179

dreautall opened this issue Apr 19, 2024 · 8 comments · May be fixed by #1204
Assignees
Labels
package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@dreautall
Copy link

dreautall commented Apr 19, 2024

Hello.

I have an app that works fine with cronet_http with the GPS-Cronet. Trying to build the same app with --dart-define=cronetHttpNoPlay=true works, but the app is not usable and throws errors on http requests. The error message reads:

Exception in Java code called through JNI:
java.lang.ClassNotFoundException: Didn't find class "org/chromium/net/CronetEngine$Builder" on path:
DexPathList[[zip file "/data/app/~~xlxrt1ba2YAQ0amUKmEvNg==/com.dreautall.waterflyiii-AbxaklwneLCpq2CmygW_Jg==/base.apk"],nativeLibrary Directories=[/data/app/~~xlxrt1ba2YAQ0amUKmEvNg==/com.dreautall.waterflyiii-AbxaklwneLCpq2CmygW_Jg==/lib/arm64,/data/app/~~xlxrt1ba2YAQ0amUKmEvNg==/com.dreautall.waterflyiii-AbxaklwneLCpq2CmygW_Jg==/base.apk!/lib/arm64-v8a, /system/lib64,/system/system_ext/lib64]]

java.lang.ClassNotFoundException: Didn't find class "org/chromium/net/CronetEngine$Builder" on path:
DexPDexPathList[[zip file "/data/app/~~xlxrt1ba2YAQ0amUKmEvNg==/com.dreautall.waterflyiii-AbxaklwneLCpq2CmygW_Jg==/base.apk"],nativeLibrary Directories=[/data/app/~~xlxrt1ba2YAQ0amUKmEvNg==/com.dreautall.waterflyiii-AbxaklwneLCpq2CmygW_Jg==/lib/arm64,/data/app/~~xlxrt1ba2YAQ0amUKmEvNg==/com.dreautall.waterflyiii-AbxaklwneLCpq2CmygW_Jg==/base.apk!/lib/arm64-v8a, /system/lib64,/system/system_ext/lib64]]

at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

pubspec.yaml defines cronet_http: ^1.2.0. As no other change is outlined in the documentation, there was no code change from my side anywhere - not sure if I would have to exclude/include something in the Android manifest, gradle build or similar.

The app was built with flutter build apk --split-debug-info=build/app/outputs/symbols/aab --release --dart-define=cronetHttpNoPlay=true, the test device of the error message is a Samsung Galaxy A52 running the stock OS, but it also fails on a Pixel 8.

@dreautall dreautall added package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 19, 2024
@dreautall
Copy link
Author

dreautall commented Apr 19, 2024

Additional information after some testing: The minimum example provided in https://github.com/dart-lang/http/tree/master/pkgs/cronet_http/example only works when you leave in the line https://github.com/dart-lang/http/blob/master/pkgs/cronet_http/example/android/app/build.gradle#L76

According to the comment in that file, this line should be removed in applications. If you remove that line and run the same example app built with --dart-define=cronetHttpNoPlay=true, the app will fail with the same error message as above:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception in Java code called through JNI: java.lang.ClassNotFoundException: Didn't find class "org/chromium/net/CronetEngine$Builder" on path: DexPathList[[zip file "/data/app/~~I8ItowLGsmVoQ2kI3h2Emg==/io.flutter.cronet_http_example-IyQ_FmWiOsAjp7272xKdUg==/base.apk"],nativeLibraryDirectories=[/data/app/~~I8ItowLGsmVoQ2kI3h2Emg==/io.flutter.cronet_http_example-IyQ_FmWiOsAjp7272xKdUg==/lib/arm64, /data/app/~~I8ItowLGsmVoQ2kI3h2Emg==/io.flutter.cronet_http_example-IyQ_FmWiOsAjp7272xKdUg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]

java.lang.ClassNotFoundException: Didn't find class "org/chromium/net/CronetEngine$Builder" on path: DexPathList[[zip file "/data/app/~~I8ItowLGsmVoQ2kI3h2Emg==/io.flutter.cronet_http_example-IyQ_FmWiOsAjp7272xKdUg==/base.apk"],nativeLibraryDirectories=[/data/app/~~I8ItowLGsmVoQ2kI3h2Emg==/io.flutter.cronet_http_example-IyQ_FmWiOsAjp7272xKdUg==/lib/arm64, /data/app/~~I8ItowLGsmVoQ2kI3h2Emg==/io.flutter.cronet_http_example-IyQ_FmWiOsAjp7272xKdUg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

I'm not sure if you're able to detect whether GPS-Cronet or No-Play-Cronet is then actually used by the application, I unfortunately don't have a test device without Play Services at hand.

@veloce
Copy link

veloce commented May 10, 2024

I also reproduce this issue either using flutter build or flutter run command.

It seems that the cronetHttpNoPlay=true flag does not work in release mode.

The app works fine with flutter run --dart-define=cronetHttpNoPlay=true (I can see the cronet version in the logs), but it ceases to work if I append --release (same class not found issue).

@brianquinlan
Copy link
Collaborator

@AlexV525 Did you want to take a look at this?

@AlexV525
Copy link
Contributor

It sounds like a obfuscate issue with native methods, but since they actually exported the same entryport the guess might be incorrect. Could anyone try with minifyEnabled disabled?

@AlexV525
Copy link
Contributor

@KevinCFechtel
Copy link

With minifyEnabled and shrinkResources disabled, the error no longer occurs for me.
Unfortunately, the multiDexKeepProguard property file did not work for me.

@AlexV525
Copy link
Contributor

So the solution we should try is providing the proguard rules that exclude the cronet library. I'll request changes later. Thanks for the feedback.

@dreautall
Copy link
Author

Can confirm a proguard-rules.pro file with this content fixes the issue in release mode with minifyEnabled and shrinkResources enabled.

-keep class org.chromium.** { *; }
-keep class io.flutter.plugins.cronet_http.** { *; }

I'm no expert in proguard rules and have not tried to "trim it down" for now. Might be the second line is useless, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants