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

Commit eb1513b

Browse files
authored
Merge pull request #147 from OneSignal/fix/disableGMSVersionChecks
Fix disableVersionCheck when GoogleServicesPlugin is applied with afterEvaluate
2 parents 32bcc6f + 3f42930 commit eb1513b

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,8 @@ class GradleProjectPlugin implements Plugin<Project> {
303303
// At fundamental level this OneSignal plugin and the gms version checks are solving the same problem
304304
// Disabling the version check part of the gms plugin with their flag
305305
static void disableGMSVersionChecks() {
306-
project.afterEvaluate {
307-
def googleServices = project.extensions.findByName('googleServices')
308-
if (googleServices)
309-
googleServices.disableVersionCheck = true
306+
project.plugins.withType(Plugin) {
307+
project.extensions.findByName('googleServices')?.disableVersionCheck = true
310308
}
311309
}
312310

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,31 @@ class MainTest extends Specification {
758758
assert results // Asserting existence and contains 1+ entries
759759
}
760760

761+
def 'can disable "Google Services Gradle Plugin" version checks with disableVersionCheck'() {
762+
// com.onesignal:OneSignal:3.15.6' defines a version range of play-services-base@[10.2.1, 16.1.99]
763+
// 17.3.0 is outside of that but this is ok, since enableJetifier is enabled in this case.
764+
// However "Google Services Gradle Plugin" thinks there is a version out of range and fails the build
765+
// We are ensuring this plugin sets disableVersionCheck correctly to disable it
766+
def compileLines = """\
767+
compile 'com.onesignal:OneSignal:3.15.6'
768+
compile 'com.google.android.gms:play-services-base:17.3.0'
769+
"""
770+
771+
when:
772+
def results = runGradleProject([
773+
skipGradleVersion: GRADLE_OLDEST_VERSION,
774+
'android.useAndroidX': true,
775+
'android.enableJetifier': true,
776+
buildscriptDependencies: "classpath 'com.google.gms:google-services:4.3.4'",
777+
applyPlugins: "apply plugin: 'com.google.gms.google-services'",
778+
compileLines : compileLines
779+
])
780+
781+
then:
782+
assertResults(results) {
783+
}
784+
}
785+
761786
def 'firebase 15 - keep mixed minor versions'() {
762787
def compileLines = """\
763788
compile 'com.google.firebase:firebase-ads:15.0.0'
@@ -778,6 +803,29 @@ class MainTest extends Specification {
778803
}
779804
}
780805

806+
// Same as the test above but handles the afterEvaluate case. See a plugin that does this below
807+
// https://github.com/dpa99c/cordova-plugin-firebasex/blob/11.0.3/src/android/build.gradle#L43
808+
def 'can disable "Google Services Gradle Plugin" version checks with disableVersionCheck - even if added in afterEvaluate'() {
809+
def compileLines = """\
810+
compile 'com.onesignal:OneSignal:3.15.6'
811+
compile 'com.google.android.gms:play-services-base:17.3.0'
812+
"""
813+
814+
when:
815+
def results = runGradleProject([
816+
skipGradleVersion: GRADLE_OLDEST_VERSION,
817+
'android.useAndroidX': true,
818+
'android.enableJetifier': true,
819+
buildscriptDependencies: "classpath 'com.google.gms:google-services:4.3.4'",
820+
applyPlugins: "afterEvaluate { apply plugin: 'com.google.gms.google-services' }",
821+
compileLines : compileLines,
822+
])
823+
824+
then:
825+
assertResults(results) {
826+
}
827+
}
828+
781829
def 'gms 15 - Support for 12 and 15 version'() {
782830
def compileLines = """\
783831
compile 'com.google.android.gms:play-services-gcm:12.0.1'

0 commit comments

Comments
 (0)