-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMobileCommand.cpp
More file actions
2251 lines (1823 loc) · 53.3 KB
/
Copy pathMobileCommand.cpp
File metadata and controls
2251 lines (1823 loc) · 53.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
*
* @file MobileCommand.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira.
* All rights reserved.
* https://github.com/vixcpp/vix
*
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
*/
#include <vix/cli/commands/MobileCommand.hpp>
#include <vix/utils/Env.hpp>
#include <algorithm>
#include <charconv>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <string_view>
#include <system_error>
#include <vector>
#ifdef _WIN32
#include <io.h>
#define VIX_MOB_ISATTY(fd) _isatty(fd)
#define VIX_MOB_FILENO(stream) _fileno(stream)
#else
#include <unistd.h>
#define VIX_MOB_ISATTY(fd) ::isatty(fd)
#define VIX_MOB_FILENO(stream) ::fileno(stream)
#endif
namespace fs = std::filesystem;
namespace
{
// -------------------------------------------------------------------------
// Color handling (ANSI), auto-detected and overridable.
// -------------------------------------------------------------------------
struct MobileTheme
{
bool color = true;
std::string_view reset() const { return color ? "\x1b[0m" : ""; }
std::string_view dim() const { return color ? "\x1b[2m" : ""; }
std::string_view bold() const { return color ? "\x1b[1m" : ""; }
std::string_view green() const { return color ? "\x1b[32m" : ""; }
std::string_view cyan() const { return color ? "\x1b[36m" : ""; }
std::string_view yellow() const { return color ? "\x1b[33m" : ""; }
std::string_view red() const { return color ? "\x1b[31m" : ""; }
std::string_view gray() const { return color ? "\x1b[90m" : ""; }
};
bool mob_detect_color(std::ostream &os)
{
if (std::getenv("NO_COLOR") != nullptr)
{
return false;
}
if (std::getenv("FORCE_COLOR") != nullptr)
{
return true;
}
std::FILE *target = (&os == &std::cerr) ? stderr : stdout;
return VIX_MOB_ISATTY(VIX_MOB_FILENO(target)) != 0;
}
// -------------------------------------------------------------------------
// Output verbosity, controlled by CLI flags (modern-runtime style).
// -------------------------------------------------------------------------
enum class MobileLogMode
{
Normal,
Quiet,
Json
};
struct MobileReporter
{
MobileTheme theme;
MobileLogMode mode = MobileLogMode::Normal;
bool normal() const { return mode == MobileLogMode::Normal; }
bool json() const { return mode == MobileLogMode::Json; }
void banner(std::string_view title) const
{
if (!normal())
{
return;
}
std::cout << '\n'
<< " " << theme.green() << theme.bold() << title << theme.reset()
<< '\n';
}
void row(std::string_view key, std::string_view value,
std::string_view valueColor = {}) const
{
if (!normal())
{
return;
}
constexpr std::size_t keyWidth = 9;
std::string label(key);
if (label.size() < keyWidth)
{
label.append(keyWidth - label.size(), ' ');
}
std::cout << " " << theme.dim() << label << theme.reset() << " "
<< (valueColor.empty() ? theme.reset() : valueColor)
<< value << theme.reset() << '\n';
}
void info_line(std::string_view message) const
{
if (!normal())
{
return;
}
std::cout << " " << theme.cyan() << "info" << theme.reset()
<< " " << message << '\n';
}
void step(std::string_view message) const
{
if (!normal())
{
return;
}
std::cout << " " << theme.gray() << "\u2022 " << theme.reset()
<< message << '\n';
}
void hint(std::string_view message) const
{
if (!normal())
{
return;
}
std::cout << " " << theme.gray() << message << theme.reset() << '\n';
}
void success(std::string_view message) const
{
if (!normal())
{
return;
}
std::cout << " " << theme.green() << "\u2714" << theme.reset()
<< " " << message << '\n';
}
// Errors always print (even in quiet mode), to stderr.
void error(std::string_view message) const
{
std::cerr << " " << theme.red() << theme.bold() << "error" << theme.reset()
<< " " << message << '\n';
}
void error_hint(std::string_view message) const
{
if (message.empty())
{
return;
}
std::cerr << " " << theme.gray() << message << theme.reset() << '\n';
}
void event(std::string_view name, std::string_view key = {},
std::string_view value = {}) const
{
if (!json())
{
return;
}
std::cout << "{\"event\":\"" << name << "\"";
if (!key.empty())
{
std::cout << ",\"" << key << "\":\"" << value << "\"";
}
std::cout << "}\n";
std::cout.flush();
}
};
// -------------------------------------------------------------------------
// Output-flag parsing (--quiet / --json / --color), shared by subcommands.
// -------------------------------------------------------------------------
bool mob_take_output_flag(const std::string &arg,
MobileLogMode &mode,
int &colorOverride) // -1 auto, 0 off, 1 on
{
if (arg == "--quiet" || arg == "-q" || arg == "--silent")
{
mode = MobileLogMode::Quiet;
return true;
}
if (arg == "--json")
{
mode = MobileLogMode::Json;
return true;
}
if (arg == "--no-color" || arg == "--no-colour")
{
colorOverride = 0;
return true;
}
if (arg == "--color" || arg == "--colour")
{
colorOverride = 1;
return true;
}
return false;
}
void mob_finalize_reporter(MobileReporter &out, MobileLogMode mode, int colorOverride)
{
out.mode = mode;
out.theme.color =
(colorOverride == -1) ? mob_detect_color(std::cout) : (colorOverride == 1);
}
// -------------------------------------------------------------------------
// Option structures
// -------------------------------------------------------------------------
struct AndroidMobileOptions
{
std::string name{"Vix Mobile"};
std::string packageName{"com.vixcpp.mobile"};
std::string url{"http://127.0.0.1:8080"};
fs::path outputDirectory{"mobile/android"};
int minSdk{23};
int targetSdk{36};
int compileSdk{36};
int versionCode{1};
std::string versionName{"1.0.0"};
std::string androidGradlePluginVersion{"8.13.2"};
bool allowCleartext{false};
bool force{false};
MobileLogMode logMode{MobileLogMode::Normal};
int colorOverride{-1};
};
bool is_help_arg(const std::string &arg)
{
return arg == "-h" || arg == "--help" || arg == "help";
}
bool starts_with(std::string_view value, std::string_view prefix)
{
return value.size() >= prefix.size() &&
value.substr(0, prefix.size()) == prefix;
}
bool parse_positive_int(const std::string &value, int &out)
{
if (value.empty())
{
return false;
}
long parsed = 0;
const char *begin = value.data();
const char *end = value.data() + value.size();
auto result = std::from_chars(begin, end, parsed);
if (result.ec != std::errc{} || result.ptr != end)
{
return false;
}
if (parsed <= 0 || parsed > 100000000)
{
return false;
}
out = static_cast<int>(parsed);
return true;
}
bool consume_value(
const MobileReporter &out,
const std::vector<std::string> &args,
std::size_t &index,
const std::string &option,
std::string &value)
{
if (index + 1 >= args.size())
{
out.error("Missing value for " + option + ".");
return false;
}
value = args[++index];
if (value.empty())
{
out.error("Value for " + option + " cannot be empty.");
return false;
}
return true;
}
fs::path detect_android_sdk_directory()
{
const char *androidHome = vix::utils::vix_getenv("ANDROID_HOME");
if (androidHome != nullptr && *androidHome != '\0')
{
return fs::path(androidHome);
}
const char *androidSdkRoot = vix::utils::vix_getenv("ANDROID_SDK_ROOT");
if (androidSdkRoot != nullptr && *androidSdkRoot != '\0')
{
return fs::path(androidSdkRoot);
}
const char *home = vix::utils::vix_getenv("HOME");
if (home != nullptr && *home != '\0')
{
fs::path candidate = fs::path(home) / "Android" / "Sdk";
std::error_code ec;
if (fs::exists(candidate, ec) && !ec)
{
return candidate;
}
}
return {};
}
std::string escape_local_properties_path(const fs::path &path)
{
std::string value = path.string();
std::string output;
for (char c : value)
{
if (c == '\\')
{
output += "\\\\";
}
else if (c == ':')
{
output += "\\:";
}
else
{
output.push_back(c);
}
}
return output;
}
std::string render_local_properties()
{
const fs::path sdk = detect_android_sdk_directory();
if (sdk.empty())
{
return {};
}
return "sdk.dir=" + escape_local_properties_path(sdk) + "\n";
}
bool parse_prefixed_value(
const std::string &arg,
const char *prefix,
std::string &out)
{
const std::string p(prefix);
if (arg.rfind(p, 0) != 0)
{
return false;
}
out = arg.substr(p.size());
return true;
}
std::string xml_escape(std::string_view value)
{
std::string out;
for (char c : value)
{
switch (c)
{
case '&':
out += "&";
break;
case '<':
out += "<";
break;
case '>':
out += ">";
break;
case '"':
out += """;
break;
case '\'':
out += "\\'";
break;
default:
out.push_back(c);
break;
}
}
return out;
}
std::string java_escape(std::string_view value)
{
std::string out;
for (char c : value)
{
switch (c)
{
case '\\':
out += "\\\\";
break;
case '"':
out += "\\\"";
break;
case '\n':
out += "\\n";
break;
case '\r':
out += "\\r";
break;
case '\t':
out += "\\t";
break;
default:
out.push_back(c);
break;
}
}
return out;
}
bool valid_package_part(std::string_view part)
{
if (part.empty())
{
return false;
}
const unsigned char first =
static_cast<unsigned char>(part.front());
if (!std::isalpha(first) && part.front() != '_')
{
return false;
}
for (char ch : part)
{
const unsigned char c =
static_cast<unsigned char>(ch);
if (std::isalnum(c) || ch == '_')
{
continue;
}
return false;
}
return true;
}
bool is_valid_package_name(const std::string &packageName)
{
if (packageName.empty())
{
return false;
}
std::size_t start = 0;
int parts = 0;
while (start < packageName.size())
{
const std::size_t dot = packageName.find('.', start);
const std::string_view part =
dot == std::string::npos
? std::string_view(packageName).substr(start)
: std::string_view(packageName).substr(start, dot - start);
if (!valid_package_part(part))
{
return false;
}
++parts;
if (dot == std::string::npos)
{
break;
}
start = dot + 1;
}
return parts >= 2;
}
fs::path java_package_directory(
const fs::path &javaRoot,
const std::string &packageName)
{
fs::path path = javaRoot;
std::size_t start = 0;
while (start < packageName.size())
{
const std::size_t dot = packageName.find('.', start);
const std::string part =
dot == std::string::npos
? packageName.substr(start)
: packageName.substr(start, dot - start);
path /= part;
if (dot == std::string::npos)
{
break;
}
start = dot + 1;
}
return path;
}
std::string safe_project_name(std::string value)
{
if (value.empty())
{
return "VixMobile";
}
std::string out;
for (char ch : value)
{
const unsigned char c =
static_cast<unsigned char>(ch);
if (std::isalnum(c))
{
out.push_back(ch);
}
else if (ch == ' ' || ch == '-' || ch == '_')
{
out.push_back('_');
}
}
if (out.empty())
{
return "VixMobile";
}
if (std::isdigit(static_cast<unsigned char>(out.front())))
{
out.insert(out.begin(), 'V');
}
return out;
}
bool write_text_file(
const fs::path &path,
const std::string &content,
std::string &err)
{
err.clear();
std::error_code ec;
fs::create_directories(path.parent_path(), ec);
if (ec)
{
err = "cannot create directory: " +
path.parent_path().string() +
": " +
ec.message();
return false;
}
std::ofstream out(path, std::ios::binary | std::ios::trunc);
if (!out.is_open())
{
err = "cannot write file: " + path.string();
return false;
}
out << content;
if (!out.good())
{
err = "failed while writing file: " + path.string();
return false;
}
return true;
}
bool output_directory_is_safe(
const fs::path &directory,
bool force,
std::string &err)
{
err.clear();
std::error_code ec;
if (!fs::exists(directory, ec))
{
return true;
}
if (ec)
{
err = "cannot inspect output directory: " +
directory.string() +
": " +
ec.message();
return false;
}
if (!fs::is_directory(directory, ec))
{
err = "output path exists but is not a directory: " +
directory.string();
return false;
}
if (force)
{
return true;
}
if (fs::is_empty(directory, ec) && !ec)
{
return true;
}
err = "output directory already exists and is not empty: " +
directory.string();
return false;
}
std::string render_settings_gradle(const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "pluginManagement {\n"
<< " repositories {\n"
<< " google()\n"
<< " mavenCentral()\n"
<< " gradlePluginPortal()\n"
<< " }\n"
<< "}\n\n"
<< "dependencyResolutionManagement {\n"
<< " repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n"
<< " repositories {\n"
<< " google()\n"
<< " mavenCentral()\n"
<< " }\n"
<< "}\n\n"
<< "rootProject.name = '" << safe_project_name(options.name) << "'\n"
<< "include ':app'\n";
return out.str();
}
std::string render_root_build_gradle(
const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "plugins {\n"
<< " id 'com.android.application' version '"
<< options.androidGradlePluginVersion
<< "' apply false\n"
<< "}\n";
return out.str();
}
std::string render_app_build_gradle(
const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "plugins {\n"
<< " id 'com.android.application'\n"
<< "}\n\n"
<< "android {\n"
<< " namespace '" << options.packageName << "'\n"
<< " compileSdk " << options.compileSdk << "\n\n"
<< " defaultConfig {\n"
<< " applicationId '" << options.packageName << "'\n"
<< " minSdk " << options.minSdk << "\n"
<< " targetSdk " << options.targetSdk << "\n"
<< " versionCode " << options.versionCode << "\n"
<< " versionName '" << options.versionName << "'\n"
<< " }\n"
<< "}\n";
return out.str();
}
std::string render_manifest(const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
<< "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\">\n"
<< " <uses-permission android:name=\"android.permission.INTERNET\" />\n\n"
<< " <application\n"
<< " android:allowBackup=\"true\"\n"
<< " android:label=\"@string/app_name\"\n"
<< " android:supportsRtl=\"true\"\n"
<< " android:theme=\"@style/AppTheme\"";
if (options.allowCleartext)
{
out << "\n android:usesCleartextTraffic=\"true\"";
}
out
<< ">\n"
<< " <activity\n"
<< " android:name=\".MainActivity\"\n"
<< " android:exported=\"true\">\n"
<< " <intent-filter>\n"
<< " <action android:name=\"android.intent.action.MAIN\" />\n"
<< " <category android:name=\"android.intent.category.LAUNCHER\" />\n"
<< " </intent-filter>\n"
<< " </activity>\n"
<< " </application>\n"
<< "</manifest>\n";
return out.str();
}
std::string render_main_activity(const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "package " << options.packageName << ";\n\n"
<< "import android.annotation.SuppressLint;\n"
<< "import android.app.Activity;\n"
<< "import android.os.Bundle;\n"
<< "import android.webkit.WebResourceRequest;\n"
<< "import android.webkit.WebSettings;\n"
<< "import android.webkit.WebView;\n"
<< "import android.webkit.WebViewClient;\n\n"
<< "public class MainActivity extends Activity {\n"
<< " private static final String APP_URL = \""
<< java_escape(options.url)
<< "\";\n\n"
<< " private WebView webView;\n\n"
<< " @SuppressLint(\"SetJavaScriptEnabled\")\n"
<< " @Override\n"
<< " protected void onCreate(Bundle savedInstanceState) {\n"
<< " super.onCreate(savedInstanceState);\n\n"
<< " webView = new WebView(this);\n"
<< " setContentView(webView);\n\n"
<< " WebSettings settings = webView.getSettings();\n"
<< " settings.setJavaScriptEnabled(true);\n"
<< " settings.setDomStorageEnabled(true);\n"
<< " settings.setLoadWithOverviewMode(true);\n"
<< " settings.setUseWideViewPort(true);\n"
<< " settings.setAllowFileAccess(false);\n"
<< " settings.setAllowContentAccess(false);\n\n"
<< " webView.setWebViewClient(new WebViewClient() {\n"
<< " @Override\n"
<< " public boolean shouldOverrideUrlLoading(\n"
<< " WebView view,\n"
<< " WebResourceRequest request) {\n"
<< " view.loadUrl(request.getUrl().toString());\n"
<< " return true;\n"
<< " }\n"
<< " });\n\n"
<< " webView.loadUrl(APP_URL);\n"
<< " }\n\n"
<< " @Override\n"
<< " public void onBackPressed() {\n"
<< " if (webView != null && webView.canGoBack()) {\n"
<< " webView.goBack();\n"
<< " return;\n"
<< " }\n\n"
<< " super.onBackPressed();\n"
<< " }\n\n"
<< " @Override\n"
<< " protected void onDestroy() {\n"
<< " if (webView != null) {\n"
<< " webView.destroy();\n"
<< " webView = null;\n"
<< " }\n\n"
<< " super.onDestroy();\n"
<< " }\n"
<< "}\n";
return out.str();
}
std::string render_strings_xml(const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
<< "<resources>\n"
<< " <string name=\"app_name\">"
<< xml_escape(options.name)
<< "</string>\n"
<< "</resources>\n";
return out.str();
}
std::string render_colors_xml()
{
return R"XML(<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="vix_accent">#f37726</color>
</resources>
)XML";
}
std::string render_styles_xml()
{
return R"XML(<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:style/Theme.Material.Light.NoActionBar">
<item name="android:fontFamily">sans</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:colorAccent">@color/vix_accent</item>
</style>
</resources>
)XML";
}
std::string render_gradle_properties()
{
return R"TXT(org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=false
)TXT";
}
std::string render_readme(const AndroidMobileOptions &options)
{
std::ostringstream out;
out
<< "# " << options.name << "\n\n"
<< "Generated by `vix mobile init android`.\n\n"
<< "## App URL\n\n"
<< "```text\n"
<< options.url << "\n"
<< "```\n\n"
<< "## Build\n\n"
<< "```bash\n"
<< "gradle :app:assembleDebug\n"
<< "```\n\n"
<< "Later, `vix mobile build android` will wrap this command.\n";
return out.str();
}
bool write_android_project(
const AndroidMobileOptions &options,
std::string &err)
{
const fs::path root = options.outputDirectory;
const fs::path appRoot = root / "app";
const fs::path mainRoot = appRoot / "src" / "main";
const fs::path javaRoot = mainRoot / "java";
const fs::path packageRoot =
java_package_directory(javaRoot, options.packageName);
std::vector<std::pair<fs::path, std::string>> files{
{root / "settings.gradle", render_settings_gradle(options)},
{root / "build.gradle", render_root_build_gradle(options)},
{root / "gradle.properties", render_gradle_properties()},
{root / "README.md", render_readme(options)},
{appRoot / "build.gradle", render_app_build_gradle(options)},
{mainRoot / "AndroidManifest.xml", render_manifest(options)},
{packageRoot / "MainActivity.java", render_main_activity(options)},
{mainRoot / "res" / "values" / "strings.xml", render_strings_xml(options)},
{mainRoot / "res" / "values" / "colors.xml", render_colors_xml()},
{mainRoot / "res" / "values" / "styles.xml", render_styles_xml()}};
const std::string localProperties = render_local_properties();
if (!localProperties.empty())
{
files.push_back({root / "local.properties", localProperties});
}
for (const auto &[path, content] : files)
{
if (!write_text_file(path, content, err))
{
return false;
}
}
return true;
}
bool is_android_project_directory(const fs::path &directory)
{
std::error_code ec;
return fs::exists(directory / "app" / "build.gradle", ec) && !ec;
}