termux-app
238 строк · 9.9 Кб
1plugins {
2id "com.android.application"
3}
4
5ext {
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" "apt-android-5" ]
12packageVariant = System.getenv("TERMUX_PACKAGE_VARIANT") ?: "apt-android-7" // Default: "apt-android-7"
13}
14
15android {
16compileSdkVersion project.properties.compileSdkVersion.toInteger()
17ndkVersion = System.getenv("JITPACK_NDK_VERSION") ?: project.properties.ndkVersion
18def appVersionName = System.getenv("TERMUX_APP_VERSION_NAME") ?: ""
19def apkVersionTag = System.getenv("TERMUX_APK_VERSION_TAG") ?: ""
20def splitAPKsForDebugBuilds = System.getenv("TERMUX_SPLIT_APKS_FOR_DEBUG_BUILDS") ?: "1"
21def splitAPKsForReleaseBuilds = System.getenv("TERMUX_SPLIT_APKS_FOR_RELEASE_BUILDS") ?: "0" // F-Droid does not support split APKs #1904
22
23dependencies {
24implementation "androidx.annotation:annotation:1.3.0"
25implementation "androidx.core:core:1.6.0"
26implementation "androidx.drawerlayout:drawerlayout:1.1.1"
27implementation "androidx.preference:preference:1.1.1"
28implementation "androidx.viewpager:viewpager:1.0.0"
29implementation "com.google.android.material:material:1.4.0"
30implementation "com.google.guava:guava:24.1-jre"
31implementation "io.noties.markwon:core:$markwonVersion"
32implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
33implementation "io.noties.markwon:linkify:$markwonVersion"
34implementation "io.noties.markwon:recycler:$markwonVersion"
35
36implementation project(":terminal-view")
37implementation project(":termux-shared")
38}
39
40defaultConfig {
41applicationId "com.termux"
42minSdkVersion project.properties.minSdkVersion.toInteger()
43targetSdkVersion project.properties.targetSdkVersion.toInteger()
44versionCode 118
45versionName "0.118.0"
46
47if (appVersionName) versionName = appVersionName
48validateVersionName(versionName)
49
50buildConfigField "String", "TERMUX_PACKAGE_VARIANT", "\"" + project.ext.packageVariant + "\"" // Used by TermuxApplication class
51
52manifestPlaceholders.TERMUX_PACKAGE_NAME = "com.termux"
53manifestPlaceholders.TERMUX_APP_NAME = "Termux"
54manifestPlaceholders.TERMUX_API_APP_NAME = "Termux:API"
55manifestPlaceholders.TERMUX_BOOT_APP_NAME = "Termux:Boot"
56manifestPlaceholders.TERMUX_FLOAT_APP_NAME = "Termux:Float"
57manifestPlaceholders.TERMUX_STYLING_APP_NAME = "Termux:Styling"
58manifestPlaceholders.TERMUX_TASKER_APP_NAME = "Termux:Tasker"
59manifestPlaceholders.TERMUX_WIDGET_APP_NAME = "Termux:Widget"
60
61externalNativeBuild {
62ndkBuild {
63cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
64}
65}
66
67splits {
68abi {
69enable ((gradle.startParameter.taskNames.any { it.contains("Debug") } && splitAPKsForDebugBuilds == "1") ||
70(gradle.startParameter.taskNames.any { it.contains("Release") } && splitAPKsForReleaseBuilds == "1"))
71reset ()
72include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
73universalApk true
74}
75}
76}
77
78signingConfigs {
79debug {
80storeFile file('testkey_untrusted.jks')
81keyAlias 'alias'
82storePassword 'xrj45yWGLbsO7W0v'
83keyPassword 'xrj45yWGLbsO7W0v'
84}
85}
86
87buildTypes {
88release {
89minifyEnabled true
90shrinkResources false // Reproducible builds
91proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
92}
93
94debug {
95signingConfig signingConfigs.debug
96}
97}
98
99compileOptions {
100// Flag to enable support for the new language APIs
101coreLibraryDesugaringEnabled true
102
103sourceCompatibility JavaVersion.VERSION_1_8
104targetCompatibility JavaVersion.VERSION_1_8
105}
106
107externalNativeBuild {
108ndkBuild {
109path "src/main/cpp/Android.mk"
110}
111}
112
113lintOptions {
114disable 'ProtectedPermissions'
115}
116
117testOptions {
118unitTests {
119includeAndroidResources = true
120}
121}
122
123packagingOptions {
124jniLibs {
125useLegacyPackaging true
126}
127}
128
129applicationVariants.all { variant ->
130variant.outputs.all { output ->
131if (variant.buildType.name == "debug") {
132def abi = output.getFilter(com.android.build.OutputFile.ABI)
133outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageVariant + "-" + "debug") + "_" + (abi ? abi : "universal") + ".apk")
134} else if (variant.buildType.name == "release") {
135def abi = output.getFilter(com.android.build.OutputFile.ABI)
136outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageVariant + "-" + "release") + "_" + (abi ? abi : "universal") + ".apk")
137}
138}
139}
140
141}
142
143dependencies {
144testImplementation "junit:junit:4.13.2"
145testImplementation "org.robolectric:robolectric:4.10"
146coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
147}
148
149task versionName {
150doLast {
151print android.defaultConfig.versionName
152}
153}
154
155def validateVersionName(String versionName) {
156// https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
157// ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
158if (!java.util.regex.Pattern.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\$", versionName))
159throw new GradleException("The versionName '" + versionName + "' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html.")
160}
161
162def downloadBootstrap(String arch, String expectedChecksum, String version) {
163def digest = java.security.MessageDigest.getInstance("SHA-256")
164
165def localUrl = "src/main/cpp/bootstrap-" + arch + ".zip"
166def file = new File(projectDir, localUrl)
167if (file.exists()) {
168def buffer = new byte[8192]
169def input = new FileInputStream(file)
170while (true) {
171def readBytes = input.read(buffer)
172if (readBytes < 0) break
173digest.update(buffer, 0, readBytes)
174}
175def checksum = new BigInteger(1, digest.digest()).toString(16)
176while (checksum.length() < 64) { checksum = "0" + checksum }
177if (checksum == expectedChecksum) {
178return
179} else {
180logger.quiet("Deleting old local file with wrong hash: " + localUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
181file.delete()
182}
183}
184
185def remoteUrl = "https://github.com/termux/termux-packages/releases/download/bootstrap-" + version + "/bootstrap-" + arch + ".zip"
186logger.quiet("Downloading " + remoteUrl + " ...")
187
188file.parentFile.mkdirs()
189def out = new BufferedOutputStream(new FileOutputStream(file))
190
191def connection = new URL(remoteUrl).openConnection()
192connection.setInstanceFollowRedirects(true)
193def digestStream = new java.security.DigestInputStream(connection.inputStream, digest)
194out << digestStream
195out.close()
196
197def checksum = new BigInteger(1, digest.digest()).toString(16)
198while (checksum.length() < 64) { checksum = "0" + checksum }
199if (checksum != expectedChecksum) {
200file.delete()
201throw new GradleException("Wrong checksum for " + remoteUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
202}
203}
204
205clean {
206doLast {
207def tree = fileTree(new File(projectDir, 'src/main/cpp'))
208tree.include 'bootstrap-*.zip'
209tree.each { it.delete() }
210}
211}
212
213task downloadBootstraps() {
214doLast {
215def packageVariant = project.ext.packageVariant
216if (packageVariant == "apt-android-7") {
217def version = "2022.04.28-r5" + "+" + packageVariant
218downloadBootstrap("aarch64", "4a51a7eb209fe82efc24d52e3cccc13165f27377290687cb82038cbd8e948430", version)
219downloadBootstrap("arm", "6459a786acbae50d4c8a36fa1c3de6a4dd2d482572f6d54f73274709bd627325", version)
220downloadBootstrap("i686", "919d212b2f19e08600938db4079e794e947365022dbfd50ac342c50fcedcd7be", version)
221downloadBootstrap("x86_64", "61b02fdc03ea4f5d9da8d8cf018013fdc6659e6da6cbf44e9b24d1c623580b89", version)
222} else if (packageVariant == "apt-android-5") {
223def version = "2022.04.28-r6" + "+" + packageVariant
224downloadBootstrap("aarch64", "913609d439415c828c5640be1b0561467e539cb1c7080662decaaca2fb4820e7", version)
225downloadBootstrap("arm", "26bfb45304c946170db69108e5eb6e3641aad751406ce106c80df80cad2eccf8", version)
226downloadBootstrap("i686", "46dcfeb5eef67ba765498db9fe4c50dc4690805139aa0dd141a9d8ee0693cd27", version)
227downloadBootstrap("x86_64", "615b590679ee6cd885b7fd2ff9473c845e920f9b422f790bb158c63fe42b8481", version)
228} else {
229throw new GradleException("Unsupported TERMUX_PACKAGE_VARIANT \"" + packageVariant + "\"")
230}
231}
232}
233
234afterEvaluate {
235android.applicationVariants.all { variant ->
236variant.javaCompileProvider.get().dependsOn(downloadBootstraps)
237}
238}
239