forked from daniele-rapagnani/alephone-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
123 lines (102 loc) · 4.06 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
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import java.nio.file.Paths
import java.security.MessageDigest
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
task cleanDistribution(type: Delete) {
delete gradle.libDistributionRoot
}
ext.getFileHash = {
String path ->
File f = new File(path)
if (!f.exists() || f.isDirectory()) {
logger.info("File '${path}' does not exist or is a directory")
return ""
}
byte[] data = f.readBytes()
def hash = MessageDigest.getInstance("MD5").digest(data).encodeHex().toString()
logger.info("File '${path}' hash is: ${hash}")
return hash
}
ext.distHeaders = {
from, into = null ->
return [
from: "src/main/cpp/" + from,
into: into ? into : "@@projName@@/include",
include: "**/*.h"
]
}
ext.distLib = {
libName, type = "ndkBuild", projName = "@@projName@@", from = null ->
return [
from: from ? from : "build/intermediates/${type}/@@buildType@@/obj" + (type == "ndkBuild" ? "/local" : ""),
into: projName + "/lib/@@buildType@@",
include: "**/" + libName
]
}
ext.defineDistributeTask = {
prj, buildType, files, name = "distributeLibs" ->
project(prj.name) {
def taskName = "${name}${buildType.capitalize()}"
task(taskName) {
def projPath = prj.file(".").getPath()
doLast {
files.each {
entry ->
def intoPath = Paths.get(project(":").file(".").getPath(), gradle.libDistributionRoot).toAbsolutePath().toString()
def fromPath = Paths.get(projPath, entry["from"].replaceAll("@@buildType@@", buildType))
.toAbsolutePath()
.toString()
def subIntoPath = entry["into"]
.replaceAll("@@buildType@@", buildType)
.replaceAll("@@projName@@", prj.name)
def includeGlob = entry.containsKey("include") ? entry["include"] : "**/*"
copy {
into intoPath
include includeGlob
from(fromPath) {
into subIntoPath
}
eachFile {
FileCopyDetails file ->
def sourceHash = getFileHash(file.getFile().getAbsolutePath())
def destHash = getFileHash(Paths.get(intoPath, file.path).toAbsolutePath().toString())
if (sourceHash == destHash) {
logger.info("Skipping distribution copy of: " + file)
file.exclude()
return;
}
logger.info("Copying for distribution: " + file)
}
}
}
}
}
tasks.getByPath(":${prj.name}:externalNativeBuild${buildType.capitalize()}").finalizedBy(taskName)
}
}
ext.defineDistributeTasks = {
prj, files, name = "distributeLibs" -> (
prj.android.buildTypes.all {
buildType -> defineDistributeTask(prj, buildType.name, files, name)
}
)
}