Add more logging for UnsatisfiedLinkError (flutter/engine#51534)

Add additional logging for this error, because there are still no local reproduction cases.

related to https://github.com/flutter/flutter/issues/144291

follow up to https://github.com/flutter/engine/pull/50247

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Gray Mackall 2024-03-20 08:34:05 -07:00 committed by GitHub
parent 427b0641bb
commit 156c44315f
2 changed files with 32 additions and 15 deletions

View File

@ -144,20 +144,7 @@ public class FlutterJNI {
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;
}

View File

@ -182,7 +182,37 @@ public class FlutterLoader {
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.