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

Downgrade work-runtime to 2.6.0 if compileSdkVersion 30 or older is used #182

Merged
merged 5 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class GradleProjectPlugin implements Plugin<Project> {

static final String GROUP_GMS = 'com.google.android.gms'
static final String GROUP_ANDROID_SUPPORT = 'com.android.support'
static final String GROUP_ANDROIDX = 'androidx.work'
static final String GROUP_FIREBASE = 'com.google.firebase'
static final String GROUP_ONESIGNAL = 'com.onesignal'

Expand Down Expand Up @@ -101,7 +102,19 @@ class GradleProjectPlugin implements Plugin<Project> {
// Exists only for UPDATE_PARENT_ON_DEPENDENCY_UPGRADE
(GROUP_ONESIGNAL): [
version: NO_REF_VERSION
]
],

// Exists only for MODULE_DEPENDENCY_MAX_ANDROID_COMPILE_SDK
(GROUP_ANDROIDX): [
version: NO_REF_VERSION
],
]

// Sets an upper limit for specific modules based on the compileSdkVersion
static final Map<String, Map<Integer, String>> MODULE_DEPENDENCY_MAX_ANDROID_COMPILE_SDK = [
'androidx.work:work-runtime': [
30: '[2.0.0, 2.6.99]',
],
]


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

static int getCompileSdkVersion() {
(project.android.compileSdkVersion as String).split('-')[1].toInteger()
}

static String maxAndroidSupportVersion(Map<Integer, String> maxSupportVersionObj) {
def compileSdkVersion = (project.android.compileSdkVersion as String).split('-')[1].toInteger()
def compileSdkVersion = getCompileSdkVersion()
if (compileSdkVersion <= LAST_MAJOR_ANDROID_SUPPORT_VERSION) {
String maxSupportVersion = maxSupportVersionObj[compileSdkVersion]
if (maxSupportVersion)
Expand Down Expand Up @@ -937,10 +954,21 @@ class GradleProjectPlugin implements Plugin<Project> {
}
}

updateVersionModuleAlignsForCompileSdkVersion(inputModule)

if (group == GROUP_GMS && module == 'play-services')
hasFullPlayServices = true
}

static void updateVersionModuleAlignsForCompileSdkVersion(String module) {
def compileVersion = getCompileSdkVersion()
MODULE_DEPENDENCY_MAX_ANDROID_COMPILE_SDK[module].each {maxSdkVersion , versionMax ->
if (compileVersion <= maxSdkVersion) {
versionModuleAligns[module] = [version: versionMax]
}
}
}

static void updateVersionModuleAlignsKey(String groupAndModule, String version) {
versionModuleAligns[groupAndModule] = [version: version]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GradleTestTemplate {
static def buildArgumentSets = [:]

static def defaultBuildParams = [
compileSdkVersion: 30,
compileSdkVersion: 31,
targetSdkVersion: 30,
minSdkVersion: 16
]
Expand Down Expand Up @@ -162,6 +162,7 @@ class GradleTestTemplate {
buildscript {
repositories {
maven { url 'https://maven.google.com' }
mavenCentral()
jcenter()
}
dependencies {
Expand All @@ -184,6 +185,7 @@ class GradleTestTemplate {
maven { url 'https://maven.google.com' }
// Local maven repo to test local libaries; such as firebase-app-unity
maven { url(uri('m2repository')) }
mavenCentral()
jcenter()
}
}
Expand Down
64 changes: 64 additions & 0 deletions src/test/groovy/com/onesignal/androidsdk/MainTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1274,4 +1274,68 @@ class MainTest extends Specification {
then:
assert results // Asserting existence and contains 1+ entries
}

// AGP task checkDebugAarMetadata has a build rule that checks for compileSdkVersion 31
// via a minCompileSdk property defined in the aar-metadata.properties in the work-runtime-2.7.0.aar
def runGradleProjectForCompileSdkVersion30WithWorkRuntime2_7_0() {
runGradleProject([
'android.useAndroidX': true,
compileSdkVersion: 30,
compileLines : "implementation 'androidx.work:work-runtime:[2.0.0, 2.7.0]'",
skipGradleVersion : GRADLE_OLDEST_VERSION,
])
}

def 'compileSdkVersion 30 with work-runtime:2.7.0, passes checkDebugAarMetadata'() {
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['checkDebugAarMetadata']]

when:
def results = runGradleProjectForCompileSdkVersion30WithWorkRuntime2_7_0()

then:
assert results // Asserting existence and contains 1+ entries
}

def 'compileSdkVersion 30 with work-runtime:2.7.0, downgrades to 2.6.0'() {
when:
def results = runGradleProjectForCompileSdkVersion30WithWorkRuntime2_7_0()

then:
assertResults(results) {
assert it.value.contains('androidx.work:work-runtime:[2.0.0, 2.7.0] -> 2.6.0')
}
}

def 'compileSdkVersion 30 with onesignal:4.6.2, passes checkDebugAarMetadata'() {
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['checkDebugAarMetadata']]

when:
def results = runGradleProject([
'android.useAndroidX': true,
compileSdkVersion: 30,
compileLines : "implementation 'com.onesignal:OneSignal:4.6.2'",
skipGradleVersion : GRADLE_OLDEST_VERSION,
])

then:
assert results // Asserting existence and contains 1+ entries
}

def 'compileSdkVersion 30 with onesignal:4.6.2 & work-runtime:2.4.0 '() {
when:
def results = runGradleProject([
'android.useAndroidX': true,
compileSdkVersion: 30,
compileLines : '''
implementation 'com.onesignal:OneSignal:4.6.2'
implementation 'androidx.work:work-runtime:2.4.0'
''',
skipGradleVersion : GRADLE_OLDEST_VERSION,
])

then:
assertResults(results) {
assert it.value.contains('androidx.work:work-runtime:[2.1.0, 2.7.99] -> 2.4.0')
}
}
}