Skip to content

Commit 5b8fa50

Browse files
committed
switch sdk to use Gradle's rich versions
This allows us to define a required version range while providing a preferred tested exact version. This gives the consumer consistent versions when building that won't change if a newer version of a library like firebase-messaging is released. We want to keep version ranges to be as compatible as possible with other dependencies declared for the exact module we use. This means if an older version of a library OneSignal depends on is also required by the app or its dependencies Gradle will accommodate within the ranges that overlap. This also fixes build errors when the app uses `strict-version-matcher-plugin` or uses the `google-services` Gradle plugins without setting `disableVersionCheck = true`. This is because the Google plugins require a version scheme the provides consistent builds. I have tested end-to-end to confirm the facts above are correct.
1 parent 821bbfe commit 5b8fa50

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

OneSignalSDK/onesignal/build.gradle

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,67 @@ dependencies {
4747

4848
// play-services-location:16.0.0 is the last version before going to AndroidX
4949
// play-services-location:17.0.0 is the first version using AndroidX
50-
compileOnly 'com.google.android.gms:play-services-location:[17.0.0, 18.0.99]'
50+
compileOnly('com.google.android.gms:play-services-location:[17.0.0, 18.0.99]') {
51+
version {
52+
require '[17.0.0, 18.0.99]'
53+
prefer '18.0.0'
54+
}
55+
}
5156

5257
// play-services-base:16.1.0 is the last version before going to AndroidX
5358
// play-services-base:17.0.0 is the first version using AndroidX
5459
// Required for GoogleApiAvailability
55-
implementation 'com.google.android.gms:play-services-base:[17.0.0, 17.6.99]'
60+
implementation('com.google.android.gms:play-services-base') {
61+
version {
62+
require '[17.0.0, 17.6.99]'
63+
prefer '17.6.0'
64+
}
65+
}
5666

5767
// firebase-messaging:18.0.0 is the last version before going to AndroidX
5868
// firebase-messaging:19.0.0 is the first version using AndroidX
59-
api 'com.google.firebase:firebase-messaging:[19.0.0, 22.0.99]'
69+
api('com.google.firebase:firebase-messaging') {
70+
version {
71+
require '[19.0.0, 22.0.99]'
72+
prefer '22.0.0'
73+
}
74+
}
6075

6176
// Huawei PushKit
6277
// KEEP as "compileOnly", so OneSignal isn't a direct dependency in the POM file.
6378
compileOnly "com.huawei.hms:push:$huaweiHMSPushVersion"
6479
compileOnly "com.huawei.hms:location:$huaweiHMSLocationVersion"
6580

66-
api 'androidx.cardview:cardview:[1.0.0, 1.0.99]'
67-
api 'androidx.legacy:legacy-support-v4:[1.0.0, 1.0.99]'
68-
api 'androidx.browser:browser:[1.0.0, 1.3.99]'
69-
api 'androidx.appcompat:appcompat:[1.0.0, 1.3.99]'
70-
api 'androidx.work:work-runtime:[2.1.0, 2.7.99]'
81+
api('androidx.cardview:cardview') {
82+
version {
83+
require '[1.0.0, 1.0.99]'
84+
prefer '1.0.0'
85+
}
86+
}
87+
api('androidx.legacy:legacy-support-v4') {
88+
version {
89+
require '[1.0.0, 1.0.99]'
90+
prefer '1.0.0'
91+
}
92+
}
93+
api('androidx.browser:browser') {
94+
version {
95+
require '[1.0.0, 1.3.99]'
96+
prefer '1.3.0'
97+
}
98+
}
99+
api('androidx.appcompat:appcompat') {
100+
version {
101+
require '[1.0.0, 1.3.99]'
102+
prefer '1.3.1'
103+
}
104+
}
105+
api('androidx.work:work-runtime') {
106+
version {
107+
require '[2.1.0, 2.7.99]'
108+
prefer '2.7.1'
109+
}
110+
}
71111
}
72112

73-
apply from: 'maven-push.gradle'
113+
apply from: 'maven-push.gradle'

0 commit comments

Comments
 (0)