这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit b950efe

Browse files
Added: Add support for TERMUX_APP_PACKAGE_MANAGER and TERMUX_APP_PACKAGE_VARIANT to build APKs with different package manager configurations
The `TermuxBootstrap` class has been added that defines the `PackageManager` and `PackageVariant` classes for the supported package manager configurations for the app. The variant is defined by the `project.ext.packageVariant` value in the `app/build.gradle` and its value is used by the `build.gradle` to pack its respective bootstrap zips in the app APK at build time and the value is used to set `TermuxBootstrap.TERMUX_APP_PACKAGE_MANAGER` and `TermuxBootstrap.TERMUX_APP_PACKAGE_VARIANT` static values that are used at runtime by the app to run variant specific code. The manager is automatically extracted from the variant as the substring before first dash `-`. The default variant is `apt-android-7` and it can either be replaced in `app/build.gradle` manually or the `TERMUX_PACKAGE_VARIANT` env variable can be exported in which the build command is run. The `TERMUX_APP_PACKAGE_MANAGER` and `TERMUX_APP_PACKAGE_VARIANT` environmental variables will be exported by the app and they will also be added in Termux app info in about page and reports, allowing users and devs to know which variant is currently installed. Bootstrap of a different variant must not be manually installed by the user after app installation by replacing `$PREFIX` since app code is dependant on the variant used to build the APK. Currently, `apt-android-7` and `apt-android-5` variants will be built for by the workflows but they will fail for `apt-android-5` since `build.gradle` support is currently not enabled and will be enabled by a pull request that adds support for Android 5. The workflow needs to try to build the `apt-android-5` variant so that pull request builds are generated.
1 parent 4b3b1a5 commit b950efe

File tree

8 files changed

+250
-25
lines changed

8 files changed

+250
-25
lines changed

.github/workflows/attach_debug_apks_to_release.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ on:
88
jobs:
99
attach-apks:
1010
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
package_variant: [ apt-android-7, apt-android-5 ]
1115
env:
1216
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
1318
steps:
1419
- name: Clone repository
1520
uses: actions/checkout@v2
@@ -18,6 +23,8 @@ jobs:
1823

1924
- name: Build and attach APKs to release
2025
shell: bash {0}
26+
env:
27+
PACKAGE_VARIANT: ${{ matrix.package_variant }}
2128
run: |
2229
exit_on_error() {
2330
echo "$1"
@@ -34,13 +41,14 @@ jobs:
3441
fi
3542
3643
APK_DIR_PATH="./app/build/outputs/apk/debug"
37-
APK_VERSION_TAG="$RELEASE_VERSION_NAME+github-debug"
44+
APK_VERSION_TAG="$RELEASE_VERSION_NAME+${{ env.PACKAGE_VARIANT }}-github-debug"
3845
APK_BASENAME_PREFIX="termux-app_$APK_VERSION_TAG"
3946
40-
echo "Building APKs for '$RELEASE_VERSION_NAME' release"
47+
echo "Building APKs for 'APK_VERSION_TAG' release"
4148
export TERMUX_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
49+
export TERMUX_PACKAGE_VARIANT="${{ env.PACKAGE_VARIANT }}" # Used by app/build.gradle
4250
if ! ./gradlew assembleDebug; then
43-
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release."
51+
exit_on_error "Build failed for '$APK_VERSION_TAG' release."
4452
fi
4553
4654
echo "Validating APKs"
@@ -58,8 +66,8 @@ jobs:
5866
"${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \
5967
"${APK_BASENAME_PREFIX}_x86_64.apk" \
6068
"${APK_BASENAME_PREFIX}_x86.apk" \
61-
> sha256sums); then
62-
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
69+
> "${APK_BASENAME_PREFIX}_sha256sums"); then
70+
exit_on_error "Generate sha25sums failed for '$APK_VERSION_TAG' release."
6371
fi
6472
6573
echo "Attaching APKs to github release"
@@ -70,7 +78,7 @@ jobs:
7078
-a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \
7179
-a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_x86_64.apk" \
7280
-a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_x86.apk" \
73-
-a "$APK_DIR_PATH/sha256sums" \
81+
-a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_sha256sums" \
7482
"$RELEASE_VERSION_NAME"; then
75-
exit_on_error "Attach APKs to release failed for '$RELEASE_VERSION_NAME' release."
83+
exit_on_error "Attach APKs to release failed for '$APK_VERSION_TAG' release."
7684
fi

.github/workflows/debug_build.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
package_variant: [ apt-android-7, apt-android-5 ]
18+
1419
steps:
1520
- name: Clone repository
1621
uses: actions/checkout@v2
1722

