Generalize runFromBundle to support multiple bundlePaths (flutter/engine#7151)
This commit is contained in:
committed by
GitHub
parent
50efc8bc35
commit
194bf111b6
@@ -76,12 +76,20 @@ public class FlutterNativeView implements BinaryMessenger {
|
||||
}
|
||||
|
||||
public void runFromBundle(FlutterRunArguments args) {
|
||||
if (args.bundlePath == null) {
|
||||
throw new AssertionError("A bundlePath must be specified");
|
||||
if (args.bundlePath == null && args.bundlePaths.length == 0) {
|
||||
throw new AssertionError("Either bundlePath or bundlePaths must be specified");
|
||||
} else if ((args.bundlePath != null || args.defaultPath != null) &&
|
||||
args.bundlePaths.length != 0) {
|
||||
throw new AssertionError("Can't specify both bundlePath and bundlePaths");
|
||||
} else if (args.entrypoint == null) {
|
||||
throw new AssertionError("An entrypoint must be specified");
|
||||
throw new AssertionError("An entrypoint must be specified");
|
||||
}
|
||||
if (args.bundlePaths.length != 0) {
|
||||
runFromBundleInternal(args.bundlePaths, args.entrypoint, args.libraryPath);
|
||||
} else {
|
||||
runFromBundleInternal(new String[] {args.bundlePath, args.defaultPath},
|
||||
args.entrypoint, args.libraryPath);
|
||||
}
|
||||
runFromBundleInternal(args.bundlePath, args.entrypoint, args.libraryPath, args.defaultPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,17 +100,17 @@ public class FlutterNativeView implements BinaryMessenger {
|
||||
@Deprecated
|
||||
public void runFromBundle(String bundlePath, String defaultPath, String entrypoint,
|
||||
boolean reuseRuntimeController) {
|
||||
runFromBundleInternal(bundlePath, entrypoint, null, defaultPath);
|
||||
runFromBundleInternal(new String[] {bundlePath, defaultPath}, entrypoint, null);
|
||||
}
|
||||
|
||||
private void runFromBundleInternal(String bundlePath, String entrypoint,
|
||||
String libraryPath, String defaultPath) {
|
||||
private void runFromBundleInternal(String[] bundlePaths, String entrypoint,
|
||||
String libraryPath) {
|
||||
assertAttached();
|
||||
if (applicationIsRunning)
|
||||
throw new AssertionError(
|
||||
"This Flutter engine instance is already running an application");
|
||||
nativeRunBundleAndSnapshotFromLibrary(mNativePlatformView, bundlePath,
|
||||
defaultPath, entrypoint, libraryPath, mContext.getResources().getAssets());
|
||||
nativeRunBundleAndSnapshotFromLibrary(mNativePlatformView, bundlePaths,
|
||||
entrypoint, libraryPath, mContext.getResources().getAssets());
|
||||
|
||||
applicationIsRunning = true;
|
||||
}
|
||||
@@ -240,9 +248,8 @@ public class FlutterNativeView implements BinaryMessenger {
|
||||
private static native void nativeDetach(long nativePlatformViewAndroid);
|
||||
|
||||
private static native void nativeRunBundleAndSnapshotFromLibrary(
|
||||
long nativePlatformViewAndroid, String bundlePath,
|
||||
String defaultPath, String entrypoint, String libraryUrl,
|
||||
AssetManager manager);
|
||||
long nativePlatformViewAndroid, String[] bundlePaths,
|
||||
String entrypoint, String libraryUrl, AssetManager manager);
|
||||
|
||||
private static native String nativeGetObservatoryUri();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ package io.flutter.view;
|
||||
* the first time.
|
||||
*/
|
||||
public class FlutterRunArguments {
|
||||
public String[] bundlePaths;
|
||||
public String bundlePath;
|
||||
public String entrypoint;
|
||||
public String libraryPath;
|
||||
|
||||
@@ -236,15 +236,17 @@ std::unique_ptr<IsolateConfiguration> CreateIsolateConfiguration(
|
||||
static void RunBundleAndSnapshotFromLibrary(JNIEnv* env,
|
||||
jobject jcaller,
|
||||
jlong shell_holder,
|
||||
jstring jbundlepath,
|
||||
jstring jdefaultPath,
|
||||
jobjectArray jbundlepaths,
|
||||
jstring jEntrypoint,
|
||||
jstring jLibraryUrl,
|
||||
jobject jAssetManager) {
|
||||
auto asset_manager = std::make_shared<blink::AssetManager>();
|
||||
for (const auto& bundlepath :
|
||||
fml::jni::StringArrayToVector(env, jbundlepaths)) {
|
||||
if (bundlepath.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto bundlepath = fml::jni::JavaStringToString(env, jbundlepath);
|
||||
if (bundlepath.size() > 0) {
|
||||
// If we got a bundle path, attempt to use that as a directory asset
|
||||
// bundle or a zip asset bundle.
|
||||
const auto file_ext_index = bundlepath.rfind(".");
|
||||
@@ -255,28 +257,21 @@ static void RunBundleAndSnapshotFromLibrary(JNIEnv* env,
|
||||
asset_manager->PushBack(
|
||||
std::make_unique<blink::DirectoryAssetBundle>(fml::OpenDirectory(
|
||||
bundlepath.c_str(), false, fml::FilePermission::kRead)));
|
||||
|
||||
// Use the last path component of the bundle path to determine the
|
||||
// directory in the APK assets.
|
||||
const auto last_slash_index = bundlepath.rfind("/", bundlepath.size());
|
||||
if (last_slash_index != std::string::npos) {
|
||||
auto apk_asset_dir = bundlepath.substr(
|
||||
last_slash_index + 1, bundlepath.size() - last_slash_index);
|
||||
|
||||
asset_manager->PushBack(std::make_unique<blink::APKAssetProvider>(
|
||||
env, // jni environment
|
||||
jAssetManager, // asset manager
|
||||
std::move(apk_asset_dir)) // apk asset dir
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Use the last path component of the bundle path to determine the
|
||||
// directory in the APK assets.
|
||||
const auto last_slash_index = bundlepath.rfind("/", bundlepath.size());
|
||||
if (last_slash_index != std::string::npos) {
|
||||
auto apk_asset_dir = bundlepath.substr(
|
||||
last_slash_index + 1, bundlepath.size() - last_slash_index);
|
||||
|
||||
asset_manager->PushBack(std::make_unique<blink::APKAssetProvider>(
|
||||
env, // jni environment
|
||||
jAssetManager, // asset manager
|
||||
std::move(apk_asset_dir)) // apk asset dir
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const auto defaultpath = fml::jni::JavaStringToString(env, jdefaultPath);
|
||||
if (defaultpath.size() > 0) {
|
||||
asset_manager->PushBack(
|
||||
std::make_unique<blink::DirectoryAssetBundle>(fml::OpenDirectory(
|
||||
defaultpath.c_str(), false, fml::FilePermission::kRead)));
|
||||
}
|
||||
|
||||
auto isolate_configuration = CreateIsolateConfiguration(*asset_manager);
|
||||
@@ -591,9 +586,8 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
|
||||
},
|
||||
{
|
||||
.name = "nativeRunBundleAndSnapshotFromLibrary",
|
||||
.signature =
|
||||
"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;Landroid/content/res/AssetManager;)V",
|
||||
.signature = "(J[Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;Landroid/content/res/AssetManager;)V",
|
||||
.fnPtr =
|
||||
reinterpret_cast<void*>(&shell::RunBundleAndSnapshotFromLibrary),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user