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

[cronet_http] Crash occurring on 32bit android devices since version 1.2.1 #1213

Closed
veloce opened this issue May 28, 2024 · 23 comments · Fixed by #1225
Closed

[cronet_http] Crash occurring on 32bit android devices since version 1.2.1 #1213

veloce opened this issue May 28, 2024 · 23 comments · Fixed by #1225
Assignees
Labels
package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@veloce
Copy link

veloce commented May 28, 2024

Using the official example, I consistently reproduce a crash when launching the application on a Samsung Galaxy A11 running on android 10 (using Browserstack App Live).

I'm building the application using flutter main channel.

Here are the logs:

05-28 10:47:48.334 E/FlutterLoader(22190): java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.

05-28 10:47:48.340 E/AndroidRuntime(22190): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cronet_crash_demo/com.example.cronet_crash_demo.MainActivity}: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.

05-28 10:47:48.340 E/AndroidRuntime(22190): Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.

05-28 10:47:48.340 E/AndroidRuntime(22190): Caused by: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.

The application runs fine on the same device with cronet_http version 1.2.0.

I cannot ascertain it, but based on crash reports in my application it looks like these also suffer from the crash (and probably others):

  • ZTE Blade A31
  • Galaxy A01 Core
@veloce veloce added package:cronet_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 28, 2024
@brianquinlan
Copy link
Collaborator

What version of Android are you using on your Galaxy A11?

@brianquinlan
Copy link
Collaborator

Can you reproduce this with package:cronet_http 1.3.0?

@brianquinlan
Copy link
Collaborator

