diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 9a18c4ba57b40..e24953bd8ee1b 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -144,20 +144,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. - if (e.toString().contains("couldn't find \"libflutter.so\"")) { - 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..55ae4f20f7874 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,37 @@ public InitResult call() { try (TraceSection e = TraceSection.scoped("FlutterLoader initTask")) { ResourceExtractor resourceExtractor = initResources(appContext); - flutterJNI.loadLibrary(); + try { + flutterJNI.loadLibrary(); + } 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 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 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 the native libraries directory contains the following files: " + + Arrays.toString(nativeLibs), + unsatisfiedLinkError); + } + + throw unsatisfiedLinkError; + } + flutterJNI.updateRefreshRate(); // Prefetch the default font manager as soon as possible on a background thread.