Skip to content
This repository was archived by the owner on Oct 31, 2022. It is now read-only.

Commit 906c765

Browse files
committed
Ignore Firebase Unity libraries
* Example such as com.google.firebase:firebase-messaging-unity:6.2.2 - We need to omit as these wrapper library versions do not line up with Firebase's native ones
1 parent 1f3f1aa commit 906c765

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

src/main/groovy/com/onesignal/androidsdk/GradleProjectPlugin.groovy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ class GradleProjectPlugin implements Plugin<Project> {
6969

7070
// ### Google Firebase library
7171
(GROUP_FIREBASE): [
72-
version: NO_REF_VERSION
72+
version: NO_REF_VERSION,
73+
// Do not attempt to align Firebase's Unity libraries
74+
// These wrapper libraries have their own version numbers that don't line up
75+
omitModulesPostFix: '-unity',
7376
],
7477

7578
// ### Android Support Library
@@ -598,6 +601,10 @@ class GradleProjectPlugin implements Plugin<Project> {
598601
if (omitModules && omitModules.contains(name))
599602
return false
600603

604+
def omitModulesPostFix = versionOverride['omitModulesPostFix']
605+
if (omitModulesPostFix && name.endsWith(omitModulesPostFix))
606+
return false
607+
601608
true
602609
}
603610

src/test/groovy/com/onesignal/androidsdk/GradleTestTemplate.groovy

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class GradleTestTemplate {
108108
'''.stripIndent()
109109
}
110110

111-
static def createGradlePropertiesFile(buildSections) {
111+
static void createGradlePropertiesFile(buildSections) {
112112
def gradlePropertiesFile = testProjectDir.newFile("gradle.properties")
113113
gradlePropertiesFile << """\
114114
android.useAndroidX=${buildSections['android.useAndroidX'] ?: false}
@@ -119,6 +119,26 @@ class GradleTestTemplate {
119119
""".stripIndent()
120120
}
121121

122+
// Creates a local maven repo to test local libraries; such as firebase-app-unity
123+
static void createM2repository(String group, String module, String version) {
124+
final libPath = "m2repository/${group.replace('.', '/')}/${module}/${version}"
125+
testProjectDir.newFolder(libPath.split('/'))
126+
127+
final pomFile = testProjectDir.newFile("${libPath}/${module}-${version}.pom")
128+
pomFile << """\
129+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
130+
xmlns="http://maven.apache.org/POM/4.0.0"
131+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
132+
<modelVersion>4.0.0</modelVersion>
133+
<groupId>${group}</groupId>
134+
<artifactId>${module}</artifactId>
135+
<version>${version}</version>
136+
<packaging>pom</packaging>
137+
<dependencies></dependencies>
138+
</project>
139+
"""
140+
}
141+
122142
static void createBuildFile(buildSections) {
123143
testProjectDir = new TemporaryFolder()
124144
testProjectDir.create()
@@ -151,6 +171,8 @@ class GradleTestTemplate {
151171
allprojects {
152172
repositories {
153173
maven { url 'https://maven.google.com' }
174+
// Local maven repo to test local libaries; such as firebase-app-unity
175+
maven { url(uri('m2repository')) }
154176
jcenter()
155177
}
156178
}
@@ -264,14 +286,15 @@ class GradleTestTemplate {
264286
createSubProject(currentParams)
265287
createProguardFile()
266288

267-
// Test running gradle plugin last on newest version of Gradle only
268-
// if (gradleVersion.key == GRADLE_OLDEST_VERSION)
269-
// return
270-
// currentParams['onesignalPluginId'] = "id 'com.onesignal.androidsdk.onesignal-gradle-plugin' apply false"
271-
// currentParams['applyPlugins'] = "apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'"
289+
// Uncomment to test with only the latest version of Gradle
290+
// if (!runLatestGradleOnly(gradleVersion, currentParams))
291+
// return
272292

273293
buildArguments.removeAll([null])
274294

295+
if (buildParams['preBuildClosure'])
296+
buildParams['preBuildClosure']()
297+
275298
def result =
276299
GradleRunner.create()
277300
.withProjectDir(testProjectDir.root)
@@ -293,4 +316,12 @@ class GradleTestTemplate {
293316
if (buildSections['onesignalPluginId'] == null)
294317
buildSections['onesignalPluginId'] = "id 'com.onesignal.androidsdk.onesignal-gradle-plugin'"
295318
}
319+
320+
static boolean runLatestGradleOnly(gradleVersion, currentParams) {
321+
if (gradleVersion.key == GRADLE_OLDEST_VERSION)
322+
return false
323+
currentParams['onesignalPluginId'] = "id 'com.onesignal.androidsdk.onesignal-gradle-plugin' apply false"
324+
currentParams['applyPlugins'] = "apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'"
325+
true
326+
}
296327
}

src/test/groovy/com/onesignal/androidsdk/MainTest.groovy

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MainTest extends Specification {
2525

2626
then:
2727
results.each {
28-
assert it.value.contains('com.onesignal:OneSignal:[3.8.3, 3.99.99] -> 3.11.1')
28+
assert it.value.contains('com.onesignal:OneSignal:[3.8.3, 3.99.99] -> 3.11.2')
2929
}
3030
}
3131

@@ -964,6 +964,27 @@ class MainTest extends Specification {
964964
}
965965
}
966966

967+
def 'when firebase-app-unity and firebase-messaging'() {
968+
when:
969+
def results = runGradleProject([
970+
skipGradleVersion: GRADLE_OLDEST_VERSION,
971+
compileLines : """\
972+
implementation 'com.google.firebase:firebase-messaging:17.0.0'
973+
implementation 'com.google.firebase:firebase-app-unity:6.2.2'
974+
""",
975+
preBuildClosure: {
976+
GradleTestTemplate.createM2repository('com.google.firebase', 'firebase-app-unity', '6.2.2')
977+
}
978+
])
979+
980+
then:
981+
assert results // Asserting existence and contains 1+ entries
982+
results.each {
983+
// Ensure we are not trying to update this unity library
984+
assert it.value.contains('com.google.firebase:firebase-app-unity:6.2.2\n')
985+
}
986+
}
987+
967988
// Note: Slow 20 second test, this is doing a full build
968989
// This is needed as we are making sure compile and runtime versions are not being miss aligned
969990
// Asserts just a double check as Gradle or AGP fails to build when this happens

0 commit comments

Comments
 (0)