forked from creativepsyco/secondary-dex-gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
134 lines (113 loc) · 4.5 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
/*
* Copyright (c) 2014 Mohit Kanwal.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*/
apply plugin: 'android'
def log = project.logger
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
// Need to disable pre dexing to be able to build properly
// Otherwise we need to add more tasks to the libraries
// This is a small penalty to keep the house in order!
dexOptions {
incremental false
preDexLibraries = false
jumboMode = false
}
enforceUniquePackageName false
useOldManifestMerger true
buildTypes {
// prevents dexing of lib classes
release {
runProguard false
debuggable false
zipAlign true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.applicationVariants.all { variant ->
def name = variant.buildType.name
// if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
// return; // Skip debug builds.
// }
log.info("========================================")
log.info("Starting Variant Build For the Application")
log.info("Variant Name: ${variant.name}")
log.info("Build Type Name: ${variant.buildType}")
log.info("Variant: ${variant}")
log.info("${variant.dex.libraries}")
log.info("========================================")
Task dexRelease = project.tasks.getByName("dex${name.capitalize()}")
log.info("Dex Task:\n=========== ${dexRelease.libraries}")
def libraryFiles = new ArrayList<?>()
/**
* This needs to be the name of your second module
* {@code lib/unspecified/classes.jar }
*/
variant.dex.libraries.each {
File file ->
if (!file.absolutePath.contains("lib/unspecified/classes.jar")) {
log.info("File Name ${file} Needs to be dexed")
libraryFiles.add(file);
}
}
variant.dex.libraries = libraryFiles
log.info("Libraries after modification: ${variant.dex.libraries}")
Task packageApp = project.tasks.getByName("package${name.capitalize()}")
def finalPackagedJars = new ArrayList<?>()
def libJars = new ArrayList<?>()
variant.packageApplication.packagedJars.each {
File file ->
if (!file.absolutePath.contains("lib/unspecified/classes.jar")) {
log.info("File Name ${file} Needs to be dexed")
finalPackagedJars.add(file);
} else {
libJars.add(file)
}
}
variant.packageApplication.packagedJars = finalPackagedJars
def mergeAssetTask = project.tasks.getByName("merge${name.capitalize()}Assets")
def copyJars = project.tasks.create("copy${name.capitalize()}Jar", Copy)
log.error("Copy Files List ${project.files(libJars)}" )
copyJars.from project.files(libJars)
copyJars.into "${buildDir}/intermediates/assets/${name}"
copyJars.eachFile { details ->
log.error("Boom ${details.path}")
}
copyJars.dependsOn(mergeAssetTask)
log.error("Asset Directory: ${variant.processResources.assetsDir}")
project.tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(copyJars)
}
// variant.packageApplication.dependsOn(copyJars)
// variant.processResources.dependsOn(copyJars)
// packageApp.dependsOn(copyJars)
log.error("${name.capitalize()} Package ${variant.packageApplication.packagedJars}")
}
//android.applicationVariants.each {
// variant ->
// variant.dex.libraries = variant.dex.libraries - files('/home/gardev/android/libs/SecondaryDexSample/app/build/exploded-aar/SecondaryDexSample/lib/unspecified/classes.jar')
// log.info("Dex Task After Removing Libs: ${variant.dex.libraries}")
//}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile project(':lib')
}