Skip to content

Commit 3480319

Browse files
Added Fdroid flag (#1414)
* fdroid flavor * feat. added proot url
1 parent 9bd7829 commit 3480319

File tree

7 files changed

+117
-19
lines changed

7 files changed

+117
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ pnpm-lock.yaml
1313
.zed
1414
.idea
1515
ace-builds
16+
fdroid.bool

hooks/post-process.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@ deleteDirRecursively(resPath, [
3030
]);
3131
copyDirRecursively(localResPath, resPath);
3232
enableLegacyJni()
33+
enableStaticContext()
34+
patchTargetSdkVersion()
35+
36+
37+
function patchTargetSdkVersion() {
38+
const prefix = execSync('npm prefix').toString().trim();
39+
const gradleFile = path.join(prefix, 'platforms/android/app/build.gradle');
40+
41+
if (!fs.existsSync(gradleFile)) {
42+
console.warn('[Cordova Hook] ⚠️ build.gradle not found');
43+
return;
44+
}
45+
46+
let content = fs.readFileSync(gradleFile, 'utf-8');
47+
48+
const sdkRegex = /targetSdkVersion\s+(cordovaConfig\.SDK_VERSION|\d+)/;
49+
50+
if (sdkRegex.test(content)) {
51+
const fdroid = fs.readFileSync(path.join(prefix,'fdroid.bool'), 'utf-8').trim();
52+
var api = "34"
53+
if(fdroid == "true"){
54+
api = "28"
55+
}
56+
57+
content = content.replace(sdkRegex, 'targetSdkVersion '+api);
58+
fs.writeFileSync(gradleFile, content, 'utf-8');
59+
console.log('[Cordova Hook] ✅ Patched targetSdkVersion to '+api);
60+
} else {
61+
console.warn('[Cordova Hook] ⚠️ targetSdkVersion not found');
62+
}
63+
}
3364

3465

3566
function enableLegacyJni() {
@@ -59,6 +90,63 @@ function enableLegacyJni() {
5990
console.log('[Cordova Hook] ✅ Enabled legacy JNI packaging');
6091
}
6192

93+
function enableStaticContext() {
94+
try {
95+
const prefix = execSync('npm prefix').toString().trim();
96+
const mainActivityPath = path.join(
97+
prefix,
98+
'platforms/android/app/src/main/java/com/foxdebug/acode/MainActivity.java'
99+
);
100+
101+
if (!fs.existsSync(mainActivityPath)) {
102+
return;
103+
}
104+
105+
let content = fs.readFileSync(mainActivityPath, 'utf-8');
106+
107+
// Skip if fully patched
108+
if (
109+
content.includes('WeakReference<Context>') &&
110+
content.includes('public static Context getContext()') &&
111+
content.includes('weakContext = new WeakReference<>(this);')
112+
) {
113+
return;
114+
}
115+
116+
// Add missing imports
117+
if (!content.includes('import java.lang.ref.WeakReference;')) {
118+
content = content.replace(
119+
/import org\.apache\.cordova\.\*;/,
120+
match =>
121+
match +
122+
'\nimport android.content.Context;\nimport java.lang.ref.WeakReference;'
123+
);
124+
}
125+
126+
// Inject static field and method into class body
127+
content = content.replace(
128+
/public class MainActivity extends CordovaActivity\s*\{/,
129+
match =>
130+
match +
131+
`\n\n private static WeakReference<Context> weakContext;\n\n` +
132+
` public static Context getContext() {\n` +
133+
` return weakContext != null ? weakContext.get() : null;\n` +
134+
` }\n`
135+
);
136+
137+
// Insert weakContext assignment inside onCreate
138+
content = content.replace(
139+
/super\.onCreate\(savedInstanceState\);/,
140+
`super.onCreate(savedInstanceState);\n weakContext = new WeakReference<>(this);`
141+
);
142+
143+
fs.writeFileSync(mainActivityPath, content, 'utf-8');
144+
} catch (err) {
145+
console.error('[Cordova Hook] ❌ Failed to patch MainActivity:', err.message);
146+
}
147+
}
148+
149+
62150
/**
63151
* Copy directory recursively
64152
* @param {string} src Source directory

package-lock.json

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"cordova-plugin-websocket": {},
3838
"cordova-plugin-buildinfo": {},
3939
"cordova-plugin-system": {},
40-
"com.foxdebug.acode.rk.exec.terminal": {},
41-
"com.foxdebug.acode.rk.exec.proot": {}
40+
"com.foxdebug.acode.rk.exec.terminal": {}
4241
},
4342
"platforms": [
4443
"android"
@@ -64,7 +63,6 @@
6463
"@types/url-parse": "^1.4.11",
6564
"autoprefixer": "^10.4.19",
6665
"babel-loader": "^9.1.3",
67-
"com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot",
6866
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
6967
"cordova-android": "13.0.0",
7068
"cordova-clipboard": "^1.3.0",

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ yarn setup
6060
2. Build the project:
6161

6262
```shell
63-
yarn build <platform (android)> <free|paid> <p|prod|d|dev>
63+
yarn build <free|paid> <p|prod|d|dev> [fdroid]
6464
```
6565

66+
**Note**: Add the fdroid flag only if you want to build the F-Droid-compatible version of Acode.
67+
Omit this flag to build the regular APK (Play Store or normal version).
68+
6669
## • Contributing
6770

6871
Acode Editor is an open-source project, and we welcome contributions from the community. To contribute, follow these steps:

src/plugins/terminal/www/Terminal.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,22 @@ const Terminal = {
8585
try {
8686
let alpineUrl;
8787
let axsUrl;
88-
let prootUrl = "";
89-
let libTalloc = "";
88+
let prootUrl;
89+
let libTalloc;
9090

9191
if (arch === "arm64-v8a") {
92+
libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libtalloc.so";
93+
prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot-xed.so";
9294
axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/download/${AXS_VERSION_TAG}/axs-musl-android-arm64`;
9395
alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-minirootfs-3.21.0-aarch64.tar.gz";
9496
} else if (arch === "armeabi-v7a") {
97+
libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libtalloc.so";
98+
prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libproot-xed.so";
9599
axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/download/${AXS_VERSION_TAG}/axs-musl-android-armv7`;
96100
alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/armhf/alpine-minirootfs-3.21.0-armhf.tar.gz";
97101
} else if (arch === "x86_64") {
102+
libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libtalloc.so";
103+
prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot-xed.so";
98104
axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/download/${AXS_VERSION_TAG}/axs-musl-android-x86_64`;
99105
alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz";
100106
} else {

utils/scripts/build.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#! /bin/bash
22

3-
platform="$1"
4-
app="$2"
5-
mode="$3"
3+
app="$1"
4+
mode="$2"
5+
fdroidFlag="$3"
66
webpackmode="development"
77
cordovamode=""
88

9-
if [ -z "$platform" ]
10-
then
11-
platform="android"
9+
root=$(npm prefix)
10+
11+
12+
if [[ "$fdroidFlag" == "fdroid" ]]; then
13+
echo "true" > "$root/fdroid.bool"
14+
cordova plugin remove com.foxdebug.acode.rk.exec.proot
15+
16+
else
17+
echo "false" > "$root/fdroid.bool"
18+
cordova plugin add src/plugins/proot/
1219
fi
1320

1421
if [ -z "$mode" ]
@@ -33,7 +40,7 @@ NC=''
3340
script1="node ./utils/config.js $mode $app"
3441
script2="webpack --progress --mode $webpackmode "
3542
script3="node ./utils/loadStyles.js"
36-
script4="cordova build $platform $cordovamode"
43+
script4="cordova build android $cordovamode"
3744
eval "
3845
echo \"${RED}$script1${NC}\";
3946
$script1;

0 commit comments

Comments
 (0)