You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-14 13:41:12 +00:00
Add support for Play Asset Delivery.
This only adds support for a subset of Play Asset Delivery: this causes a single install-time asset pack to always be present, but doesn't add support for dynamically downloaded asset packs.
This commit is contained in:
@@ -221,6 +221,9 @@ static const LauncherIcon launcher_adaptive_icon_backgrounds[icon_densities_coun
|
|||||||
static const int EXPORT_FORMAT_APK = 0;
|
static const int EXPORT_FORMAT_APK = 0;
|
||||||
static const int EXPORT_FORMAT_AAB = 1;
|
static const int EXPORT_FORMAT_AAB = 1;
|
||||||
|
|
||||||
|
static const char *APK_ASSETS_DIRECTORY = "res://android/build/assets";
|
||||||
|
static const char *AAB_ASSETS_DIRECTORY = "res://android/build/assetPacks/installTime/src/main/assets";
|
||||||
|
|
||||||
void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
|
void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
|
||||||
EditorExportPlatformAndroid *ea = (EditorExportPlatformAndroid *)ud;
|
EditorExportPlatformAndroid *ea = (EditorExportPlatformAndroid *)ud;
|
||||||
|
|
||||||
@@ -426,6 +429,11 @@ String EditorExportPlatformAndroid::get_package_name(const String &p_package) co
|
|||||||
return pname;
|
return pname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String EditorExportPlatformAndroid::get_assets_directory(const Ref<EditorExportPreset> &p_preset) const {
|
||||||
|
int export_format = int(p_preset->get("custom_template/export_format"));
|
||||||
|
return export_format == EXPORT_FORMAT_AAB ? AAB_ASSETS_DIRECTORY : APK_ASSETS_DIRECTORY;
|
||||||
|
}
|
||||||
|
|
||||||
bool EditorExportPlatformAndroid::is_package_name_valid(const String &p_package, String *r_error) const {
|
bool EditorExportPlatformAndroid::is_package_name_valid(const String &p_package, String *r_error) const {
|
||||||
String pname = p_package;
|
String pname = p_package;
|
||||||
|
|
||||||
@@ -2335,11 +2343,21 @@ Error EditorExportPlatformAndroid::sign_apk(const Ref<EditorExportPreset> &p_pre
|
|||||||
|
|
||||||
void EditorExportPlatformAndroid::_clear_assets_directory() {
|
void EditorExportPlatformAndroid::_clear_assets_directory() {
|
||||||
DirAccessRef da_res = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
DirAccessRef da_res = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||||
if (da_res->dir_exists("res://android/build/assets")) {
|
|
||||||
print_verbose("Clearing assets directory..");
|
// Clear the APK assets directory
|
||||||
DirAccessRef da_assets = DirAccess::open("res://android/build/assets");
|
if (da_res->dir_exists(APK_ASSETS_DIRECTORY)) {
|
||||||
|
print_verbose("Clearing APK assets directory..");
|
||||||
|
DirAccessRef da_assets = DirAccess::open(APK_ASSETS_DIRECTORY);
|
||||||
da_assets->erase_contents_recursive();
|
da_assets->erase_contents_recursive();
|
||||||
da_res->remove("res://android/build/assets");
|
da_res->remove(APK_ASSETS_DIRECTORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the AAB assets directory
|
||||||
|
if (da_res->dir_exists(AAB_ASSETS_DIRECTORY)) {
|
||||||
|
print_verbose("Clearing AAB assets directory..");
|
||||||
|
DirAccessRef da_assets = DirAccess::open(AAB_ASSETS_DIRECTORY);
|
||||||
|
da_assets->erase_contents_recursive();
|
||||||
|
da_res->remove(AAB_ASSETS_DIRECTORY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2459,6 +2477,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||||||
return ERR_UNCONFIGURED;
|
return ERR_UNCONFIGURED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const String assets_directory = get_assets_directory(p_preset);
|
||||||
String sdk_path = EDITOR_GET("export/android/android_sdk_path");
|
String sdk_path = EDITOR_GET("export/android/android_sdk_path");
|
||||||
ERR_FAIL_COND_V_MSG(sdk_path.is_empty(), ERR_UNCONFIGURED, "Android SDK path must be configured in Editor Settings at 'export/android/android_sdk_path'.");
|
ERR_FAIL_COND_V_MSG(sdk_path.is_empty(), ERR_UNCONFIGURED, "Android SDK path must be configured in Editor Settings at 'export/android/android_sdk_path'.");
|
||||||
print_verbose("Android sdk path: " + sdk_path);
|
print_verbose("Android sdk path: " + sdk_path);
|
||||||
@@ -2480,6 +2499,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||||||
if (!apk_expansion) {
|
if (!apk_expansion) {
|
||||||
print_verbose("Exporting project files..");
|
print_verbose("Exporting project files..");
|
||||||
CustomExportData user_data;
|
CustomExportData user_data;
|
||||||
|
user_data.assets_directory = assets_directory;
|
||||||
user_data.debug = p_debug;
|
user_data.debug = p_debug;
|
||||||
err = export_project_files(p_preset, rename_and_store_file_in_gradle_project, &user_data, copy_gradle_so);
|
err = export_project_files(p_preset, rename_and_store_file_in_gradle_project, &user_data, copy_gradle_so);
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
@@ -2501,7 +2521,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_verbose("Storing command line flags..");
|
print_verbose("Storing command line flags..");
|
||||||
store_file_at_path("res://android/build/assets/_cl_", command_line_flags);
|
store_file_at_path(assets_directory + "/_cl_", command_line_flags);
|
||||||
|
|
||||||
print_verbose("Updating ANDROID_HOME environment to " + sdk_path);
|
print_verbose("Updating ANDROID_HOME environment to " + sdk_path);
|
||||||
OS::get_singleton()->set_environment("ANDROID_HOME", sdk_path); //set and overwrite if required
|
OS::get_singleton()->set_environment("ANDROID_HOME", sdk_path); //set and overwrite if required
|
||||||
|
|||||||
@@ -87,11 +87,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
|||||||
EditorProgress *ep = nullptr;
|
EditorProgress *ep = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CustomExportData {
|
|
||||||
bool debug;
|
|
||||||
Vector<String> libs;
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector<PluginConfigAndroid> plugins;
|
Vector<PluginConfigAndroid> plugins;
|
||||||
String last_plugin_names;
|
String last_plugin_names;
|
||||||
uint64_t last_custom_build_time = 0;
|
uint64_t last_custom_build_time = 0;
|
||||||
@@ -109,6 +104,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
|||||||
|
|
||||||
String get_package_name(const String &p_package) const;
|
String get_package_name(const String &p_package) const;
|
||||||
|
|
||||||
|
String get_assets_directory(const Ref<EditorExportPreset> &p_preset) const;
|
||||||
|
|
||||||
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const;
|
bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const;
|
||||||
|
|
||||||
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
|
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ Error store_string_at_path(const String &p_path, const String &p_data) {
|
|||||||
// It's functionality mirrors that of the method save_apk_file.
|
// It's functionality mirrors that of the method save_apk_file.
|
||||||
// This method will be called ONLY when custom build is enabled.
|
// This method will be called ONLY when custom build is enabled.
|
||||||
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
|
Error rename_and_store_file_in_gradle_project(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
|
||||||
String dst_path = p_path.replace_first("res://", "res://android/build/assets/");
|
CustomExportData *export_data = (CustomExportData *)p_userdata;
|
||||||
|
String dst_path = p_path.replace_first("res://", export_data->assets_directory + "/");
|
||||||
print_verbose("Saving project files from " + p_path + " into " + dst_path);
|
print_verbose("Saving project files from " + p_path + " into " + dst_path);
|
||||||
Error err = store_file_at_path(dst_path, p_data);
|
Error err = store_file_at_path(dst_path, p_data);
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ const String godot_project_name_xml_string = R"(<?xml version="1.0" encoding="ut
|
|||||||
</resources>
|
</resources>
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
struct CustomExportData {
|
||||||
|
String assets_directory;
|
||||||
|
bool debug;
|
||||||
|
Vector<String> libs;
|
||||||
|
};
|
||||||
|
|
||||||
int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation);
|
int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation);
|
||||||
|
|
||||||
String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation);
|
String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation);
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
apply plugin: 'com.android.asset-pack'
|
||||||
|
|
||||||
|
assetPack {
|
||||||
|
packName = "installTime" // Directory name for the asset pack
|
||||||
|
dynamicDelivery {
|
||||||
|
deliveryType = "install-time" // Delivery mode
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,6 +72,8 @@ android {
|
|||||||
targetCompatibility versions.javaVersion
|
targetCompatibility versions.javaVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assetPacks = [":assetPacks:installTime"]
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Godot projects.
|
// The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Godot projects.
|
||||||
aaptOptions {
|
aaptOptions {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// Empty settings.gradle file to denote this directory as being the root project
|
// This is the root directory of the Godot custom build.
|
||||||
// of the Godot custom build.
|
include ':assetPacks:installTime'
|
||||||
|
|||||||
@@ -4,3 +4,6 @@ rootProject.name = "Godot"
|
|||||||
include ':app'
|
include ':app'
|
||||||
include ':lib'
|
include ':lib'
|
||||||
include ':nativeSrcsConfigs'
|
include ':nativeSrcsConfigs'
|
||||||
|
|
||||||
|
include ':assetPacks:installTime'
|
||||||
|
project(':assetPacks:installTime').projectDir = file("app/assetPacks/installTime")
|
||||||
|
|||||||
Reference in New Issue
Block a user