Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/android/export/export_plugin.h
10278 views
1
/**************************************************************************/
2
/* export_plugin.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#ifndef DISABLE_DEPRECATED
34
#include "godot_plugin_config.h"
35
#endif // DISABLE_DEPRECATED
36
37
#include "gradle_export_util.h"
38
39
#include "core/io/image.h"
40
#include "core/io/zip_io.h"
41
#include "core/os/os.h"
42
#include "editor/export/editor_export_platform.h"
43
44
// Optional environment variables for defining confidential information. If any
45
// of these is set, they will override the values set in the credentials file.
46
const String ENV_ANDROID_KEYSTORE_DEBUG_PATH = "GODOT_ANDROID_KEYSTORE_DEBUG_PATH";
47
const String ENV_ANDROID_KEYSTORE_DEBUG_USER = "GODOT_ANDROID_KEYSTORE_DEBUG_USER";
48
const String ENV_ANDROID_KEYSTORE_DEBUG_PASS = "GODOT_ANDROID_KEYSTORE_DEBUG_PASSWORD";
49
const String ENV_ANDROID_KEYSTORE_RELEASE_PATH = "GODOT_ANDROID_KEYSTORE_RELEASE_PATH";
50
const String ENV_ANDROID_KEYSTORE_RELEASE_USER = "GODOT_ANDROID_KEYSTORE_RELEASE_USER";
51
const String ENV_ANDROID_KEYSTORE_RELEASE_PASS = "GODOT_ANDROID_KEYSTORE_RELEASE_PASSWORD";
52
53
const String DEFAULT_ANDROID_KEYSTORE_DEBUG_USER = "androiddebugkey";
54
const String DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD = "android";
55
56
struct LauncherIcon {
57
const char *export_path;
58
int dimensions = 0;
59
};
60
61
class EditorExportPlatformAndroid : public EditorExportPlatform {
62
GDCLASS(EditorExportPlatformAndroid, EditorExportPlatform);
63
64
Ref<ImageTexture> logo;
65
Ref<ImageTexture> run_icon;
66
67
struct Device {
68
String id;
69
String name;
70
String description;
71
int api_level = 0;
72
String architecture;
73
};
74
75
struct APKExportData {
76
EditorExportPlatform::PackData pd;
77
zipFile apk;
78
EditorProgress *ep = nullptr;
79
};
80
81
struct FeatureInfo {
82
String name;
83
bool required;
84
String version;
85
};
86
87
#ifndef DISABLE_DEPRECATED
88
mutable Vector<PluginConfigAndroid> android_plugins;
89
mutable SafeFlag android_plugins_changed;
90
Mutex android_plugins_lock;
91
#endif // DISABLE_DEPRECATED
92
String last_plugin_names;
93
uint64_t last_gradle_build_time = 0;
94
String last_gradle_build_dir;
95
96
Vector<Device> devices;
97
SafeFlag devices_changed;
98
Mutex device_lock;
99
#ifndef ANDROID_ENABLED
100
Thread check_for_changes_thread;
101
SafeFlag quit_request;
102
SafeFlag has_runnable_preset;
103
104
static void _check_for_changes_poll_thread(void *ud);
105
void _update_preset_status();
106
#endif
107
108
String get_project_name(const Ref<EditorExportPreset> &p_preset, const String &p_name) const;
109
110
String get_package_name(const Ref<EditorExportPreset> &p_preset, const String &p_package) const;
111
112
String get_valid_basename(const Ref<EditorExportPreset> &p_preset) const;
113
114
String get_assets_directory(const Ref<EditorExportPreset> &p_preset, int p_export_format) const;
115
116
bool is_package_name_valid(const Ref<EditorExportPreset> &p_preset, const String &p_package, String *r_error = nullptr) const;
117
bool is_project_name_valid(const Ref<EditorExportPreset> &p_preset) const;
118
119
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
120
121
static zip_fileinfo get_zip_fileinfo();
122
123
struct ABI {
124
String abi;
125
String arch;
126
127
bool operator==(const ABI &p_a) const {
128
return p_a.abi == abi;
129
}
130
131
ABI(const String &p_abi, const String &p_arch) {
132
abi = p_abi;
133
arch = p_arch;
134
}
135
ABI() {}
136
};
137
138
static Vector<ABI> get_abis();
139
140
#ifndef DISABLE_DEPRECATED
141
/// List the gdap files in the directory specified by the p_path parameter.
142
static Vector<String> list_gdap_files(const String &p_path);
143
144
static Vector<PluginConfigAndroid> get_plugins();
145
146
static Vector<PluginConfigAndroid> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets);
147
#endif // DISABLE_DEPRECATED
148
149
static Error store_in_apk(APKExportData *ed, const String &p_path, const Vector<uint8_t> &p_data, int compression_method = Z_DEFLATED);
150
151
static Error save_apk_so(void *p_userdata, const SharedObject &p_so);
152
153
static Error save_apk_file(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, uint64_t p_seed);
154
155
static Error ignore_apk_file(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, uint64_t p_seed);
156
157
static Error copy_gradle_so(void *p_userdata, const SharedObject &p_so);
158
159
bool _has_read_write_storage_permission(const Vector<String> &p_permissions);
160
161
bool _has_manage_external_storage_permission(const Vector<String> &p_permissions);
162
163
void _get_manifest_info(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions, Vector<FeatureInfo> &r_features, Vector<MetadataInfo> &r_metadata);
164
165
void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug);
166
167
bool _is_transparency_allowed(const Ref<EditorExportPreset> &p_preset) const;
168
169
void _fix_themes_xml(const Ref<EditorExportPreset> &p_preset);
170
171
void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet);
172
173
static String _get_keystore_path(const Ref<EditorExportPreset> &p_preset, bool p_debug);
174
175
static String _parse_string(const uint8_t *p_bytes, bool p_utf8);
176
177
void _fix_resources(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &r_manifest);
178
179
void _load_image_data(const Ref<Image> &p_splash_image, Vector<uint8_t> &p_data);
180
181
void _process_launcher_icons(const String &p_file_name, const Ref<Image> &p_source_image, int dimension, Vector<uint8_t> &p_data);
182
183
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background, Ref<Image> &monochrome);
184
185
void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
186
const Ref<Image> &p_main_image,
187
const Ref<Image> &p_foreground,
188
const Ref<Image> &p_background,
189
const Ref<Image> &p_monochrome);
190
191
static void _create_editor_debug_keystore_if_needed();
192
193
static Vector<ABI> get_enabled_abis(const Ref<EditorExportPreset> &p_preset);
194
195
bool _uses_vulkan(const Ref<EditorExportPreset> &p_preset) const;
196
197
Error _generate_sparse_pck_metadata(const Ref<EditorExportPreset> &p_preset, PackData &p_pack_data, Vector<uint8_t> &r_data);
198
199
protected:
200
void _notification(int p_what);
201
202
public:
203
typedef Error (*EditorExportSaveFunction)(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, uint64_t p_seed);
204
205
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
206
207
virtual void get_export_options(List<ExportOption> *r_options) const override;
208
209
virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;
210
211
virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const override;
212
213
virtual String get_name() const override;
214
215
virtual String get_os_name() const override;
216
217
virtual Ref<Texture2D> get_logo() const override;
218
219
virtual bool should_update_export_options() override;
220
221
virtual bool poll_export() override;
222
223
virtual int get_options_count() const override;
224
225
virtual String get_options_tooltip() const override;
226
227
virtual String get_option_label(int p_index) const override;
228
229
virtual String get_option_tooltip(int p_index) const override;
230
231
virtual String get_device_architecture(int p_index) const override;
232
233
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) override;
234
235
virtual Ref<Texture2D> get_run_icon() const override;
236
237
static String get_adb_path();
238
239
static String get_apksigner_path(int p_target_sdk = -1, bool p_check_executes = false);
240
241
static String get_java_path();
242
243
static String get_keytool_path();
244
245
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;
246
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
247
static bool has_valid_username_and_password(const Ref<EditorExportPreset> &p_preset, String &r_error);
248
249
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
250
251
String _get_deprecated_plugins_names(const Ref<EditorExportPreset> &p_preset) const;
252
253
String _get_plugins_names(const Ref<EditorExportPreset> &p_preset) const;
254
255
String _resolve_export_plugin_android_library_path(const String &p_android_library_path) const;
256
257
bool _is_clean_build_required(const Ref<EditorExportPreset> &p_preset);
258
259
String get_apk_expansion_fullpath(const Ref<EditorExportPreset> &p_preset, const String &p_path);
260
261
Error save_apk_expansion_file(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
262
263
void get_command_line_flags(const Ref<EditorExportPreset> &p_preset, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags, Vector<uint8_t> &r_command_line_flags);
264
265
Error sign_apk(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &export_path, EditorProgress &ep);
266
267
void _clear_assets_directory(const Ref<EditorExportPreset> &p_preset);
268
269
void _remove_copied_libs(String p_gdextension_libs_path);
270
271
static String join_list(const List<String> &p_parts, const String &p_separator);
272
static String join_abis(const Vector<ABI> &p_parts, const String &p_separator, bool p_use_arch);
273
274
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) override;
275
276
Error export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int export_format, bool should_sign, BitField<EditorExportPlatform::DebugFlags> p_flags);
277
278
virtual void get_platform_features(List<String> *r_features) const override;
279
280
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override;
281
282
EditorExportPlatformAndroid();
283
284
~EditorExportPlatformAndroid();
285
};
286
287