-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathandroid.cpp
More file actions
105 lines (92 loc) · 2.81 KB
/
android.cpp
File metadata and controls
105 lines (92 loc) · 2.81 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
#include "android.h"
#include "ofLog.h"
#include "Utils.h"
#include "ofUtils.h"
#include <regex>
std::string androidProject::LOG_NAME = "androidProject";
androidProject::androidProject(const std::string & target) : baseProject(target) {}
bool androidProject::createProjectFile(){
bOverwrite = false;
for (auto & f : vector<fs::path> {
"build.gradle",
"gradle",
"ofApp/gradle.properties",
"ofApp/proguard-rules.pro",
"ofApp/src/AndroidManifest.xml",
"ofApp/src/ic_launcher-playstore.png",
"proguard.cfg",
"settings.gradle",
"template.config",
"src/main.cpp",
}) {
copyTemplateFiles.push_back({
templatePath / f,
projectDir / f
});
}
for (auto & f : vector<fs::path> {
"src/ofApp.h",
"src/ofApp.cpp",
"ofApp/src/CMakeLists.txt",
"ofApp/src/java/cc/openframeworks/android/OFActivity.java",
"local.properties",
"gradle.properties",
"ofApp/build.gradle",
}) {
if (!fs::exists(projectDir / f)) {
copyTemplateFiles.push_back({
templatePath / f,
projectDir / f
});
}
}
copyTemplateFiles.push_back({
templatePath / "ofApp" / "build.gradle",
projectDir / "ofApp" / "build.gradle",
{ { "emptyExample", projectName } }
});
for (auto & c : copyTemplateFiles) {
c.run();
}
try {
fs::create_directories(projectDir / "ofApp");
} catch (const std::exception & e) {
ofLogError(LOG_NAME) << "Error creating directories: " << e.what();
return false;
}
// Copy the `src/` folder from the template
try {
fs::copy(
templatePath / "ofApp",
projectDir / "ofApp",
fs::copy_options::recursive | (bOverwrite ? fs::copy_options::overwrite_existing : fs::copy_options::update_existing)
);
} catch (fs::filesystem_error & e) {
ofLogError(LOG_NAME) << "Copy failed: " << e.what();
return false;
}
try {
fs::copy(templatePath / "ofApp/src/res", projectDir / "ofApp/src/res", fs::copy_options::recursive);
} catch (fs::filesystem_error & e) {
ofLogError(LOG_NAME) << "Error copying res folder: " << e.what();
}
// Copy additional Android-specific template folders
for (const auto & p : { "srcJava", "gradle" }) { // ✅ Removed "res" from this loop
try {
fs::copy(templatePath / p, projectDir / p, fs::copy_options::recursive);
} catch (fs::filesystem_error & e) {
ofLogError(LOG_NAME) << "Error copying " << p << ": " << e.what();
}
}
findandreplaceInTexfile(projectDir / "ofApp/res/values/strings.xml", "TEMPLATE_APP_NAME", projectName);
fs::path from = projectDir / "ofApp/src/java/cc/openframeworks/android";
fs::path to = projectDir / ("ofApp/src/java/cc/openframeworks/android");
try {
fs::create_directories(to.parent_path());
fs::rename(from, to);
} catch (const std::exception & e) {
ofLogError(LOG_NAME) << "Error renaming package directory: " << e.what();
}
ofLogNotice(LOG_NAME) << "Android Project created successfully!";
return true;
}