@@ -13,9 +13,10 @@ android {
1313 targetSdkVersion project. ext. compileSdk
1414 versionCode 1
1515 versionName project. ext. version
16+ testInstrumentationRunner ' android.support.test.runner.AndroidJUnitRunner'
1617 }
1718
18- defaultPublishConfig " noDepRelease "
19+ defaultPublishConfig " release "
1920 publishNonDefault true
2021
2122 buildTypes {
@@ -28,34 +29,32 @@ android {
2829 }
2930 }
3031
31- productFlavors {
32- withGcmDep
33- noDep
32+ sourceSets {
33+ // A set of testing helpers that are shared across test types
34+ testLib { java. srcDir(" src/main" ) }
35+ test { java. srcDir(" src/testLib" ) } // Robolectric tests
36+ androidTest { java. srcDir(" src/testLib" ) } // Android (e2e) tests
3437 }
3538}
3639
3740dependencies {
38- testCompile ' junit:junit:4.12'
39- testCompile ' org.robolectric:robolectric:3.1.2'
40- testCompile ' org.mockito:mockito-core:2.2.5'
41+ // The main library only depends on the Android support lib
4142 compile " com.android.support:support-v4:${ project.ext.supportLibraryVersion} "
42- // In a perfect world we'd have these dependencies totally handled by the
43- // Android plugin using a combination of "provided" (compile-time only) and
44- // "package" (runtime only) rules:
45- //
46- // noDepCompile project(":gcm_defs")
47- // withGcmDepProvided project(":gcm_defs")
48- //
49- // Unfortunately this doesn't work. We can't import the same project with
50- // different visibility settings because the Android plugin reuses the
51- // same identifier when it creates the necessary backing rules, so we get a
52- // dupe rule error.
53- //
54- // So, instead we mark the gcm_defs as provided (compile-time only) and
55- // manually copy the required classes into the noDep flavor (below).
56- provided project(' :gcm_defs' )
57- // the withGcmDep version has an explicit dependency on the GCM library.
58- withGcmDepCompile " com.google.android.gms:play-services-gcm:10.0.1"
43+
44+ def junit = ' junit:junit:4.12'
45+ def robolectric = ' org.robolectric:robolectric:3.3.2'
46+
47+ // The common test library uses JUnit
48+ testLibCompile junit
49+
50+ // The unit tests are written using JUnit, Robolectric, and Mockito
51+ testCompile junit
52+ testCompile robolectric
53+ testCompile ' org.mockito:mockito-core:2.2.5'
54+
55+ // The Android (e2e) tests are written using JUnit and the test support lib
56+ androidTestCompile junit
57+ androidTestCompile ' com.android.support.test:runner:0.5'
5958}
6059
6160task javadocs (type : Javadoc ) {
@@ -84,22 +83,8 @@ task aar(dependsOn: "assembleRelease") {
8483}
8584
8685// Artifact descriptions (surfaced in JCenter / Maven)
87- def noDepDesc = " The Firebase JobDispatcher is a library that provides a common" +
86+ def artifactDesc = " The Firebase JobDispatcher is a library that provides a common" +
8887 " interface to scheduling engines on Android."
89- def withGcmDepDesc = noDepDesc + " This version should be used by anyone with a" +
90- " dependency on the legacy GCM library (com.google.android.gms:play-services-gcm)."
91-
92- // Maps flavors to descriptions + artifacts
93- def flavorsToPublicationsMap = [
94- noDep : [
95- description : noDepDesc,
96- artifactId : " firebase-jobdispatcher" ,
97- ],
98- withGcmDep : [
99- description : withGcmDepDesc,
100- artifactId : " firebase-jobdispatcher-with-gcm-dep" ,
101- ],
102- ]
10388
10489publishing {
10590 repositories {
@@ -111,18 +96,28 @@ publishing {
11196 }
11297
11398 publications {
114- // Create a new MavenPublication for each of the flavors (noDep, withGcmDep)
115- android. productFlavors. each { flavor ->
116- " dispatcher${ flavor.name.capitalize()} Library" (MavenPublication ) {
117- artifactId flavorsToPublicationsMap[flavor. name]. artifactId
99+ // The initial FJD releases had two artifacts; one for users that
100+ // already had a dependency on the gcm client library and one for users
101+ // that didn't. There's no longer a need for these two variants, but we
102+ // continue to produce the -with-gcm-dep version (identical to the
103+ // standard artifact) to prevent breaking clients.
104+ //
105+ // TODO(ciarandowney): add a deprecation notice pointing users to the
106+ // regular version
107+ [
108+ standardArtifact : " firebase-jobdispatcher" ,
109+ legacyArtifact : " firebase-jobdispatcher-with-gcm-dep" ,
110+ ]. each { key , value ->
111+ " dispatcherLibrary${ key.capitalize()} " (MavenPublication ) {
112+ artifactId value
118113 groupId project. ext. group
119114 version project. ext. version
120115
121116 // Add the AAR artifact
122- artifact(" ${ buildDir} /outputs/aar/jobdispatcher-${ flavor.name } - release.aar" ) {
117+ artifact(" ${ buildDir} /outputs/aar/jobdispatcher-release.aar" ) {
123118 // wrap in a closure because this task isn't defined 'till
124119 // the android plugin finishes
125- builtBy { tasks[" bundle ${ flavor.name.capitalize() } Release " ] }
120+ builtBy { tasks[" bundleRelease " ] }
126121 }
127122 // Add the sources and javadoc JARs
128123 artifact sourcesJar
@@ -132,7 +127,7 @@ publishing {
132127 pom. withXml {
133128 def n = asNode()
134129
135- n. appendNode(" description" , flavorsToPublicationsMap[flavor . name] . description )
130+ n. appendNode(" description" , artifactDesc )
136131 n. appendNode(" inceptionYear" , 2016 )
137132
138133 def licensesNode = n. appendNode(" licenses" )
@@ -168,76 +163,27 @@ publishing {
168163 dependencyNode. appendNode(' groupId' , it. group)
169164 dependencyNode. appendNode(' artifactId' , it. name)
170165 dependencyNode. appendNode(' version' , it. version)
166+ dependencyNode. appendNode(' type' , ' aar' )
171167 }
172168
173169 // add deps that everyone has
174170 configurations. compile. allDependencies. each addDep
175171 // add config specific deps
176- configurations[" ${ flavor.name } Compile " ]. allDependencies. each addDep
172+ configurations[" releaseCompile " ]. allDependencies. each addDep
177173 }
178174 }
179175 }
180176 }
181177}
182178
183- // Merges required classes into the resulting AAR (UberJAR style). Without
184- // this, the classes from gcm_defs wouldn't be packed into the AAR. We also
185- // need to make sure that the withGcmDeps flavor doesn't include the GCM
186- // parcelables.
187179afterEvaluate {
188- android. productFlavors. each { flavor ->
189- android. buildTypes. each { bt ->
190- def artifactName = " gcm_defs-release"
191- def jarDestDir = " ${ buildDir} /intermediates/libs/${ flavor.name} /${ bt.name} /libs"
192- def unpackedDestDir = " ${ buildDir} /unpacked/${ artifactName} "
193-
194- def copyLibs = task(" copy${ flavor.name.capitalize()}${ bt.name.capitalize()} Libs" ,
195- type : Copy ) {
196- description " Copies gcm_defs aar into the build dir"
197-
198- from configurations. provided
199- include " ${ artifactName} .aar"
200- into jarDestDir
201- }
202-
203- def unzipClasses = task(" unzip${ flavor.name.capitalize()}${ bt.name.capitalize()} Libs" ,
204- type : Copy , dependsOn : copyLibs) {
205- description " Unzips the copied gcm_defs aar contents"
206-
207- from zipTree(" ${ jarDestDir} /${ artifactName} .aar" )
208- into unpackedDestDir
209- }
210-
211- def syncClasses = task(" sync${ flavor.name.capitalize()}${ bt.name.capitalize()} Libs" ,
212- type : Copy , dependsOn : unzipClasses) {
213- description " Merges the copied gcm_defs classes with the aar classes"
214-
215- from(zipTree(" ${ unpackedDestDir} /classes.jar" )) {
216- exclude " **/BuildConfig.class"
217-
218- if (flavor. name == " withGcmDep" ) {
219- // Parcelable included unobfuscated in the GCM lib
220- exclude " **/com/google/android/gms/gcm/PendingCallback*.class"
221-
222- // AIDL-derived IBinder that's obfuscated in the GCM
223- // lib, so we don't have to (and shouldn't) strip our
224- // copy because it doesn't conflict.
225- // exclude "**/com/google/android/gms/gcm/INetworkTaskCallback*.class"
226- }
227- }
228- into " ${ buildDir} /intermediates/classes/${ flavor.name} /${ bt.name} "
229- }
230-
231- def jarTask = tasks[" process${ flavor.name.capitalize()}${ bt.name.capitalize()} JavaRes" ]
232- jarTask. dependsOn syncClasses
233- }
234- }
235-
236180 bintray {
237181 user = findProperty(" BINTRAY_USER" ) ?: System . getenv(" BINTRAY_USER" )
238182 key = findProperty(" BINTRAY_KEY" ) ?: System . getenv(" BINTRAY_KEY" )
239183
240- publications = [" dispatcherNoDepLibrary" , " dispatcherWithGcmDepLibrary" ]
184+ publications = [
185+ " dispatcherLibraryStandardArtifact" ,
186+ " dispatcherLibraryLegacyArtifact" ]
241187
242188 pkg {
243189 userOrg = " firebase"
0 commit comments