1823
- name: Build APKs
1924
shell: bash {0}
25+
env:
26+
PACKAGE_VARIANT: ${{ matrix.package_variant }}
2027
run: |
2128
exit_on_error() { echo "$1"; exit 1; }
2229
@@ -35,19 +42,20 @@ jobs:
3542
fi
3643
3744
APK_DIR_PATH="./app/build/outputs/apk/debug"
38-
APK_VERSION_TAG="$RELEASE_VERSION_NAME-github-debug" # Note the "-", GITHUB_SHA will already have "+" before it
45+
APK_VERSION_TAG="$RELEASE_VERSION_NAME-${{ env.PACKAGE_VARIANT }}-github-debug" # Note the "-", GITHUB_SHA will already have "+" before it
3946
APK_BASENAME_PREFIX="termux-app_$APK_VERSION_TAG"
4047
4148
# Used by attachment steps later
4249
echo "APK_DIR_PATH=$APK_DIR_PATH" >> $GITHUB_ENV
4350
echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV
4451
echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV
4552
46-
echo "Building APKs for '$RELEASE_VERSION_NAME' build"
53+
echo "Building APKs for 'APK_VERSION_TAG' build"
4754
export TERMUX_APP_VERSION_NAME="${RELEASE_VERSION_NAME/v/}" # Used by app/build.gradle
4855
export TERMUX_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
56+
export TERMUX_PACKAGE_VARIANT="${{ env.PACKAGE_VARIANT }}" # Used by app/build.gradle
4957
if ! ./gradlew assembleDebug; then
50-
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' build."
58+
exit_on_error "Build failed for '$APK_VERSION_TAG' build."
5159
fi
5260
5361
echo "Validating APKs"
@@ -65,8 +73,8 @@ jobs:
6573
"${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \
6674
"${APK_BASENAME_PREFIX}_x86_64.apk" \
6775
"${APK_BASENAME_PREFIX}_x86.apk" \
68-
> sha256sums); then
69-
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
76+
> "${APK_BASENAME_PREFIX}_sha256sums"); then
77+
exit_on_error "Generate sha25sums failed for '$APK_VERSION_TAG' release."
7078
fi
7179
7280
- name: Attach universal APK file
@@ -112,7 +120,7 @@ jobs:
112120
- name: Attach sha256sums file
113121
uses: actions/upload-artifact@v2
114122
with:
115-
name: sha256sums
123+
name: ${{ env.APK_BASENAME_PREFIX }}_sha256sums
116124
path: |
117-
${{ env.APK_DIR_PATH }}/sha256sums
125+
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_sha256sums
118126
${{ env.APK_DIR_PATH }}/output-metadata.json

app/build.gradle

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ plugins {
22
id "com.android.application"
33
}
44

