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

Commit 838734d

Browse files
authored
Merge pull request #182 from OneSignal/feat/downgrade_work-runtime_if_needed
Downgrade work-runtime if needed
2 parents b1ebcc9 + 80bb513 commit 838734d

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class GradleProjectPlugin implements Plugin<Project> {
5353

5454
static final String GROUP_GMS = 'com.google.android.gms'
5555
static final String GROUP_ANDROID_SUPPORT = 'com.android.support'
56+
static final String GROUP_ANDROIDX = 'androidx.work'
5657
static final String GROUP_FIREBASE = 'com.google.firebase'
5758
static final String GROUP_ONESIGNAL = 'com.onesignal'
5859

@@ -101,7 +102,19 @@ class GradleProjectPlugin implements Plugin<Project> {
101102
// Exists only for UPDATE_PARENT_ON_DEPENDENCY_UPGRADE
102103
(GROUP_ONESIGNAL): [
103104
version: NO_REF_VERSION
104-
]
105+
],
106+
107+
// Exists only for MODULE_DEPENDENCY_MAX_ANDROID_COMPILE_SDK
108+
(GROUP_ANDROIDX): [
109+
version: NO_REF_VERSION
110+
],
111+
]
112+
113+
// Sets an upper limit for specific modules based on the compileSdkVersion
114+
static final Map<String, Map<Integer, String>> MODULE_DEPENDENCY_MAX_ANDROID_COMPILE_SDK = [
115+
'androidx.work:work-runtime': [
116+
30: '[2.0.0, 2.6.99]',
117+
],
105118
]
106119

107120

@@ -615,8 +628,12 @@ class GradleProjectPlugin implements Plugin<Project> {
615628
versionOverride['version'] = newMaxVersion
616629
}
617630

631+
static int getCompileSdkVersion() {
632+
(project.android.compileSdkVersion as String).split('-')[1].toInteger()
633+
}
634+
618635
static String maxAndroidSupportVersion(Map<Integer, String> maxSupportVersionObj) {
619-
def compileSdkVersion = (project.android.compileSdkVersion as String).split('-')[1].toInteger()
636+
def compileSdkVersion = getCompileSdkVersion()
620637
if (compileSdkVersion <= LAST_MAJOR_ANDROID_SUPPORT_VERSION) {
621638
String maxSupportVersion = maxSupportVersionObj[compileSdkVersion]
622639
if (maxSupportVersion)
@@ -937,10 +954,21 @@ class GradleProjectPlugin implements Plugin<Project> {
937954
}
938955
}
939956

957+
updateVersionModuleAlignsForCompileSdkVersion(inputModule)
958+
940959
if (group == GROUP_GMS && module == 'play-services')
941960
hasFullPlayServices = true
942961
}
943962

963+
static void updateVersionModuleAlignsForCompileSdkVersion(String module) {
964+
def compileVersion = getCompileSdkVersion()
965+
MODULE_DEPENDENCY_MAX_ANDROID_COMPILE_SDK[module].each {maxSdkVersion , versionMax ->
966+
if (compileVersion <= maxSdkVersion) {
967+
versionModuleAligns[module] = [version: versionMax]
968+
}
969+
}
970+
}
971+
944972
static void updateVersionModuleAlignsKey(String groupAndModule, String version) {
945973
versionModuleAligns[groupAndModule] = [version: version]
946974

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GradleTestTemplate {
1313
static def buildArgumentSets = [:]
1414

1515
static def defaultBuildParams = [
16-
compileSdkVersion: 30,
16+
compileSdkVersion: 31,
1717
targetSdkVersion: 30,
1818
minSdkVersion: 16
1919
]
@@ -162,6 +162,7 @@ class GradleTestTemplate {
162162
buildscript {
163163
repositories {
164164
maven { url 'https://maven.google.com' }
165+
mavenCentral()
165166
jcenter()
166167
}
167168
dependencies {
@@ -184,6 +185,7 @@ class GradleTestTemplate {
184185
maven { url 'https://maven.google.com' }
185186
// Local maven repo to test local libaries; such as firebase-app-unity
186187
maven { url(uri('m2repository')) }
188+
mavenCentral()
187189
jcenter()
188190
}
189191
}

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,4 +1274,68 @@ class MainTest extends Specification {
12741274
then:
12751275
assert results // Asserting existence and contains 1+ entries
12761276
}
1277+
1278+
// AGP task checkDebugAarMetadata has a build rule that checks for compileSdkVersion 31
1279+
// via a minCompileSdk property defined in the aar-metadata.properties in the work-runtime-2.7.0.aar
1280+
def runGradleProjectForCompileSdkVersion30WithWorkRuntime2_7_0() {
1281+
runGradleProject([
1282+
'android.useAndroidX': true,
1283+
compileSdkVersion: 30,
1284+
compileLines : "implementation 'androidx.work:work-runtime:[2.0.0, 2.7.0]'",
1285+
skipGradleVersion : GRADLE_OLDEST_VERSION,
1286+
])
1287+
}
1288+
1289+
def 'compileSdkVersion 30 with work-runtime:2.7.0, passes checkDebugAarMetadata'() {
1290+
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['checkDebugAarMetadata']]
1291+
1292+
when:
1293+
def results = runGradleProjectForCompileSdkVersion30WithWorkRuntime2_7_0()
1294+
1295+
then:
1296+
assert results // Asserting existence and contains 1+ entries
1297+
}
1298+
1299+
def 'compileSdkVersion 30 with work-runtime:2.7.0, downgrades to 2.6.0'() {
1300+
when:
1301+
def results = runGradleProjectForCompileSdkVersion30WithWorkRuntime2_7_0()
1302+
1303+
then:
1304+
assertResults(results) {
1305+
assert it.value.contains('androidx.work:work-runtime:[2.0.0, 2.7.0] -> 2.6.0')
1306+
}
1307+
}
1308+
1309+
def 'compileSdkVersion 30 with onesignal:4.6.2, passes checkDebugAarMetadata'() {
1310+
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['checkDebugAarMetadata']]
1311+
1312+
when:
1313+
def results = runGradleProject([
1314+
'android.useAndroidX': true,
1315+
compileSdkVersion: 30,
1316+
compileLines : "implementation 'com.onesignal:OneSignal:4.6.2'",
1317+
skipGradleVersion : GRADLE_OLDEST_VERSION,
1318+
])
1319+
1320+
then:
1321+
assert results // Asserting existence and contains 1+ entries
1322+
}
1323+
1324+
def 'compileSdkVersion 30 with onesignal:4.6.2 & work-runtime:2.4.0 '() {
1325+
when:
1326+
def results = runGradleProject([
1327+
'android.useAndroidX': true,
1328+
compileSdkVersion: 30,
1329+
compileLines : '''
1330+
implementation 'com.onesignal:OneSignal:4.6.2'
1331+
implementation 'androidx.work:work-runtime:2.4.0'
1332+
''',
1333+
skipGradleVersion : GRADLE_OLDEST_VERSION,
1334+
])
1335+
1336+
then:
1337+
assertResults(results) {
1338+
assert it.value.contains('androidx.work:work-runtime:[2.1.0, 2.7.99] -> 2.4.0')
1339+
}
1340+
}
12771341
}

0 commit comments

Comments
 (0)