From 5afc3daf35b35c7d23b80ffcd0e8d7b9593f6f7a Mon Sep 17 00:00:00 2001 From: Stanislav Baranov Date: Thu, 7 Jun 2018 15:09:23 -0700 Subject: [PATCH] Support running bundles from zip file. (flutter/engine#5473) Support running bundles from zip file. --- engine/src/flutter/assets/directory_asset_bundle.h | 2 -- .../platform/android/platform_view_android_jni.cc | 14 +++++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/assets/directory_asset_bundle.h b/engine/src/flutter/assets/directory_asset_bundle.h index c3f231e0ae..b436eaf4f9 100644 --- a/engine/src/flutter/assets/directory_asset_bundle.h +++ b/engine/src/flutter/assets/directory_asset_bundle.h @@ -22,8 +22,6 @@ class DirectoryAssetBundle : public AssetResolver { const fml::UniqueFD descriptor_; bool is_valid_ = false; - std::string GetPathForAsset(const std::string& asset_name) const; - // |blink::AssetResolver| bool IsValid() const override; diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc index 20748b09aa..de5b1df461 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc @@ -9,6 +9,7 @@ #include #include "flutter/assets/directory_asset_bundle.h" +#include "flutter/assets/zip_asset_store.h" #include "flutter/common/settings.h" #include "flutter/fml/file.h" #include "flutter/fml/platform/android/jni_util.h" @@ -207,9 +208,16 @@ static void RunBundleAndSnapshot( if (bundlepath.size() > 0) { // If we got a bundle path, attempt to use that as a directory asset - // bundle. - asset_manager->PushBack(std::make_unique( - fml::OpenFile(bundlepath.c_str(), fml::OpenPermission::kRead, true))); + // bundle or a zip asset bundle. + const auto file_ext_index = bundlepath.rfind("."); + if (bundlepath.substr(file_ext_index) == ".zip") { + asset_manager->PushBack(std::make_unique( + bundlepath)); + } else { + asset_manager->PushBack(std::make_unique( + fml::OpenFile(bundlepath.c_str(), fml::OpenPermission::kRead, true), + bundlepath)); + } // Use the last path component of the bundle path to determine the // directory in the APK assets.