@@ -951,69 +951,63 @@ public void setDynamicFeatureManager(@NonNull DynamicFeatureManager dynamicFeatu
951951 this .dynamicFeatureManager = dynamicFeatureManager ;
952952 }
953953
954- private Context dynamicFeatureContext ;
955-
956- @ UiThread
957- public void setDynamicFeatureContext (@ NonNull Context context ) {
958- ensureRunningOnMainThread ();
959- this .dynamicFeatureContext = context ;
960- }
961-
962- @ SuppressWarnings ("unused" )
963- @ UiThread
964- public void downloadDynamicFeature (int loadingUnitId ) {
965- int moduleNameIdentifier =
966- dynamicFeatureContext
967- .getResources ()
968- .getIdentifier (
969- "loadingUnit" + loadingUnitId , "string" , dynamicFeatureContext .getPackageName ());
970- String moduleName = dynamicFeatureContext .getResources ().getString (moduleNameIdentifier );
971- downloadDynamicFeature (moduleName , loadingUnitId );
972- }
973-
974- // Called by the engine upon invocation of dart loadLibrary() request
954+ /**
955+ * Called by dart's deferred load handler to request that a dart deferred library corresponding
956+ * to loadingUnitId be downloaded (if necessary) and loaded into the dart vm.
957+ *
958+ * <p>This method delegates the task to DynamicFeatureManager, which handles the download and
959+ * loading of the dart library and any assets.
960+ *
961+ * @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
962+ * automatically retrieved when loadLibrary() is called on a dart deferred
963+ * library.
964+ */
975965 @ SuppressWarnings ("unused" )
976966 @ UiThread
977- public void downloadDynamicFeature ( String moduleName , int loadingUnitId ) {
978- dynamicFeatureManager .downloadFeature ( moduleName , loadingUnitId );
967+ public void RequestDartDeferredLibrary ( int loadingUnitId ) {
968+ dynamicFeatureManager .downloadDynamicFeature ( loadingUnitId , null );
979969 }
980970
981971 /**
982- * This should be called for every loading unit to be loaded into the dart isolate.
983- *
984- * <p>abi, libName, and apkPaths are used together to search the installed apks for the desired
985- * .so library. If not found, soPath may be provided as a fallback if a pre-extracted .so exists,
986- * especially on older devices with libs compressed in the apk.
972+ * Searches each of the provided paths for a valid dart shared library .so file and resolves
973+ * symbols to load into the dart VM.
987974 *
988- * <p>Successful loading of the dart library also completes the loadLibrary() future that
975+ * <p>Successful loading of the dart library completes the future returned by loadLibrary() that
989976 * triggered the install/load process.
977+ *
978+ * @param loadingUnitId The loadingUnitId is assigned during compile time by gen_snapshot and is
979+ * automatically retrieved when loadLibrary() is called on a dart deferred
980+ * library. This is used to identify which dart deferred library the resolved
981+ * correspond to.
982+ *
983+ * @param searchPaths An array of paths in which to look for valid dart shared libraries. This
984+ * supports paths within zipped apks as long as the apks are not compressed
985+ * using the `path/to/apk.apk!path/inside/apk/lib.so` format. Paths will be
986+ * tried first to last and ends when a library is sucessfully found. When the
987+ * found library is invalid, no additional paths will be attempted.
990988 */
991989 @ UiThread
992- public void loadDartLibrary (
990+ public void loadDartDeferredLibrary (
993991 int loadingUnitId ,
994- @ NonNull String libName ,
995- @ NonNull String [] apkPaths ,
996- @ NonNull String abi ,
997- @ NonNull String soPath ) {
992+ @ NonNull String [] searchPaths ) {
998993 ensureRunningOnMainThread ();
999994 ensureAttachedToNative ();
1000- nativeLoadDartLibrary (nativePlatformViewId , loadingUnitId , libName , apkPaths , abi , soPath );
995+ nativeLoadDartDeferredLibrary (nativePlatformViewId , loadingUnitId , searchPaths );
1001996 }
1002997
1003- private native void nativeLoadDartLibrary (
998+ private native void nativeLoadDartDeferredLibrary (
1004999 long nativePlatformViewId ,
10051000 int loadingUnitId ,
1006- @ NonNull String libName ,
1007- @ NonNull String [] apkPaths ,
1008- @ NonNull String abi ,
1009- @ NonNull String soPath );
1001+ @ NonNull String [] searchPaths );
10101002
10111003 /**
10121004 * Specifies a new AssetManager that has access to the dynamic feature's assets in addition to the
10131005 * base module's assets.
10141006 *
1015- * <p>assetBundlePath is the subdirectory that the flutter assets are stored in. The typical value
1016- * is `flutter_assets`.
1007+ * @param assetManager An android AssetManager that is able to access the newly downloaded assets.
1008+ *
1009+ * @param assetBundlePath The subdirectory that the flutter assets are stored in. The typical value
1010+ * is `flutter_assets`.
10171011 */
10181012 @ UiThread
10191013 public void updateAssetManager (
@@ -1028,19 +1022,34 @@ private native void nativeUpdateAssetManager(
10281022 @ NonNull AssetManager assetManager ,
10291023 @ NonNull String assetBundlePath );
10301024
1031- // Called when an install encounters a failure during the Android portion of installing a module.
1032- // When transient is false, new attempts to install will automatically result in same error in
1033- // dart before the request is passed to Android.
1025+ /**
1026+ * Indicates that a failure was encountered during the Android portion of downloading a dynamic
1027+ * feature module and loading a dart deferred library, which is typically done by
1028+ * DynamicFeatureManager.
1029+ *
1030+ * <p>This will inform dart that the future returned by loadLibrary() should complete with an error.
1031+ *
1032+ * @param loadingUnitId The loadingUnitId that corresponds to the dart deferred library that
1033+ * failed to install.
1034+ *
1035+ * @param moduleName The name of the module that includes the loadingUnitId. This parameter is
1036+ * not necessary and used for logging purposes.
1037+ *
1038+ * @param error The error message to display.
1039+ *
1040+ * @param isTransient When isTransient is false, new attempts to install will automatically result in
1041+ * same error in dart before the request is passed to Android.
1042+ */
10341043 @ SuppressWarnings ("unused" )
10351044 @ UiThread
10361045 public void dynamicFeatureInstallFailure (
1037- @ NonNull String moduleName , int loadingUnitId , @ NonNull String error , boolean trans ) {
1046+ int loadingUnitId , String moduleName , @ NonNull String error , boolean isTransient ) {
10381047 ensureRunningOnMainThread ();
1039- nativeDynamicFeatureInstallFailure (moduleName , loadingUnitId , error , trans );
1048+ nativeDynamicFeatureInstallFailure (loadingUnitId , moduleName , error , isTransient );
10401049 }
10411050
10421051 private native void nativeDynamicFeatureInstallFailure (
1043- @ NonNull String moduleName , int loadingUnitId , @ NonNull String error , boolean trans );
1052+ int loadingUnitId , String moduleName , @ NonNull String error , boolean isTransient );
10441053
10451054 // ----- End Dynamic Features Support ----
10461055
0 commit comments