termux-app

Форк
0
/
build.gradle 
238 строк · 9.9 Кб
1
plugins {
2
    id "com.android.application"
3
}
4

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" "apt-android-5" ]
12
    packageVariant = System.getenv("TERMUX_PACKAGE_VARIANT") ?: "apt-android-7" // Default: "apt-android-7"
13
}
14

15
android {
16
    compileSdkVersion project.properties.compileSdkVersion.toInteger()
17
    ndkVersion = System.getenv("JITPACK_NDK_VERSION") ?: project.properties.ndkVersion
18
    def appVersionName = System.getenv("TERMUX_APP_VERSION_NAME") ?: ""
19
    def apkVersionTag = System.getenv("TERMUX_APK_VERSION_TAG") ?: ""
20
    def splitAPKsForDebugBuilds = System.getenv("TERMUX_SPLIT_APKS_FOR_DEBUG_BUILDS") ?: "1"
21
    def splitAPKsForReleaseBuilds = System.getenv("TERMUX_SPLIT_APKS_FOR_RELEASE_BUILDS") ?: "0" // F-Droid does not support split APKs #1904
22

23
    dependencies {
24
        implementation "androidx.annotation:annotation:1.3.0"
25
        implementation "androidx.core:core:1.6.0"
26
        implementation "androidx.drawerlayout:drawerlayout:1.1.1"
27
        implementation "androidx.preference:preference:1.1.1"
28
        implementation "androidx.viewpager:viewpager:1.0.0"
29
        implementation "com.google.android.material:material:1.4.0"
30
        implementation "com.google.guava:guava:24.1-jre"
31
        implementation "io.noties.markwon:core:$markwonVersion"
32
        implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
33
        implementation "io.noties.markwon:linkify:$markwonVersion"
34
        implementation "io.noties.markwon:recycler:$markwonVersion"
35

36
        implementation project(":terminal-view")
37
        implementation project(":termux-shared")
38
    }
39

40
    defaultConfig {
41
        applicationId "com.termux"
42
        minSdkVersion project.properties.minSdkVersion.toInteger()
43
        targetSdkVersion project.properties.targetSdkVersion.toInteger()
44
        versionCode 118
45
        versionName "0.118.0"
46

47
        if (appVersionName) versionName = appVersionName
48
        validateVersionName(versionName)
49

50
        buildConfigField "String", "TERMUX_PACKAGE_VARIANT", "\"" + project.ext.packageVariant + "\"" // Used by TermuxApplication class
51

52
        manifestPlaceholders.TERMUX_PACKAGE_NAME = "com.termux"
53
        manifestPlaceholders.TERMUX_APP_NAME = "Termux"
54
        manifestPlaceholders.TERMUX_API_APP_NAME = "Termux:API"
55
        manifestPlaceholders.TERMUX_BOOT_APP_NAME = "Termux:Boot"
56
        manifestPlaceholders.TERMUX_FLOAT_APP_NAME = "Termux:Float"
57
        manifestPlaceholders.TERMUX_STYLING_APP_NAME = "Termux:Styling"
58
        manifestPlaceholders.TERMUX_TASKER_APP_NAME = "Termux:Tasker"
59
        manifestPlaceholders.TERMUX_WIDGET_APP_NAME = "Termux:Widget"
60

61
        externalNativeBuild {
62
            ndkBuild {
63
                cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
64
            }
65
        }
66

67
        splits {
68
            abi {
69
                enable ((gradle.startParameter.taskNames.any { it.contains("Debug") } && splitAPKsForDebugBuilds == "1") ||
70
                    (gradle.startParameter.taskNames.any { it.contains("Release") } && splitAPKsForReleaseBuilds == "1"))
71
                reset ()
72
                include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
73
                universalApk true
74
            }
75
        }
76
    }
77

78
    signingConfigs {
79
        debug {
80
            storeFile file('testkey_untrusted.jks')
81
            keyAlias 'alias'
82
            storePassword 'xrj45yWGLbsO7W0v'
83
            keyPassword 'xrj45yWGLbsO7W0v'
84
        }
85
    }
86

87
    buildTypes {
88
        release {
89
            minifyEnabled true
90
            shrinkResources false // Reproducible builds
91
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
92
        }
93

94
        debug {
95
            signingConfig signingConfigs.debug
96
        }
97
    }
98

99
    compileOptions {
100
        // Flag to enable support for the new language APIs
101
        coreLibraryDesugaringEnabled true
102

103
        sourceCompatibility JavaVersion.VERSION_1_8
104
        targetCompatibility JavaVersion.VERSION_1_8
105
    }
106

107
    externalNativeBuild {
108
        ndkBuild {
109
            path "src/main/cpp/Android.mk"
110
        }
111
    }
112

113
    lintOptions {
114
        disable 'ProtectedPermissions'
115
    }
116

117
    testOptions {
118
        unitTests {
119
            includeAndroidResources = true
120
        }
121
    }
122

123
    packagingOptions {
124
        jniLibs {
125
            useLegacyPackaging true
126
        }
127
    }
128

129
    applicationVariants.all { variant ->
130
        variant.outputs.all { output ->
131
            if (variant.buildType.name == "debug") {
132
                def abi = output.getFilter(com.android.build.OutputFile.ABI)
133
                outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageVariant + "-" + "debug") + "_" + (abi ? abi : "universal") + ".apk")
134
            } else if (variant.buildType.name == "release") {
135
                def abi = output.getFilter(com.android.build.OutputFile.ABI)
136
                outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageVariant + "-" + "release") + "_" + (abi ? abi : "universal") + ".apk")
