forked from googleads/googleads-mobile-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
72 lines (62 loc) · 2.6 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
/*
* Gradle file to build the Unity plugin for the Google Mobile Ads SDK.
* Useage: ./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'
}
pluginSource = file('source/plugin').absolutePath
pluginBuildDir = file('temp/plugin-build-dir').absolutePath
buildPath = file('temp').absolutePath
exportPath = file('GoogleMobileAds.unitypackage').absolutePath
}
// Delete existing android plugin jar file.
task clearJar(type: Delete) {
delete 'source/android-library/app/build/intermediates/bundles/release/unity-plugin-library.jar'
}
// Build jar from android plugin source files using existing Gradle build file.
task buildAndroidPluginJar(type: GradleBuild) {
buildFile = 'source/android-library/app/build.gradle'
tasks = ['build']
}
// Move android plugin jar to temporary build directory.
task copyAndroidLibraryJar(type: Copy) {
from("source/android-library/app/build/intermediates/bundles/release/")
into("${pluginBuildDir}/Assets/Plugins/Android/GoogleMobileAdsPlugin/libs")
include('classes.jar')
rename('classes.jar', 'unity-plugin-library.jar')
}
copyAndroidLibraryJar.dependsOn(clearJar, buildAndroidPluginJar)
// 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 {
exec {
executable "${unity_exe}"
args "-g.building", "-batchmode", "-projectPath", "${pluginBuildDir}", "-logFile", "temp/unity.log", "-exportPackage", "Assets/GoogleMobileAds", "Assets/Plugins", "Assets/PlayServicesResolver", "${exportPath}", "-quit"
}
}
}
task createTempBuildFolder(type: Copy) {
from {"${pluginSource}"}
into {"${pluginBuildDir}"}
}
task clearTempBuildFolder(type:Delete) {
delete {"${buildPath}"}
}
exportPackage.dependsOn(createTempBuildFolder, copyAndroidLibraryJar)
exportPackage.finalizedBy(clearTempBuildFolder)