This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
forked from novoda/gradle-android-command-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
175 lines (149 loc) · 4.49 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// To depend on the deployed version of the plugin add the following line here:
// classpath 'com.novoda:gradle-android-command-plugin:{latest-version}'
}
}
apply plugin: 'com.android.application'
// apply AFTER android plugin
apply plugin: 'com.novoda.android-command'
repositories {
mavenCentral()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
versionCode 1
versionName 'v0.0.1'
minSdkVersion 14
targetSdkVersion 25
}
buildTypes {
debug
release {
signingConfig debug.signingConfig
}
QA {
signingConfig debug.signingConfig
}
}
productFlavors {
flavorDimensions 'pricing', 'releaseType'
beta {
dimension 'releaseType'
}
normal {
dimension 'releaseType'
}
free {
dimension 'pricing'
}
paid {
dimension 'pricing'
}
}
// change APK name to include the version name
applicationVariants.all { variant ->
def file = variant.outputs[0].packageApplication.outputFile
variant.outputs[0].packageApplication.outputFile = new File(file.parent, file.name.replace('.apk', "-${defaultConfig.versionName}.apk"))
}
command {
deviceId {
def apiLevel = defaultConfig.minSdkVersion.getApiLevel()
def minSdkDevice = devices().find { it.sdkVersion() >= apiLevel }
if (!minSdkDevice) {
throw new IllegalStateException("No device found running android version >= ${apiLevel}")
}
minSdkDevice.id
}
monkey {
events 1000
categories 'android.intent.category.ONLY_ME', 'android.intent.category.MONKEY'
}
sortBySubtasks false
task('runAmazon', com.novoda.gradle.command.Run) {
deviceId {
def kindle = devices().find { it.brand() == 'Amazon' }
if (!kindle) {
throw new GroovyRuntimeException('No Amazon device found')
}
kindle.id
}
}
task('runNewest', com.novoda.gradle.command.Run, ['installDevice']) {
deviceId {
def device = devices().max { it.sdkVersion() }
device.id
}
}
task autoLogin(type: com.novoda.gradle.command.Input) {
script {
2.times {
text 'bob'
enter()
}
enter()
}
}
task listDevices doLast {
println()
println 'Attached devices:'
devices().each {
println it
}
}
task('installFromGooglePlay', com.novoda.gradle.command.Install) {
customFlags {
return ['-i', 'com.android.vending']
}
}
task dumpActivityStack(type: com.novoda.gradle.command.ActivityStack) {
}
}
}
/**
* Sample task that installs APKs of all variants on a device.
*
* Device can also be specified like below:
* ./gradlew installDeviceAllVariants -DdeviceId=SERIAL_NUMBER
*/
def installAllTask = task installDeviceAllVariants {
description = 'Install APKs for all variants on a specified device'
group = 'install'
}
android.applicationVariants.all {
installAllTask.dependsOn tasks.findByName("installDevice${it.name.capitalize()}")
}
/**
* Uses the Files task type to backup photos on the device to
* some local directory.
* Only pulls files that are not yet backed up.
*/
task syncPhotos(type: com.novoda.gradle.command.Files) {
deviceId {
def moto = android.command.devices().find { it.brand() == 'motorola' }
if (!moto) {
throw new GroovyRuntimeException('No Motorola device found')
}
moto.id
}
script {
def deviceImageDir = '/sdcard/DCIM/Camera/'
def backupDir = mkdir('motoPhoto')
list(deviceImageDir).findAll { image ->
image.name.endsWith('jpg') && !image.name.contains(':nopm:')
}
.findAll { image ->
!new File(backupDir.path, image.name).exists()
}
.each { image ->
println image
pull image.path + image.name, backupDir.path
}
}
}