I looked at the change history - the only thing that changed in package:cronet_http between 1.2.0 and 1.2.1 was upgrading the version of package:jni used from 0.7.3 to 0.9.1 and removal of the bindings_type: dart_only configuration in jnigen.yaml (but this is the default inpackage:jnigen so it shouldn't have affected anything).

I couldn't find any similar issues reported on package:jni/package:jnigen but that doesn't mean that those aren't the problem.

Any help with a reproduction that doesn't require owning a specific phone module would be helpful.

@veloce
Copy link
Author

veloce commented May 29, 2024

I do reproduce with cronet_http 1.3.0.

But I can only reproduce on these 2 devices: Samsung Galaxy A10 (android 9) and Samsung Galaxy A11 (android 10).

Capture d’écran 2024-05-29 à 09 27 25 Capture d’écran 2024-05-29 à 09 25 15

That's about all the information I can provide now. Let me know if I can help in any other way.

@brianquinlan
Copy link
Collaborator

@HosseinYousefi Can you think of any way that this issue could be related to package:jni/package:jnigen?

If not, I'll see more help to reproduce @veloce

@HosseinYousefi
Copy link
Member

I mean if the only change is the jni version. Then maybe that causes the issue. The error message doesn't seem to be related to jni though. Does it also happen on flutter stable?

@veloce
Copy link
Author

veloce commented May 30, 2024

I could reproduce on flutter stable (still with the Galaxy A11). This time I managed to get more logs:

05-30 19:20:27.977 E/FlutterLoader(12954): Flutter initialization failed.
05-30 19:20:27.977 E/FlutterLoader(12954): java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.
05-30 19:20:27.977 E/FlutterLoader(12954): App is using cpu architecture: armv8l, and the native libraries directory (with path /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm) contains the following files: [libdartjni.so]
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.util.concurrent.FutureTask.report(FutureTask.java:123)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.util.concurrent.FutureTask.get(FutureTask.java:193)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:260)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.engine.FlutterEngineGroup.<init>(FlutterEngineGroup.java:63)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.setUpFlutterEngine(FlutterActivityAndFragmentDelegate.java:328)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:193)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:638)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.Activity.performCreate(Activity.java:7955)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.Activity.performCreate(Activity.java:7944)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.os.Handler.dispatchMessage(Handler.java:107)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.os.Looper.loop(Looper.java:237)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at android.app.ActivityThread.main(ActivityThread.java:7814)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.lang.reflect.Method.invoke(Native Method)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
05-30 19:20:27.977 E/FlutterLoader(12954): Caused by: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.
05-30 19:20:27.977 E/FlutterLoader(12954): App is using cpu architecture: armv8l, and the native libraries directory (with path /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm) contains the following files: [libdartjni.so]
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:209)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:176)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.lang.Thread.run(Thread.java:919)
05-30 19:20:27.977 E/FlutterLoader(12954): Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm, /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/base.apk!/lib/armeabi-v7a, /system/lib, /product/lib]]] couldn't find "libflutter.so"
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at java.lang.System.loadLibrary(System.java:1667)
05-30 19:20:27.977 E/FlutterLoader(12954): 	at io.flutter.embedding.engine.FlutterJNI.loadLibrary(FlutterJNI.java:147)
05-30 19:20:27.978 E/FlutterLoader(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:183)
05-30 19:20:27.978 E/FlutterLoader(12954): 	... 5 more
05-30 19:20:27.978 D/AndroidRuntime(12954): Shutting down VM
05-30 19:20:27.983 E/AndroidRuntime(12954): FATAL EXCEPTION: main
05-30 19:20:27.983 E/AndroidRuntime(12954): Process: com.example.cronet_crash_demo_stable, PID: 12954
05-30 19:20:27.983 E/AndroidRuntime(12954): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cronet_crash_demo_stable/com.example.cronet_crash_demo_stable.MainActivity}: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.
05-30 19:20:27.983 E/AndroidRuntime(12954): App is using cpu architecture: armv8l, and the native libraries directory (with path /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm) contains the following files: [libdartjni.so]
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3448)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.os.Handler.dispatchMessage(Handler.java:107)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.os.Looper.loop(Looper.java:237)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.ActivityThread.main(ActivityThread.java:7814)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at java.lang.reflect.Method.invoke(Native Method)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
05-30 19:20:27.983 E/AndroidRuntime(12954): Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.
05-30 19:20:27.983 E/AndroidRuntime(12954): App is using cpu architecture: armv8l, and the native libraries directory (with path /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm) contains the following files: [libdartjni.so]
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:377)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.FlutterEngineGroup.<init>(FlutterEngineGroup.java:63)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.setUpFlutterEngine(FlutterActivityAndFragmentDelegate.java:328)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:193)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:638)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.Activity.performCreate(Activity.java:7955)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.Activity.performCreate(Activity.java:7944)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	... 11 more
05-30 19:20:27.983 E/AndroidRuntime(12954): Caused by: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.
05-30 19:20:27.983 E/AndroidRuntime(12954): App is using cpu architecture: armv8l, and the native libraries directory (with path /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm) contains the following files: [libdartjni.so]
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at java.util.concurrent.FutureTask.report(FutureTask.java:123)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at java.util.concurrent.FutureTask.get(FutureTask.java:193)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:260)
05-30 19:20:27.983 E/AndroidRuntime(12954): 	... 19 more
05-30 19:20:27.984 E/AndroidRuntime(12954): Caused by: java.lang.UnsupportedOperationException: Could not load libflutter.so this is possibly because the application is running on an architecture that Flutter Android does not support (e.g. x86) see https://docs.flutter.dev/deployment/android#what-are-the-supported-target-architectures for more detail.
05-30 19:20:27.984 E/AndroidRuntime(12954): App is using cpu architecture: armv8l, and the native libraries directory (with path /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm) contains the following files: [libdartjni.so]
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:209)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:176)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.lang.Thread.run(Thread.java:919)
05-30 19:20:27.984 E/AndroidRuntime(12954): Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/lib/arm, /data/app/com.example.cronet_crash_demo_stable-NRd6mA3lmJgtLwratNLKng==/base.apk!/lib/armeabi-v7a, /system/lib, /product/lib]]] couldn't find "libflutter.so"
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at java.lang.System.loadLibrary(System.java:1667)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.FlutterJNI.loadLibrary(FlutterJNI.java:147)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:183)
05-30 19:20:27.984 E/AndroidRuntime(12954): 	... 5 more

Full log here:

app-debug.apk_2024_5_30_21_28_7.log

@brianquinlan
Copy link
Collaborator

There are some Cronet-related log lines before the failure e.g. 05-30 19:19:50.265 I/cr_CronetLibraryLoader( 8024): Cronet version: 114.0.5735.84, arch: armv8l so cronet itself is probably not the issue.

