From 29a474fe3ece25567d823e64df56cae1e115ef3b Mon Sep 17 00:00:00 2001 From: Gray Mackall <34871572+gmackall@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:12:03 -0700 Subject: [PATCH] More logs for Android unsatisfiedLinkError (flutter/engine#53920) See https://github.com/flutter/flutter/issues/83596#issuecomment-2140605278, there are two cases: 1. IO issue 2. The directory doesn't exist Narrow down by including in the logs if the directory exists or not. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../engine/loader/FlutterLoader.java | 7 +++++-- .../engine/loader/FlutterLoaderTest.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 0c2f2e5f44..1be3f67701 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -207,8 +207,11 @@ public class FlutterLoader { + cpuArch + ", and the native libraries directory (with path " + nativeLibsDir.getAbsolutePath() - + ") contains the following files: " - + Arrays.toString(nativeLibsContents), + + ") " + + (nativeLibsDir.exists() + ? "contains the following files: " + + Arrays.toString(nativeLibsContents) + : "does not exist."), unsatisfiedLinkError); } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java index 99ddf30acd..aa9c108947 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java @@ -34,6 +34,7 @@ import java.util.concurrent.ExecutorService; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; import org.robolectric.annotation.Config; @Config(manifest = Config.NONE) @@ -61,6 +62,25 @@ public class FlutterLoaderTest { verify(mockFlutterJNI, times(1)).updateRefreshRate(); } + @Test + public void unsatisfiedLinkErrorPathDoesNotExist() { + FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); + ctx.getApplicationInfo().nativeLibraryDir = "/path/that/doesnt/exist"; + FlutterLoader flutterLoader = new FlutterLoader(mockFlutterJNI); + + Mockito.doThrow(new UnsatisfiedLinkError("couldn't find \"libflutter.so\"")) + .when(mockFlutterJNI) + .loadLibrary(); + try { + flutterLoader.startInitialization(ctx); + } catch (UnsupportedOperationException e) { + assertTrue( + e.getMessage() + .contains( + "and the native libraries directory (with path /path/that/doesnt/exist) does not exist.")); + } + } + @Test public void itDefaultsTheOldGenHeapSizeAppropriately() { FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);