From 7e1cae2fad43d365bc606e0a7c43e6e327fde5e4 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 10 Sep 2024 16:35:40 -0700 Subject: [PATCH 1/7] replace System.loadLibrary with ReLinker.loadLibrary() --- DEPS | 2 +- shell/platform/android/BUILD.gn | 1 + shell/platform/android/build.gradle | 2 +- .../android/io/flutter/embedding/engine/FlutterJNI.java | 6 +++--- .../io/flutter/embedding/engine/loader/FlutterLoader.java | 2 +- .../flutter/embedding/engine/loader/FlutterLoaderTest.java | 4 ++-- tools/androidx/files.json | 6 ++++++ 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/DEPS b/DEPS index dcd6ebe819fb5..dd95421811e03 100644 --- a/DEPS +++ b/DEPS @@ -780,7 +780,7 @@ deps = { 'packages': [ { 'package': 'flutter/android/embedding_bundle', - 'version': 'last_updated:2024-06-18T12:13:41-0700' + 'version': 'last_updated:2024-09-10T16:32:16-0700' } ], 'condition': 'download_android_deps', diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 65797086ff0fe..6f062431cf747 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -394,6 +394,7 @@ embedding_dependencies_jars = [ "//flutter/third_party/android_embedding_dependencies/lib/viewpager-1.0.0.jar", "//flutter/third_party/android_embedding_dependencies/lib/window-1.2.0.jar", "//flutter/third_party/android_embedding_dependencies/lib/window-java-1.2.0.jar", + "//flutter/third_party/android_embedding_dependencies/lib/relinker-1.4.5.jar", ] action("check_imports") { diff --git a/shell/platform/android/build.gradle b/shell/platform/android/build.gradle index 9f8b409965b3f..e3051725da9fd 100644 --- a/shell/platform/android/build.gradle +++ b/shell/platform/android/build.gradle @@ -8,7 +8,7 @@ buildscript { mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:7.4.2" + classpath "com.android.tools.build:gradle:7.4.1" } } diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 3c966d2f4fa98..389e866829f09 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 com.getkeepsafe.relinker.ReLinker; import io.flutter.Log; import io.flutter.embedding.engine.FlutterEngine.EngineLifecycleListener; import io.flutter.embedding.engine.dart.PlatformMessageHandler; @@ -139,12 +140,11 @@ public FlutterJNI provideFlutterJNI() { * *

This method should only be called once across all FlutterJNI instances. */ - public void loadLibrary() { + public void loadLibrary(Context context) { if (FlutterJNI.loadLibraryCalled) { Log.w(TAG, "FlutterJNI.loadLibrary called more than once"); } - - System.loadLibrary("flutter"); + ReLinker.loadLibrary(context, "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 70302e7f42ae7..9416bf18ab5ed 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,7 @@ public InitResult call() { ResourceExtractor resourceExtractor = initResources(appContext); try { - flutterJNI.loadLibrary(); + flutterJNI.loadLibrary(appContext); } catch (UnsatisfiedLinkError unsatisfiedLinkError) { String couldntFindVersion = "couldn't find \"libflutter.so\""; String notFoundVersion = "dlopen failed: library \"libflutter.so\" not found"; diff --git a/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java b/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java index 98d60d4b78465..e403668887dd4 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java @@ -58,7 +58,7 @@ public void itReportsInitializedAfterInitializing() { flutterLoader.ensureInitializationComplete(ctx, null); shadowOf(getMainLooper()).idle(); assertTrue(flutterLoader.initialized()); - verify(mockFlutterJNI, times(1)).loadLibrary(); + verify(mockFlutterJNI, times(1)).loadLibrary(ctx); verify(mockFlutterJNI, times(1)).updateRefreshRate(); } @@ -70,7 +70,7 @@ public void unsatisfiedLinkErrorPathDoesNotExist() { Mockito.doThrow(new UnsatisfiedLinkError("couldn't find \"libflutter.so\"")) .when(mockFlutterJNI) - .loadLibrary(); + .loadLibrary(ctx); try { flutterLoader.startInitialization(ctx); } catch (UnsupportedOperationException e) { diff --git a/tools/androidx/files.json b/tools/androidx/files.json index 3150c04671713..a6a284a27410b 100644 --- a/tools/androidx/files.json +++ b/tools/androidx/files.json @@ -86,5 +86,11 @@ "out_file_name": "core-1.10.3.aar", "maven_dependency": "com.google.android.play:core:1.10.3", "provides": [] + }, + { + "url": "https://repo1.maven.org/maven2/com/getkeepsafe/relinker/relinker/1.4.5/relinker-1.4.5.aar", + "out_file_name": "relinker-1.4.5.aar", + "maven_dependency": "com.getkeepsafe.relinker:relinker:1.4.5", + "provides": ["com.getkeepsafe.relinker.ReLinker"] } ] From 8b5be3e8bafeadf3fbf83f4697e4d80ac27da094 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Tue, 10 Sep 2024 16:37:55 -0700 Subject: [PATCH 2/7] undo meaningless ide agp change that was for force-reloading jars --- shell/platform/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/build.gradle b/shell/platform/android/build.gradle index e3051725da9fd..9f8b409965b3f 100644 --- a/shell/platform/android/build.gradle +++ b/shell/platform/android/build.gradle @@ -8,7 +8,7 @@ buildscript { mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:7.4.1" + classpath "com.android.tools.build:gradle:7.4.2" } } From 96a3364b2638408b1a3a5ffa0a246bfdd20ac421 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Wed, 11 Sep 2024 11:54:15 -0700 Subject: [PATCH 3/7] keep old signature, mark as deprecated --- .../flutter/embedding/engine/FlutterJNI.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 389e866829f09..27994bad4aa1c 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -132,6 +132,25 @@ public FlutterJNI provideFlutterJNI() { } // BEGIN Methods related to loading for FlutterLoader. + /** + * Loads the libflutter.so C++ library. + * + *

This must be called before any other native methods, and can be overridden by tests to avoid + * loading native libraries. + * + *

This method should only be called once across all FlutterJNI instances. + * + * @deprecated replaced by {@link #loadLibrary(Context)}. + */ + @Deprecated + public void loadLibrary() { + if (FlutterJNI.loadLibraryCalled) { + Log.w(TAG, "FlutterJNI.loadLibrary called more than once"); + } + System.loadLibrary("flutter"); + FlutterJNI.loadLibraryCalled = true; + } + /** * Loads the libflutter.so C++ library. * From 6bdc1999e1d0bc7d7298174173cab2541ef3653b Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Wed, 11 Sep 2024 11:54:36 -0700 Subject: [PATCH 4/7] format --- .../android/io/flutter/embedding/engine/FlutterJNI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 27994bad4aa1c..fa22bbcd8ebff 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -139,7 +139,7 @@ public FlutterJNI provideFlutterJNI() { * loading native libraries. * *

This method should only be called once across all FlutterJNI instances. - * + * * @deprecated replaced by {@link #loadLibrary(Context)}. */ @Deprecated @@ -150,7 +150,7 @@ public void loadLibrary() { System.loadLibrary("flutter"); FlutterJNI.loadLibraryCalled = true; } - + /** * Loads the libflutter.so C++ library. * From c2286461046bfa3472fdd440a703abf83b7ae6e0 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Wed, 11 Sep 2024 11:56:13 -0700 Subject: [PATCH 5/7] Revert "format" This reverts commit 6bdc1999e1d0bc7d7298174173cab2541ef3653b. --- .../android/io/flutter/embedding/engine/FlutterJNI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index fa22bbcd8ebff..27994bad4aa1c 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -139,7 +139,7 @@ public FlutterJNI provideFlutterJNI() { * loading native libraries. * *

This method should only be called once across all FlutterJNI instances. - * + * * @deprecated replaced by {@link #loadLibrary(Context)}. */ @Deprecated @@ -150,7 +150,7 @@ public void loadLibrary() { System.loadLibrary("flutter"); FlutterJNI.loadLibraryCalled = true; } - + /** * Loads the libflutter.so C++ library. * From 8dba295aff15d604bb99f1a6094983fed24f2312 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Wed, 11 Sep 2024 11:56:20 -0700 Subject: [PATCH 6/7] Revert "keep old signature, mark as deprecated" This reverts commit 96a3364b2638408b1a3a5ffa0a246bfdd20ac421. --- .../flutter/embedding/engine/FlutterJNI.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 27994bad4aa1c..389e866829f09 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -132,25 +132,6 @@ public FlutterJNI provideFlutterJNI() { } // BEGIN Methods related to loading for FlutterLoader. - /** - * Loads the libflutter.so C++ library. - * - *

This must be called before any other native methods, and can be overridden by tests to avoid - * loading native libraries. - * - *

This method should only be called once across all FlutterJNI instances. - * - * @deprecated replaced by {@link #loadLibrary(Context)}. - */ - @Deprecated - public void loadLibrary() { - if (FlutterJNI.loadLibraryCalled) { - Log.w(TAG, "FlutterJNI.loadLibrary called more than once"); - } - System.loadLibrary("flutter"); - FlutterJNI.loadLibraryCalled = true; - } - /** * Loads the libflutter.so C++ library. * From e383d8b7bc189a249eabe044ddf88c6b6534d7a3 Mon Sep 17 00:00:00 2001 From: Gray Mackall Date: Wed, 11 Sep 2024 13:12:12 -0700 Subject: [PATCH 7/7] readme for androidx/files.json --- tools/androidx/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tools/androidx/README.md diff --git a/tools/androidx/README.md b/tools/androidx/README.md new file mode 100644 index 0000000000000..1471d12954b45 --- /dev/null +++ b/tools/androidx/README.md @@ -0,0 +1,3 @@ +Defines the additional Android build time dependencies downloaded by `engine/tools/cipd/android_embedding_bundle`, which then get uploaded to CIPD and pulled by `gclient sync` into `third_party/android_embedding_dependencies/lib/`. + +Despite the directory name, `files.json` actually includes one non-androidx dependency: [ReLinker](https://github.com/KeepSafe/ReLinker). \ No newline at end of file