Could you try testing these scenarios (to see if you get the same error):

  1. try running with cronetHttpNoPlay=true e.g. flutter run --dart-define=cronetHttpNoPlay=true
  2. remove the dependency on cronet_http
  3. remove the dependency on cronet_http but add one on package:jni (and maybe make one call e.g. Jni.getCachedApplicationContext()

@veloce
Copy link
Author

veloce commented May 31, 2024

Looks like it is not due to cronet itself. Based on this results I had doubts on what I submitted earlier, so I tried again with cronet_http:1.2.0 and now I see the same error (perhaps I forgot to flutter clean last time?).

For each scenario I used flutter stable and a debug build (and flutter clean in between).
Here are the results:

with cronetHttpNoPlay

  • Same error
  • I don't see the CronetLibraryLoader in the logs

app-debug.apk_2024_5_31_9_46_1.log

2 Remove dependency on cronet_http

App won't even install, I got this error:

App install failed: INSTALL_FAILED_NO_MATCHING_ABIS

3. remove the dependency on cronet_http but add one on package:jni

With package:jni version 0.9.2: same error

app-debug.apk_2024_5_31_10_14_53.log

With package:jni version 0.7.3, same error.

app-debug.apk_2024_5_31_10_24_1.log

@veloce
Copy link
Author

veloce commented May 31, 2024

Now I could finally reproduce the problem happening in cronet. I got confused because I was seeing both errors in crashlytics (this one and the libflutter.so not found).

With this Gradle config:

        ndk {
            abiFilters 'armeabi-v7a'
        }

The cronet example app is now running on the Galaxy A11.

And now I can reproduce the difference between cronet_http version 1.2.1+ where I got this error:

05-31 09:53:41.395 E/flutter (19099): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s):  Unknown public builder cache mode
05-31 09:53:41.395 E/flutter (19099): #0      CronetEngine.build (package:cronet_http/src/cronet_client.dart:137)
05-31 09:53:41.395 E/flutter (19099): #1      main (package:cronet_http_example/main.dart:20)
05-31 09:53:41.395 E/flutter (19099): #2      _runMain.<anonymous closure> (dart:ui/hooks.dart:301)
05-31 09:53:41.395 E/flutter (19099): #3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297)
05-31 09:53:41.395 E/flutter (19099): #4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)
05-31 09:53:41.395 E/flutter (19099): 

app-release.apk_2024_5_31_12_0_30.log

And cronet_http version 1.2.0 where it runs fine.

app-release.apk_2024_5_31_12_16_11.log

EDIT

I also tried with --dart-define=cronetHttpNoPlay=true and got the same error. Also made a debug build to send the logs in case it is useful:

app-debug.apk_2024_5_31_12_35_25.log

@brianquinlan
Copy link
Collaborator

It looks like that exception comes from here:
https://chromium.googlesource.com/chromium/src/+/lkgr/components/cronet/android/java/src/org/chromium/net/impl/CronetEngineBuilderImpl.java?autodive=0%2F%2F#123

It looks like the documented cache mode constants:
https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder.html#constants

Match what package:cronet_http is using:

What cache mode are you using in CronetEngine.build?

@veloce
Copy link
Author

veloce commented Jun 3, 2024

Using whatever CacheMode mode fails actually.

If I remove these lines in CronetClient:

if (cacheMode == CacheMode.disabled) {
builder.enableHttpCache(0, 0); // HTTP_CACHE_DISABLED, 0 bytes
} else if (cacheMode != null && cacheMaxSize != null) {
builder.enableHttpCache(cacheMode.index, cacheMaxSize);
}
then it works.

So the origin of the bug is in the new jni_bindings:

76deb75#diff-a5b5707c935a2d47feed8e55b3d6f5a8fa7118d44d6847ea5dc0dd892de91a2fR2549

Where the _enableHttpCache function is changed to:

  static final _enableHttpCache = ProtectedJniExtensions.lookup<
              ffi.NativeFunction<
                  jni.JniResult Function(ffi.Pointer<ffi.Void>,
                      jni.JMethodIDPtr, ffi.VarArgs<(ffi.Int64, ffi.Int64)>)>>(
          "globalEnv_CallObjectMethod")
      .asFunction<
          jni.JniResult Function(
              ffi.Pointer<ffi.Void>, jni.JMethodIDPtr, int, int)>();

Specifically this line I think: jni.JMethodIDPtr, ffi.VarArgs<(ffi.Int64, ffi.Int64)>) ; Making it not compatible anymore with 32 bit devices.

@veloce veloce changed the title [cronet_http] Crash occurring on some android devices since version 1.2.1 [cronet_http] Crash occurring on 32bit android devices since version 1.2.1 Jun 3, 2024
@brianquinlan
Copy link
Collaborator

@veloce Amazing analysis!

  static final _id_enableHttpCache = _class.instanceMethodId(
    r"enableHttpCache",
    r"(IJ)Lorg/chromium/net/CronetEngine$Builder;",
  );

+ static final _enableHttpCache = ProtectedJniExtensions.lookup<
+             ffi.NativeFunction<
+                 jni.JniResult Function(ffi.Pointer<ffi.Void>,
+                     jni.JMethodIDPtr, ffi.VarArgs<(ffi.Int64, ffi.Int64)>)>>(
+         "globalEnv_CallObjectMethod")
+     .asFunction<
+         jni.JniResult Function(
+             ffi.Pointer<ffi.Void>, jni.JMethodIDPtr, int, int)>();

  /// from: public org.chromium.net.CronetEngine$Builder enableHttpCache(int i, long j)
  /// The returned object must be released after use, by calling the [release] method.
  CronetEngine_Builder enableHttpCache(
    int i,
    int j,
  ) {
-   return _id_enableHttpCache(
-       this, const $CronetEngine_BuilderType(), [jni.JValueInt(i), j]);
+   return _enableHttpCache(
+           reference.pointer, _id_enableHttpCache as jni.JMethodIDPtr, i, j)
+       .object(const $CronetEngine_BuilderType());
  }