137
            }
138
        }
139
    }
140

141
}
142

143
dependencies {
144
    testImplementation "junit:junit:4.13.2"
145
    testImplementation "org.robolectric:robolectric:4.10"
146
    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
147
}
148

149
task versionName {
150
    doLast {
151
        print android.defaultConfig.versionName
152
    }
153
}
154

155
def 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-]+)*))?$
158
    if (!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))
159
        throw 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

162
def downloadBootstrap(String arch, String expectedChecksum, String version) {
163
    def digest = java.security.MessageDigest.getInstance("SHA-256")
164

165
    def localUrl = "src/main/cpp/bootstrap-" + arch + ".zip"
166
    def file = new File(projectDir, localUrl)
167
    if (file.exists()) {
168
        def buffer = new byte[8192]
169
        def input = new FileInputStream(file)
170
        while (true) {
171
            def readBytes = input.read(buffer)
172
            if (readBytes < 0) break
173
            digest.update(buffer, 0, readBytes)
174
        }
175
        def checksum = new BigInteger(1, digest.digest()).toString(16)
176
        while (checksum.length() < 64) { checksum = "0" + checksum }
177
        if (checksum == expectedChecksum) {
178
            return
179
        } else {
180
            logger.quiet("Deleting old local file with wrong hash: " + localUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
181
            file.delete()
182
        }
183
    }
184

185
    def remoteUrl = "https://github.com/termux/termux-packages/releases/download/bootstrap-" + version + "/bootstrap-" + arch + ".zip"
186
    logger.quiet("Downloading " + remoteUrl + " ...")
187

188
    file.parentFile.mkdirs()
189
    def out = new BufferedOutputStream(new FileOutputStream(file))
190

191
    def connection = new URL(remoteUrl).openConnection()
192
    connection.setInstanceFollowRedirects(true)
193
    def digestStream = new java.security.DigestInputStream(connection.inputStream, digest)
194
    out << digestStream
195
    out.close()
196

197
    def checksum = new BigInteger(1, digest.digest()).toString(16)
198
    while (checksum.length() < 64) { checksum = "0" + checksum }
199
    if (checksum != expectedChecksum) {
200
        file.delete()
201
        throw new GradleException("Wrong checksum for " + remoteUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
202
    }
203
}
204

205
clean {
206
    doLast {
207
        def tree = fileTree(new File(projectDir, 'src/main/cpp'))
208
        tree.include 'bootstrap-*.zip'
209
        tree.each { it.delete() }
210
    }
211
}
212

213
task downloadBootstraps() {
214
    doLast {
215
        def packageVariant = project.ext.packageVariant
216
        if (packageVariant == "apt-android-7") {
217
            def version = "2022.04.28-r5" + "+" + packageVariant
218
            downloadBootstrap("aarch64", "4a51a7eb209fe82efc24d52e3cccc13165f27377290687cb82038cbd8e948430", version)
219
            downloadBootstrap("arm", "6459a786acbae50d4c8a36fa1c3de6a4dd2d482572f6d54f73274709bd627325", version)
220
            downloadBootstrap("i686", "919d212b2f19e08600938db4079e794e947365022dbfd50ac342c50fcedcd7be", version)
221
            downloadBootstrap("x86_64", "61b02fdc03ea4f5d9da8d8cf018013fdc6659e6da6cbf44e9b24d1c623580b89", version)
222
        } else if (packageVariant == "apt-android-5") {
223
            def version = "2022.04.28-r6" + "+" + packageVariant
224
            downloadBootstrap("aarch64", "913609d439415c828c5640be1b0561467e539cb1c7080662decaaca2fb4820e7", version)
225
            downloadBootstrap("arm", "26bfb45304c946170db69108e5eb6e3641aad751406ce106c80df80cad2eccf8", version)
226
            downloadBootstrap("i686", "46dcfeb5eef67ba765498db9fe4c50dc4690805139aa0dd141a9d8ee0693cd27", version)
227
            downloadBootstrap("x86_64", "615b590679ee6cd885b7fd2ff9473c845e920f9b422f790bb158c63fe42b8481", version)
228
        } else {
229
            throw new GradleException("Unsupported TERMUX_PACKAGE_VARIANT \"" + packageVariant + "\"")
230
        }
231
    }
232
}
233

234
afterEvaluate {
235
    android.applicationVariants.all { variant ->
236
        variant.javaCompileProvider.get().dependsOn(downloadBootstraps)
237
    }
238
}
239

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.