From 79b2bd8d9df923e72c8ed457b5b442f4df5a7e30 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Mon, 18 Mar 2024 16:27:46 -0700 Subject: [PATCH 1/6] wipundomepleasethanksgray --- .../flutter/embedding/engine/FlutterJNI.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 9a18c4ba57b40..1a3724943bef6 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -24,6 +24,7 @@ import androidx.annotation.Nullable; import androidx.annotation.UiThread; import androidx.annotation.VisibleForTesting; + import io.flutter.Log; import io.flutter.embedding.engine.FlutterEngine.EngineLifecycleListener; import io.flutter.embedding.engine.dart.PlatformMessageHandler; @@ -39,6 +40,7 @@ import io.flutter.view.AccessibilityBridge; import io.flutter.view.FlutterCallbackInformation; import io.flutter.view.TextureRegistry; + import java.io.IOException; import java.lang.ref.WeakReference; import java.nio.ByteBuffer; @@ -148,7 +150,24 @@ public void loadLibrary() { System.loadLibrary("flutter"); } catch (UnsatisfiedLinkError e) { // Sniff if this because libflutter.so couldn't be found. - if (e.toString().contains("couldn't find \"libflutter.so\"")) { + String couldntFindVersion = "couldn't find \"libflutter.so\""; + String notFoundVersion = "dlopen failed: library \"libflutter.so\" not found"; + + if (e.toString().contains(couldntFindVersion) + || e.toString().contains(notFoundVersion)) { + // To gather more information for https://github.com/flutter/flutter/issues/144291, + // try to do the same thing that the android code itself does, and log along the way. + // This code only exists because despite the underlying issue causing an increasingly + // large number of crashes, we still don't have a reproduction. + + Class callerClass = this.getClass(); + ClassLoader loader = callerClass.getClassLoader(); + String libname = "flutter"; + + // BEGIN COPIED CODE FROM RUNTIME.JAVA + + // END COPIED CODE FROM RUNTIME.JAVA + throw new UnsupportedOperationException( "Could not load libflutter.so this is likely because the application" + " is running on an architecture that Flutter Android does not support (e.g. x86)" From d6445a1369a35f12491c0ef650373ba08c1814e9 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 19 Mar 2024 13:01:27 -0700 Subject: [PATCH 2/6] logging --- .../flutter/embedding/engine/FlutterJNI.java | 33 ++----------------- .../engine/loader/FlutterLoader.java | 28 +++++++++++++++- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 1a3724943bef6..c2865451e686b 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -29,6 +29,7 @@ import io.flutter.embedding.engine.FlutterEngine.EngineLifecycleListener; import io.flutter.embedding.engine.dart.PlatformMessageHandler; import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager; +import io.flutter.embedding.engine.loader.ApplicationInfoLoader; import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorsStack; import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; import io.flutter.embedding.engine.renderer.SurfaceTextureWrapper; @@ -146,37 +147,7 @@ public void loadLibrary() { Log.w(TAG, "FlutterJNI.loadLibrary called more than once"); } - try { - System.loadLibrary("flutter"); - } catch (UnsatisfiedLinkError e) { - // Sniff if this because libflutter.so couldn't be found. - String couldntFindVersion = "couldn't find \"libflutter.so\""; - String notFoundVersion = "dlopen failed: library \"libflutter.so\" not found"; - - if (e.toString().contains(couldntFindVersion) - || e.toString().contains(notFoundVersion)) { - // To gather more information for https://github.com/flutter/flutter/issues/144291, - // try to do the same thing that the android code itself does, and log along the way. - // This code only exists because despite the underlying issue causing an increasingly - // large number of crashes, we still don't have a reproduction. - - Class callerClass = this.getClass(); - ClassLoader loader = callerClass.getClassLoader(); - String libname = "flutter"; - - // BEGIN COPIED CODE FROM RUNTIME.JAVA - - // END COPIED CODE FROM RUNTIME.JAVA - - throw new UnsupportedOperationException( - "Could not load libflutter.so this is likely 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.", - e); - } - throw e; - } + System.loadLibrary("flutter"); FlutterJNI.loadLibraryCalled = true; } diff --git a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index a4e1337b8f458..5317b862d99e6 100644 --- a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -182,7 +182,33 @@ public InitResult call() { try (TraceSection e = TraceSection.scoped("FlutterLoader initTask")) { ResourceExtractor resourceExtractor = initResources(appContext); - flutterJNI.loadLibrary(); + try { + flutterJNI.loadLibrary(); + Log.e("GRAYMACKALL",System.getProperty("os.arch") + " and " + Arrays.toString(new File(flutterApplicationInfo.nativeLibraryDir).list())); + } catch (UnsatisfiedLinkError unsatisfiedLinkError) { + String couldntFindVersion = "couldn't find \"libflutter.so\""; + String notFoundVersion = "dlopen failed: library \"libflutter.so\" not found"; + + if (unsatisfiedLinkError.toString().contains(couldntFindVersion) + || unsatisfiedLinkError.toString().contains(notFoundVersion)) { + // To gather more information for https://github.com/flutter/flutter/issues/144291, + // log the contents of the native directory as well as the cpu architecture. + + String cpuArch = System.getProperty("os.arch"); + String[] nativeLibs = new File(flutterApplicationInfo.nativeLibraryDir).list(); + + throw new UnsupportedOperationException( + "Could not load libflutter.so this is likely 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.\n" + + "App is using cpu architecture: " + cpuArch + " and loading native libraries: " + nativeLibs.toString(), + unsatisfiedLinkError); + } + + throw unsatisfiedLinkError; + } + flutterJNI.updateRefreshRate(); // Prefetch the default font manager as soon as possible on a background thread. From 22f9cfa3c88a462250de181f334999b73acd103b Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 19 Mar 2024 13:02:14 -0700 Subject: [PATCH 3/6] format --- .../flutter/embedding/engine/FlutterJNI.java | 3 --- .../engine/loader/FlutterLoader.java | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index c2865451e686b..e24953bd8ee1b 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -24,12 +24,10 @@ import androidx.annotation.Nullable; import androidx.annotation.UiThread; import androidx.annotation.VisibleForTesting; - import io.flutter.Log; import io.flutter.embedding.engine.FlutterEngine.EngineLifecycleListener; import io.flutter.embedding.engine.dart.PlatformMessageHandler; import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager; -import io.flutter.embedding.engine.loader.ApplicationInfoLoader; import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorsStack; import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; import io.flutter.embedding.engine.renderer.SurfaceTextureWrapper; @@ -41,7 +39,6 @@ import io.flutter.view.AccessibilityBridge; import io.flutter.view.FlutterCallbackInformation; import io.flutter.view.TextureRegistry; - import java.io.IOException; import java.lang.ref.WeakReference; import java.nio.ByteBuffer; diff --git a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 5317b862d99e6..c718766f7d40f 100644 --- a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -184,26 +184,35 @@ public InitResult call() { try { flutterJNI.loadLibrary(); - Log.e("GRAYMACKALL",System.getProperty("os.arch") + " and " + Arrays.toString(new File(flutterApplicationInfo.nativeLibraryDir).list())); + Log.e( + "GRAYMACKALL", + System.getProperty("os.arch") + + " and " + + Arrays.toString( + new File(flutterApplicationInfo.nativeLibraryDir).list())); } catch (UnsatisfiedLinkError unsatisfiedLinkError) { String couldntFindVersion = "couldn't find \"libflutter.so\""; String notFoundVersion = "dlopen failed: library \"libflutter.so\" not found"; if (unsatisfiedLinkError.toString().contains(couldntFindVersion) - || unsatisfiedLinkError.toString().contains(notFoundVersion)) { - // To gather more information for https://github.com/flutter/flutter/issues/144291, + || unsatisfiedLinkError.toString().contains(notFoundVersion)) { + // To gather more information for + // https://github.com/flutter/flutter/issues/144291, // log the contents of the native directory as well as the cpu architecture. String cpuArch = System.getProperty("os.arch"); String[] nativeLibs = new File(flutterApplicationInfo.nativeLibraryDir).list(); throw new UnsupportedOperationException( - "Could not load libflutter.so this is likely 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.\n" - + "App is using cpu architecture: " + cpuArch + " and loading native libraries: " + nativeLibs.toString(), - unsatisfiedLinkError); + "Could not load libflutter.so this is likely 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.\n" + + "App is using cpu architecture: " + + cpuArch + + " and loading native libraries: " + + nativeLibs.toString(), + unsatisfiedLinkError); } throw unsatisfiedLinkError; From 8888c31190b480d3978580c466791872b680d74a Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 19 Mar 2024 14:36:18 -0700 Subject: [PATCH 4/6] logging --- .../flutter/embedding/engine/loader/FlutterLoader.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index c718766f7d40f..774a007da42ba 100644 --- a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -198,20 +198,21 @@ public InitResult call() { || unsatisfiedLinkError.toString().contains(notFoundVersion)) { // To gather more information for // https://github.com/flutter/flutter/issues/144291, - // log the contents of the native directory as well as the cpu architecture. + // log the contents of the native libraries directory as well as the + // cpu architecture. String cpuArch = System.getProperty("os.arch"); String[] nativeLibs = new File(flutterApplicationInfo.nativeLibraryDir).list(); throw new UnsupportedOperationException( - "Could not load libflutter.so this is likely because the application" + "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.\n" + "App is using cpu architecture: " + cpuArch - + " and loading native libraries: " - + nativeLibs.toString(), + + ", and the native libraries directory contains the following .so files: " + + Arrays.toString(nativeLibs), unsatisfiedLinkError); } From 4fb372212cf734c96406f67be83b808fc293f9bb Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 19 Mar 2024 14:38:12 -0700 Subject: [PATCH 5/6] remove personal log --- .../io/flutter/embedding/engine/loader/FlutterLoader.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 774a007da42ba..573b79867035e 100644 --- a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -184,12 +184,6 @@ public InitResult call() { try { flutterJNI.loadLibrary(); - Log.e( - "GRAYMACKALL", - System.getProperty("os.arch") - + " and " - + Arrays.toString( - new File(flutterApplicationInfo.nativeLibraryDir).list())); } catch (UnsatisfiedLinkError unsatisfiedLinkError) { String couldntFindVersion = "couldn't find \"libflutter.so\""; String notFoundVersion = "dlopen failed: library \"libflutter.so\" not found"; From 4d0494f2c72c39f1c65b5f8e9f69ee6c49a9542a Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 19 Mar 2024 15:02:05 -0700 Subject: [PATCH 6/6] don't assume the files are all .so files --- .../io/flutter/embedding/engine/loader/FlutterLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 573b79867035e..55ae4f20f7874 100644 --- a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -205,7 +205,7 @@ public InitResult call() { + " for more detail.\n" + "App is using cpu architecture: " + cpuArch - + ", and the native libraries directory contains the following .so files: " + + ", and the native libraries directory contains the following files: " + Arrays.toString(nativeLibs), unsatisfiedLinkError); }