@brianquinlan
Copy link
Collaborator

The signature is CronetEngine.Builder enableHttpCache(int cacheMode, long maxSize)

@HosseinYousefi can you take a look at this? This looks like a package:jnigen bug.

@HosseinYousefi
Copy link
Member

The signature is CronetEngine.Builder enableHttpCache(int cacheMode, long maxSize)

@HosseinYousefi can you take a look at this? This looks like a package:jnigen bug.

@veloce Thanks for the analysis.

I will fix it.

@HosseinYousefi
Copy link
Member

HosseinYousefi commented Jun 3, 2024

The reason that this is Int64 to begin with is: dart-lang/sdk#55471

From dart-lang/native#1090 (comment):

For now I'm using the larger types like Int64 and Double, for this to work on my machine. Once the fix for dart-lang/sdk#55471 lands in stable, we can change this. Not sure if this workaround works everywhere, will wait for CI run. – Seems to be working!

Not sure this workaround works everywhere.

Famous last words!

@dcharkes
Copy link

dcharkes commented Jun 4, 2024

The reason that this is Int64 to begin with is: dart-lang/sdk#55471

We've addressed this bug, but it's not yet in a stable release.
dart-lang/sdk@c0b938c is in 3.5.0-71.0.dev and later.

So we can either:

  • Bump JNIgen to only work on a Dart 3.5 dev release / Flutter master branch
  • Request a cherry pick to 3.4.

For now I'm using the larger types like Int64 and Double, for this to work on my machine. Once the fix for dart-lang/sdk#55471 lands in stable, we can change this. Not sure if this workaround works everywhere, will wait for CI run. – Seems to be working!

Do you have mixing and matching of Double and Float based on arch @HosseinYousefi?

@HosseinYousefi
Copy link
Member

The reason that this is Int64 to begin with is: dart-lang/sdk#55471

We've addressed this bug, but it's not yet in a stable release.

dart-lang/sdk@c0b938c is in 3.5.0-71.0.dev and later.

So we can either:

  • Bump JNIgen to only work on a Dart 3.5 dev release / Flutter master branch

  • Request a cherry pick to 3.4.

For now I'm using the larger types like Int64 and Double, for this to work on my machine. Once the fix for dart-lang/sdk#55471 lands in stable, we can change this. Not sure if this workaround works everywhere, will wait for CI run. – Seems to be working!

Do you have mixing and matching of Double and Float based on arch @HosseinYousefi?

Yes, unfortunately I do. Otherwise I could use AbiSpecificInteger for now. Could you please request a cherry pick? The problem is I need to use double instead of float for macOS arm64.

I could revert the change back to using arrays but this problem only happens for macOS arm64 (which is not used much with jnigen), so I'd prefer not to do that as we gain significant performance boost from using varargs.

@dcharkes
Copy link

dcharkes commented Jun 4, 2024

How is using AbiSpecificInteger with double and float a workaround here? Wouldn't that only work properly for types that are doubles/floats? I'm trying to understand whether we should add that as a feature for dart:ffi.

@HosseinYousefi
Copy link
Member

HosseinYousefi commented Jun 4, 2024

How is using AbiSpecificInteger with double and float a workaround here? Wouldn't that only work properly for types that are doubles/floats? I'm trying to understand whether we should add that as a feature for dart:ffi.

It's just a temporary solution to fix the current issue, right? We can create an abi specific "floating point number" for float32 that is only float64 for mac arm64 (and float32 for all other archs). This fixes the varargs issue for mac arm64, while providing the same experience for every other arch.

@brianquinlan
Copy link
Collaborator

Could I go back to package:jnigen 0.8 for now and then, when the Dart 3.4.3 is released (with the cherrypick), upgrade package:jnigen and set 3.4.3 as the minimum supported SDK version?

@HosseinYousefi
Copy link
Member

Could I go back to package:jnigen 0.8 for now and then, when the Dart 3.4.3 is released (with the cherrypick), upgrade package:jnigen and set 3.4.3 as the minimum supported SDK version?

I'd rather make a version that breaks macOS arm64, as no one really uses jni for macOS for the time being. It will just break the CI which is fine.

I'll open a PR on both repos.

@brianquinlan
Copy link
Collaborator

Thanks!

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.

4 participants