Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/android/export/export_plugin.h
20836 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
class ImageTexture;
45
46
// Optional environment variables for defining confidential information. If any
47
// of these is set, they will override the values set in the credentials file.
48
const String ENV_ANDROID_KEYSTORE_DEBUG_PATH = "GODOT_ANDROID_KEYSTORE_DEBUG_PATH";
49
const String ENV_ANDROID_KEYSTORE_DEBUG_USER = "GODOT_ANDROID_KEYSTORE_DEBUG_USER";
50
const String ENV_ANDROID_KEYSTORE_DEBUG_PASS = "GODOT_ANDROID_KEYSTORE_DEBUG_PASSWORD";
51
const String ENV_ANDROID_KEYSTORE_RELEASE_PATH = "GODOT_ANDROID_KEYSTORE_RELEASE_PATH";
52
const String ENV_ANDROID_KEYSTORE_RELEASE_USER = "GODOT_ANDROID_KEYSTORE_RELEASE_USER";
53
const String ENV_ANDROID_KEYSTORE_RELEASE_PASS = "GODOT_ANDROID_KEYSTORE_RELEASE_PASSWORD";
54
55
const String DEFAULT_ANDROID_KEYSTORE_DEBUG_USER = "androiddebugkey";
56
const String DEFAULT_ANDROID_KEYSTORE_DEBUG_PASSWORD = "android";
57
58
struct LauncherIcon {
59
const char *export_path;
60
int dimensions = 0;
61
};
62
63
class AndroidEditorGradleRunner;
64
65
class EditorExportPlatformAndroid : public EditorExportPlatform {
66
GDCLASS(EditorExportPlatformAndroid, EditorExportPlatform);
67
68
Ref<ImageTexture> logo;
69
Ref<ImageTexture> run_icon;
70
71
struct Device {
72
String id;
73
String name;
74
String description;
75
int api_level = 0;
76
String architecture;
77
};
78
79
struct APKExportData {
80
EditorExportPlatform::PackData pd;
81
zipFile apk;
82
EditorProgress *ep = nullptr;
83
};
84
85
struct FeatureInfo {
86
String name;
87
bool required;
88
String version;
89
};
90
91
#ifndef DISABLE_DEPRECATED
92
mutable Vector<PluginConfigAndroid> android_plugins;
93
mutable SafeFlag android_plugins_changed;
94
Mutex android_plugins_lock;
95
#endif // DISABLE_DEPRECATED
96
String last_plugin_names;
97
uint64_t last_gradle_build_time = 0;
98
String last_gradle_build_dir;
99
100
#ifndef ANDROID_ENABLED
101
bool use_scrcpy = false;
102
Vector<Device> devices;
103
SafeFlag devices_changed;
104
Mutex device_lock;
105
106
Thread check_for_changes_thread;
107
SafeFlag quit_request;
108
SafeFlag has_runnable_preset;
109
110
static void _check_for_changes_poll_thread(void *ud);
111
void _update_preset_status();
112
#else // ANDROID_ENABLED
113
AndroidEditorGradleRunner *android_editor_gradle_runner = nullptr;
114
#endif // ANDROID_ENABLED
115
116
String get_project_name(const Ref<EditorExportPreset> &p_preset, const String &p_name) const;
117
118
String get_package_name(const Ref<EditorExportPreset> &p_preset, const String &p_package) const;
119
120
String get_valid_basename(const Ref<EditorExportPreset> &p_preset) const;
121
122
String get_assets_directory(const Ref<EditorExportPreset> &p_preset, int p_export_format) const;
123
124
bool is_package_name_valid(const Ref<EditorExportPreset> &p_preset, const String &p_package, String *r_error = nullptr) const;
125
bool is_project_name_valid(const Ref<EditorExportPreset> &p_preset) const;
126
127
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
128
129
static zip_fileinfo get_zip_fileinfo();
130
131
struct ABI {
132
String abi;
133
String arch;
134
135
bool operator==(const ABI &p_a) const {
136
return p_a.abi == abi;
137
}
138
139
ABI(const String &p_abi, const String &p_arch) {
140
abi = p_abi;
141
arch = p_arch;
142
}
143
ABI() {}
144
};
145
146
static Vector<ABI> get_abis();
147
148
#ifndef DISABLE_DEPRECATED
149
/// List the gdap files in the directory specified by the p_path parameter.
150
static Vector<String> list_gdap_files(const String &p_path);
151
152
static Vector<PluginConfigAndroid> get_plugins();
153
154
static Vector<PluginConfigAndroid> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets);
155
#endif // DISABLE_DEPRECATED
156
157
static Error store_in_apk(APKExportData *ed, const String &p_path, const Vector<uint8_t> &p_data, int compression_method = Z_DEFLATED);
158
159
static Error save_apk_so(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const SharedObject &p_so);
160
161
static Error save_apk_file(const Ref<EditorExportPreset> &p_preset, 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, bool p_delta);
162
163
static Error ignore_apk_file(const Ref<EditorExportPreset> &p_preset, 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, bool p_delta);
164
165
static Error copy_gradle_so(const Ref<EditorExportPreset> &p_preset, void *p_userdata, const SharedObject &p_so);
166
167
bool _has_read_write_storage_permission(const Vector<String> &p_permissions);
168
169
bool _has_manage_external_storage_permission(const Vector<String> &p_permissions);
170
171
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);
172
173
void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug);
174
175
bool _is_transparency_allowed(const Ref<EditorExportPreset> &p_preset) const;
176
177
void _fix_themes_xml(const Ref<EditorExportPreset> &p_preset);
178
179
void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet);
180
181
static String _get_keystore_path(const Ref<EditorExportPreset> &p_preset, bool p_debug);
182
183
static String _parse_string(const uint8_t *p_bytes, bool p_utf8);
184
185
void _fix_resources(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &r_manifest);
186
187
void _process_launcher_icons(const String &p_file_name, const Ref<Image> &p_source_image, int dimension, Vector<uint8_t> &p_data);
188
189
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background, Ref<Image> &monochrome);
190
191
void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
192
const Ref<Image> &p_main_image,
193
const Ref<Image> &p_foreground,
194
const Ref<Image> &p_background,
195
const Ref<Image> &p_monochrome);
196
197
static void _create_editor_debug_keystore_if_needed();
198
199
static Vector<ABI> get_enabled_abis(const Ref<EditorExportPreset> &p_preset);
200
201
bool _uses_vulkan(const Ref<EditorExportPreset> &p_preset) const;
202
203
Error _generate_sparse_pck_metadata(const Ref<EditorExportPreset> &p_preset, PackData &p_pack_data, Vector<uint8_t> &r_data);
204
205
protected:
206
void _notification(int p_what);
207
208
public:
209
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);
210
211
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
212
213
virtual void get_export_options(List<ExportOption> *r_options) const override;
214
215
virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;
216
217
virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const override;
218
219
virtual String get_name() const override;
220
221
virtual String get_os_name() const override;
222
223
virtual Ref<Texture2D> get_logo() const override;
224
225
virtual bool should_update_export_options() override;
226
227
#ifndef ANDROID_ENABLED
228
virtual bool poll_export() override;
229
230
virtual int get_options_count() const override;
231
232
virtual Ref<Texture2D> get_option_icon(int p_index) const override;
233
234
virtual bool is_option_runnable(int p_index) const override { return p_index != 0; }
235
236
virtual String get_options_tooltip() const override;
237
238
virtual String get_option_label(int p_index) const override;
239
240
virtual String get_option_tooltip(int p_index) const override;
241
242
virtual String get_device_architecture(int p_index) const override;
243
244
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) override;
245
#endif // ANDROID_ENABLED
246
247
virtual Ref<Texture2D> get_run_icon() const override;
248
249
static String get_adb_path();
250
251
static String get_apksigner_path(int p_target_sdk = -1, bool p_check_executes = false);
252
253
static String get_java_path();
254
255
static String get_keytool_path();
256
257
virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug = false) const override;
258
virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
259
static bool has_valid_username_and_password(const Ref<EditorExportPreset> &p_preset, String &r_error);
260
261
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
262
263
String _get_deprecated_plugins_names(const Ref<EditorExportPreset> &p_preset) const;
264
265
String _get_plugins_names(const Ref<EditorExportPreset> &p_preset) const;
266
267
String _resolve_export_plugin_android_library_path(const String &p_android_library_path) const;
268
269
bool _is_clean_build_required(const Ref<EditorExportPreset> &p_preset);
270
271
String get_apk_expansion_fullpath(const Ref<EditorExportPreset> &p_preset, const String &p_path);
272
273
Error save_apk_expansion_file(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
274
275
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);
276
277
Error sign_apk(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &export_path, EditorProgress &ep);
278
279
void _clear_assets_directory(const Ref<EditorExportPreset> &p_preset);
280
281
void _remove_copied_libs(String p_gdextension_libs_path);
282
283
static String join_list(const List<String> &p_parts, const String &p_separator);
284
static String join_abis(const Vector<ABI> &p_parts, const String &p_separator, bool p_use_arch);
285
286
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags = 0) override;
287
288
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);
289
290
virtual void get_platform_features(List<String> *r_features) const override;
291
292
virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override;
293
294
virtual void initialize() override;
295
296
~EditorExportPlatformAndroid();
297
};
298
299