-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
build.gradle
121 lines (106 loc) · 3.99 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
/*
* Gradle file to build the Unity plugin for the Google Mobile Ads SDK.
* Usage: ./gradlew exportPackage
*/
defaultTasks 'exportPackage'
// Project level variables.
project.ext {
sdk_root = System.getProperty("ANDROID_HOME")
if (sdk_root == null || sdk_root.isEmpty()) {
sdk_root = System.getenv("ANDROID_HOME")
}
unity_exe = System.getProperty("UNITY_EXE")
if (unity_exe == null || unity_exe.isEmpty()) {
unity_exe = System.getenv("UNITY_EXE")
}
if (unity_exe == null || unity_exe.isEmpty()) {
unity_exe ='/Applications/Unity/Unity.app/Contents/MacOS/Unity'
}
git_exe = System.getProperty("GIT_EXE")
if (git_exe == null || git_exe.isEmpty()) {
git_exe = System.getenv("GIT_EXE")
}
if (git_exe == null || git_exe.isEmpty()) {
git_exe = 'git'
}
resolverPackageUri = System.getProperty("RESOLVER_PACKAGE_URI")
jarResolverRepo = 'https://github.com/googlesamples/unity-jar-resolver.git'
pluginSource = file('source/plugin').absolutePath
pluginBuildDir = file('temp/plugin-build-dir').absolutePath
exportPath = file('GoogleMobileAds.unitypackage').absolutePath
tempPath = file('temp').absolutePath
resolverDir = file("${tempPath}/jarresolver").absolutePath
}
// Delete existing android plugin aar file.
task clearAar(type: Delete) {
delete 'source/android-library/app/build/libs/googlemobileads-unity.aar'
}
// Build jar from android plugin source files using existing Gradle build file.
task buildAndroidPluginAar(type: GradleBuild) {
buildFile = 'source/android-library/app/build.gradle'
tasks = ['makeAar']
}
// Move android plugin jar to temporary build directory.
task copyAndroidLibraryAar(type: Copy) {
from("source/android-library/app/build/libs")
into("${pluginBuildDir}/Assets/Plugins/Android")
include('googlemobileads-unity.aar')
}
copyAndroidLibraryAar.dependsOn(clearAar, buildAndroidPluginAar)
task downloadResolver() {
description = "Download the Play Services Resolver"
if (resolverPackageUri != null) {
mkdir("${resolverDir}")
def resolver = new File("${resolverDir}/resolver.unitypackage")
new URL("${resolverPackageUri}").withInputStream {
inputStream -> resolver.withOutputStream { it << inputStream }
}
} else {
println 'clone ' + jarResolverRepo
def result = exec {
executable "${git_exe}"
args "clone", jarResolverRepo, "${resolverDir}"
}
if (result.exitValue == 0) {
println "Downloaded resolver from " + jarResolverRepo
}
}
}
// Build unity package using through command line interface.
// Create new unity project with files in temporary build directory and export files within Assets/GoogleMobileAds
// to a unity package.
// Command line usage and arguments documented at http://docs.unity3d.com/Manual/CommandLineArguments.html.
task exportPackage() {
description = "Creates and exports the Plugin unity package"
doLast {
def tree = fileTree("${resolverDir}")
{
include '*-latest.unitypackage'
}
def jarresolver_package = tree.getSingleFile()
exec {
executable "${unity_exe}"
args "-g.building",
"-batchmode",
"-projectPath", "${pluginBuildDir}",
"-logFile", "temp/unity.log",
"-importPackage", "${jarresolver_package}",
"-exportPackage",
"Assets/GoogleMobileAds",
"Assets/Plugins",
"Assets/ExternalDependencyManager",
"${exportPath}",
"-quit"
}
}
}
task createTempBuildFolder(type: Copy) {
from {"${pluginSource}"}
into {"${pluginBuildDir}"}
}
task clearTempBuildFolder(type:Delete) {
delete {"${tempPath}"}
}
exportPackage.dependsOn(createTempBuildFolder, copyAndroidLibraryAar,
downloadResolver)
// exportPackage.finalizedBy(clearTempBuildFolder)