-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathandroid_module_common.gradle
More file actions
141 lines (117 loc) · 3.95 KB
/
Copy pathandroid_module_common.gradle
File metadata and controls
141 lines (117 loc) · 3.95 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
/*
* File: 'android_module_common.gradle'
* Location: https://raw.githubusercontent.com/yongce/AndroidLib/master/android_module_common.gradle
* Version: 2021.10.1
* All android projects can copy and include this file.
*/
// Define some common closures (methods) for code share
if (!rootProject.ext.has('gitCommandOutputCache')) {
rootProject.ext.gitCommandOutputCache = [:]
}
ext.getGitCommandOutput = { File workingDir, List<String> commandLine ->
String cacheKey = workingDir.absolutePath + "|" + commandLine.join(" ")
if (!rootProject.ext.gitCommandOutputCache.containsKey(cacheKey)) {
String output = providers.exec {
it.workingDir = workingDir
it.commandLine = commandLine
}.standardOutput.asText.get().trim()
rootProject.ext.gitCommandOutputCache[cacheKey] = output
}
return rootProject.ext.gitCommandOutputCache[cacheKey]
}
ext.getModuleProjectCommitCount = {
try {
return getGitCommandOutput(project.projectDir, ["git", "rev-list", "HEAD", "--count"]).toInteger()
} catch (Exception e) {
println String.format("Failed to execute #getModuleProjectCommitCount() with error [%s].",
e.toString())
return 0
}
}
ext.getModuleProjectLastCommitSha1 = {
return getGitCommandOutput(project.projectDir, ["git", "log", "--format=%H", "-1"])
}
ext.getRootProjectLastCommitSha1 = {
return getGitCommandOutput(rootProject.projectDir, ["git", "log", "--format=%H", "-1"])
}
ext.getBuildIdSuffix = {
if (project.hasProperty('build_id')) {
return "." + project.property('build_id')
}
return ""
}
ext.isIgnoreLintWarnings = {
if (project.hasProperty('lint_ignore_warnings')) {
return true
}
return false
}
ext.isApkSplitsEnabled = {
return project.hasProperty('enable_apk_splits')
}
ext {
calculatedVersionCode = getModuleProjectCommitCount()
buildIdSuffix = getBuildIdSuffix()
}
android {
compileSdk = rootProject.ext.versions.compileSdk
defaultConfig {
manifestPlaceholders = [
MODULE_GIT_COMMIT_SHA1: getModuleProjectLastCommitSha1(),
ROOT_GIT_COMMIT_SHA1: getRootProjectLastCommitSha1()
]
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
if (project.plugins.hasPlugin("com.android.application")) {
signingConfigs {
androidTestKey {
storeFile file("${rootDir}/aosp.keystore")
storePassword "android"
keyAlias "android.testkey"
keyPassword "android"
}
androidPlatformKey {
storeFile file("${rootDir}/aosp.keystore")
storePassword "android"
keyAlias "android.platformkey"
keyPassword "android"
}
}
buildTypes {
debug {
signingConfig = signingConfigs.androidTestKey
}
release {
signingConfig = signingConfigs.androidTestKey
minifyEnabled = true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
if (file('proguard-rules.pro').exists()) {
proguardFiles 'proguard-rules.pro'
}
}
}
}
lint {
textReport = true
abortOnError = true
ignoreWarnings = isIgnoreLintWarnings()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
testOptions {
unitTests.all {
jvmArgs '-Xshare:off'
// All the usual Gradle options.
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
unitTests {
includeAndroidResources = true
}
}
}