5+
ext {
6+
// The packageVariant defines the bootstrap variant that will be included in the app APK.
7+
// This must be supported by com.termux.shared.termux.TermuxBootstrap.PackageVariant or app will
8+
// crash at startup.
9+
// Bootstrap of a different variant must not be manually installed by the user after app installation
10+
// by replacing $PREFIX since app code is dependant on the variant used to build the APK.
11+
// Currently supported values are: [ "apt-android-7" ]
12+
packageVariant = System.getenv("TERMUX_PACKAGE_VARIANT") ?: "apt-android-7" // Default: "apt-android-7"
13+
}
14+
515
android {
616
compileSdkVersion project.properties.compileSdkVersion.toInteger()
717
ndkVersion = System.getenv("JITPACK_NDK_VERSION") ?: project.properties.ndkVersion
@@ -37,6 +47,8 @@ android {
3747
if (appVersionName) versionName = appVersionName
3848
validateVersionName(versionName)
3949

50+
buildConfigField "String", "TERMUX_PACKAGE_VARIANT", "\"" + project.ext.packageVariant + "\"" // Used by TermuxApplication class
51+
4052
manifestPlaceholders.TERMUX_PACKAGE_NAME = "com.termux"
4153
manifestPlaceholders.TERMUX_APP_NAME = "Termux"
4254
manifestPlaceholders.TERMUX_API_APP_NAME = "Termux:API"
@@ -115,10 +127,10 @@ android {
115127
variant.outputs.all { output ->
116128
if (variant.buildType.name == "debug") {
117129
def abi = output.getFilter(com.android.build.OutputFile.ABI)
118-
outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : "debug") + "_" + (abi ? abi : "universal") + ".apk")
130+
outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageVariant + "-" + "debug") + "_" + (abi ? abi : "universal") + ".apk")
119131
} else if (variant.buildType.name == "release") {
120132
def abi = output.getFilter(com.android.build.OutputFile.ABI)
121-
outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : "release") + "_" + (abi ? abi : "universal") + ".apk")
133+
outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageVariant + "-" + "release") + "_" + (abi ? abi : "universal") + ".apk")
122134
}
123135
}
124136
}
@@ -161,7 +173,7 @@ def downloadBootstrap(String arch, String expectedChecksum, String version) {
161173
if (checksum == expectedChecksum) {
162174
return
163175
} else {
164-
logger.quiet("Deleting old local file with wrong hash: " + localUrl)
176+
logger.quiet("Deleting old local file with wrong hash: " + localUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
165177
file.delete()
166178
}
167179
}
@@ -196,11 +208,16 @@ clean {
196208

197209
task downloadBootstraps() {
198210
doLast {
199-
def version = "2022.04.22-r1"
200-
downloadBootstrap("aarch64", "ec8a6043644594fc24681cffaf9c7b32f5bc68df7491c5df9a060e40e1934c70", version)
201-
downloadBootstrap("arm", "f8ec9505081b81da0ee66413762c52e6cb4a6ebd7be1a2a5ddee8953e0795dc9", version)
202-
downloadBootstrap("i686", "0491f12ed84a5ef3c28bd742311fed9f176e32100a2c6bbdb017df8f48044484", version)
203-
downloadBootstrap("x86_64", "94073a0e136bf5a9c05c1997a55dc261248f4ccb8bffaa9a950a132529cd1529", version)
211+
def packageVariant = project.ext.packageVariant
212+
if (packageVariant == "apt-android-7") {
213+
def version = "2022.04.22-r1" + "+" + packageVariant
214+
downloadBootstrap("aarch64", "ec8a6043644594fc24681cffaf9c7b32f5bc68df7491c5df9a060e40e1934c70", version)
215+
downloadBootstrap("arm", "f8ec9505081b81da0ee66413762c52e6cb4a6ebd7be1a2a5ddee8953e0795dc9", version)
216+
downloadBootstrap("i686", "0491f12ed84a5ef3c28bd742311fed9f176e32100a2c6bbdb017df8f48044484", version)
217+
downloadBootstrap("x86_64", "94073a0e136bf5a9c05c1997a55dc261248f4ccb8bffaa9a950a132529cd1529", version)
218+
} else {
219+
throw new GradleException("Unsupported TERMUX_PACKAGE_VARIANT \"" + packageVariant + "\"")
220+
}
204221
}
205222
}
206223

app/src/main/java/com/termux/app/TermuxApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import android.app.Application;
44
import android.content.Context;
55

6+
import com.termux.BuildConfig;
67
import com.termux.shared.errors.Error;
78
import com.termux.shared.logger.Logger;
9+
import com.termux.shared.termux.TermuxBootstrap;
810
import com.termux.shared.termux.TermuxConstants;
911
import com.termux.shared.termux.crash.TermuxCrashUtils;
1012
import com.termux.shared.termux.file.TermuxFileUtils;
@@ -30,6 +32,9 @@ public void onCreate() {
3032

3133
Logger.logDebug("Starting Application");
3234

35+
// Set TermuxBootstrap.TERMUX_APP_PACKAGE_MANAGER and TermuxBootstrap.TERMUX_APP_PACKAGE_VARIANT
36+
TermuxBootstrap.setTermuxPackageManagerAndVariant(BuildConfig.TERMUX_PACKAGE_VARIANT);
37+
3338
// Init app wide SharedProperties loaded from termux.properties
3439
TermuxAppSharedProperties properties = TermuxAppSharedProperties.init(context);
3540

app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.termux.shared.interact.MessageDialogUtils;
2424
import com.termux.shared.interact.ShareUtils;
2525
import com.termux.shared.shell.ShellUtils;
26+
import com.termux.shared.termux.TermuxBootstrap;
2627
import com.termux.shared.termux.terminal.TermuxTerminalViewClientBase;
2728
import com.termux.shared.termux.extrakeys.SpecialButton;
2829
import com.termux.shared.android.AndroidUtils;
@@ -756,9 +757,11 @@ public void run() {
756757

757758
reportString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(mActivity));
758759

759-
String termuxAptInfo = TermuxUtils.geAPTInfoMarkdownString(mActivity);
760-
if (termuxAptInfo != null)
761-
reportString.append("\n\n").append(termuxAptInfo);
760+
if (TermuxBootstrap.isAppPackageManagerAPT()) {
761+
String termuxAptInfo = TermuxUtils.geAPTInfoMarkdownString(mActivity);
762+
if (termuxAptInfo != null)
763+
reportString.append("\n\n").append(termuxAptInfo);
764+
}
762765

763766
if (addTermuxDebugInfo) {
764767
String termuxDebugInfo = TermuxUtils.getTermuxDebugMarkdownString(mActivity);

0 commit comments

Comments
 (0)