-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbuild.gradle
More file actions
204 lines (185 loc) · 6.07 KB
/
Copy pathbuild.gradle
File metadata and controls
204 lines (185 loc) · 6.07 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
plugins {
id 'com.android.application'
}
final COMPILE_WITH_DEPRECATION_LINT = false
// Load signing config only if needed
def signingEnabled = gradle.startParameter.taskNames.any { it.toLowerCase().contains("signedrelease") }
def props = loadSigningConfig(signingEnabled)
android {
namespace 'fr.ralala.hexviewer'
compileSdk = 36
defaultConfig {
applicationId "fr.ralala.hexviewer"
minSdk 23
//noinspection OldTargetApi
targetSdk 35
// F-Droid seems not to appreciate the use of variables
versionCode 15909
versionName '1.59.9'
vectorDrawables {
useSupportLibrary true
}
}
buildFeatures {
buildConfig = true
viewBinding = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
coreLibraryDesugaringEnabled true
}
signingConfigs {
github {
if (signingEnabled) {
storeFile rootProject.file(props['storeFile'].trim())
storePassword props['storePassword'].trim()
keyAlias props['keyAlias'].trim()
keyPassword props['keyPassword'].trim()
v1SigningEnabled true
v2SigningEnabled true
enableV4Signing true
}
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
// to debug ProGuard rules
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
signedRelease {
initWith release
matchingFallbacks = ['release']
if (signingEnabled) {
signingConfig signingConfigs.github
}
}
}
lint {
abortOnError false
}
}
dependencies {
implementation 'org.apache.commons:commons-collections4:4.5.0'
implementation "androidx.appcompat:appcompat:1.7.1"
implementation "androidx.preference:preference:1.2.1"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0"
implementation "androidx.emoji2:emoji2:1.6.0"
implementation "androidx.documentfile:documentfile:1.1.0"
implementation "androidx.emoji2:emoji2-bundled:1.6.0"
implementation "com.google.android.material:material:1.14.0"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
testImplementation "junit:junit:4.13.2"
}
if(COMPILE_WITH_DEPRECATION_LINT) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]
}
}
/* Tasks */
tasks.withType(Test).configureEach { testTask ->
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
showStandardStreams = true
}
def totalDuration = 0L
def list = new ArrayList<String>()
doLast {
logger.lifecycle("Tests finished.")
}
addTestListener(new TestListener() {
@Override
void beforeSuite(TestDescriptor desc) {}
@Override
void beforeTest(TestDescriptor descriptor) {}
@Override
void afterTest(TestDescriptor descriptor, TestResult result) {
long duration = result.endTime - result.startTime
list << "Test ${descriptor.name} took ${duration} ms"
totalDuration += duration
}
@Override
void afterSuite(TestDescriptor desc, TestResult result) {
if (!desc.parent) { // root suite
logger.lifecycle("")
list.each { li ->
logger.lifecycle(li)
}
logger.lifecycle("Test summary: ${result.testCount} tests, ${result.successfulTestCount} succeeded, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped")
logger.lifecycle("Total time: ${totalDuration} ms")
}
}
})
}
// versionCode <-> versionName /////////////////////////////////////////////////////////////////////
// I got the idea (code) below from the repository https://github.com/sal0max/currencie
/**
* Checks if versionCode and versionName match.
* Needed because of F-Droid: both have to be hard-coded and can't be assigned dynamically.
* So at least check during build for them to match.
*/
tasks.register('checkVersion') {
int versionCode = android.defaultConfig.versionCode
int correctVersionCode = generateVersionCode(android.defaultConfig.versionName)
if (versionCode != correctVersionCode)
throw new GradleException(
"versionCode and versionName don't match: " +
"versionCode should be $correctVersionCode. Is $versionCode."
)
}
assemble.dependsOn checkVersion
/**
* Checks if a fastlane changelog for the current version is present.
*/
tasks.register('checkFastlaneChangelog') {
int versionCode = android.defaultConfig.versionCode
File changelogFile = file("$rootDir/fastlane/metadata/android/en-US/changelogs/${versionCode}.txt")
if (!changelogFile.exists())
throw new GradleException(
"Fastlane changelog missing: expecting file '$changelogFile'"
)
}
build.dependsOn checkFastlaneChangelog
/* functions */
private Properties loadSigningConfig(boolean signingEnabled) {
if (signingEnabled) {
def props = new Properties()
def propsFile = rootProject.file("keystore.properties")
if (!propsFile.exists()) {
throw new GradleException("Missing 'keystore.properties' file.")
}
propsFile.withInputStream { props.load(it) }
def requiredKeys = ['storeFile', 'storePassword', 'keyAlias', 'keyPassword']
requiredKeys.each {
if (!props.containsKey(it) || props[it].trim().isEmpty()) {
throw new GradleException("Missing or empty property: '${it}' in 'keystore.properties'.")
}
}
def keystorePath = rootProject.file(props['storeFile'].trim())
if (!keystorePath.exists()) {
throw new GradleException("Keystore file not found at: ${keystorePath}")
}
return props
}
return null
}
/**
* Generates a versionCode based on the given semVer String.
* @param semVer e.g. 1.27
* @return e.g. 127 (-> 1 27)
*
* 1.58 -> 158
* 1.58.0 -> 15800
* 1.0.0 -> 10000
*/
private static int generateVersionCode(String semVer) {
def parts = semVer.tokenize('.').collect { it.toInteger() }
parts.inject(0) { code, part -> code * 100 + part }
}