-
Notifications
You must be signed in to change notification settings - Fork 163
/
build.gradle
156 lines (140 loc) · 5.73 KB
/
build.gradle
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
import org.apache.tools.ant.taskdefs.condition.Os
import com.google.common.base.Joiner
import java.text.SimpleDateFormat
apply plugin: 'com.android.application'
def ndkDir = project.plugins.findPlugin('android').sdkHandler.ndkFolder
def timestamp() {
def dateFormat = new SimpleDateFormat("yyyy-MM-dd-HHmm")
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"))
return dateFormat.format(new Date())
}
def idForSimon() {
try {
def commit = new ByteArrayOutputStream()
exec {
// Require remote called simon because someone downstream might call my branch "upstream"
commandLine 'git', 'merge-base', 'simon/master', 'master'
standardOutput = commit
}
def shortUnique = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', commit.toString().trim()
standardOutput = shortUnique
}
return shortUnique.toString().trim()
} catch (ignored) {
return "UNOFFICIAL"
}
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "name.boyle.chris.sgtpuzzles"
versionCode 103
versionName "${timestamp()}-${idForSimon()}"
if (file(ndkDir.absolutePath + '/platforms/android-15').exists()) { // the last without PIE
minSdkVersion 7
} else {
project.logger.log(LogLevel.WARN,
"Your NDK can only support Android 4.1 and up because it forces PIE on. " +
"Install one with platforms other than android-L for broader support.")
// Specifically, add-application.mk:149 ends up "Switching to android-L", so
// setup-abi.mk:55 ends up setting TARGET_PIE := true, so build-binary.mk:210
// will enable PIE regardless of APP_PIE.
minSdkVersion 16
}
targetSdkVersion 22
ndk {
moduleName "puzzles"
cFlags "-DANDROID -DSMALL_SCREEN -DSTYLUS_BASED -DNO_PRINTING -DCOMBINED"
// WARNING abiFilters "all" here can end up omitting lib dir; I don't know why
}
fileTree(dir: 'src/main/jni', include: '*.c').each {File f ->
def game = f.name.replace(".c", "")
def text = f.text
def match = text =~ /enum\s+\{\s*COL_[^,]+,\s*(COL_[^\}]+)\}/
if (match) {
def colours = match.group(1).replaceAll(/(?s)\/\*.*?\*\//, "").replaceAll(/#[^\n]*\n/, "")
.trim().split(",")*.trim()*.replaceFirst(/^COL_/, "")*.toLowerCase()
.findAll { it =~ /^[^=]+$/ } - ["ncolours", "crossedline"]
if (colours.any { it =~ /[^a-z0-9_]/ }) {
throw new GradleException("Couldn't parse colours for " + game + ": " + match.group(1) + " -> " + colours)
}
resValue "string", game + "_colours", colours.join(',')
}
}
}
buildTypes {
debug {
jniDebuggable true
}
release {
minifyEnabled true // about to be renamed to minifyEnabled
jniDebuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.applicationVariants.all{ variant ->
variant.ndkCompile << {
// library is built, now build the executables: copy libpuzzles aside...
def prebuiltDir = file(variant.ndkCompile.soFolder.parent + '/prebuilt')
copy {
from(variant.ndkCompile.soFolder) {
include '**/libpuzzles.so'
}
into prebuiltDir
}
// use the same APP_ABI that NdkCompile.groovy does
String abiParam = 'APP_ABI='
Set<String> abiFilters = variant.ndkCompile.abiFilters
if (abiFilters != null && !abiFilters.isEmpty()) {
if (abiFilters.size() == 1) {
abiParam += abiFilters.iterator().next()
} else {
abiParam += Joiner.on((char)',').skipNulls().join(abiFilters.iterator())
}
} else {
abiParam += 'all'
}
// build the executables, with and without PIE
//noinspection GroovyAssignabilityCheck
def common = [
ndkDir.absolutePath + (Os.isFamily(Os.FAMILY_WINDOWS) ? '/ndk-build.cmd' : '/ndk-build'),
'NDK_PROJECT_PATH=null',
'APP_BUILD_SCRIPT=' + file('src/main/executable.mk').absolutePath,
'NDK_OUT=' + variant.ndkCompile.objFolder.absolutePath,
'NDK_LIBS_OUT=' + variant.ndkCompile.soFolder.absolutePath,
'PUZZLES_PREBUILT_DIR=' + prebuiltDir.absolutePath,
abiParam,
'NDK_LOG=1',
'NDK_DEBUG=' + (variant.ndkCompile.debuggable ? '1' : '0')]
exec {
commandLine common + [
'APP_PLATFORM=android-7', // 5 is earliest for x86 + mips
'PUZZLESGEN_SUFFIX=-no-pie',
'APP_PIE=false']
}
exec {
commandLine common + [
'APP_PLATFORM=android-16', // earliest for PIE
'PUZZLESGEN_SUFFIX=-with-pie',
'APP_PIE=true']
}
// rename to look like libraries, to get them installed
copy {
from(variant.ndkCompile.soFolder) {
include '**/puzzlesgen-*'
rename 'puzzlesgen-(.*)', 'libpuzzlesgen-$1.so'
}
into variant.ndkCompile.soFolder
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:gridlayout-v7:22.2.0'
compile 'com.android.support:support-annotations:22.2.0'
}