2020-08-20 23:40:33 +02:00
|
|
|
/**
|
2023-09-12 16:39:26 +02:00
|
|
|
* Downloads all android-all-instrumented dependencies and copies them to the mavenLocal() repository
|
2020-08-20 23:40:33 +02:00
|
|
|
*
|
|
|
|
* Once applied to your gradle project, can be executed with ./gradlew robolectricSdkDownload
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.nio.file.Files
|
|
|
|
|
|
|
|
// The general idea of this was borrowed from https://gist.github.com/xian/05c4f27da6d4156b9827842217c2cd5c
|
|
|
|
// I then modified it heavily to allow easier addition of new SDK versions
|
|
|
|
// The full implementation is from https://gist.github.com/simtel12/13ff3e57c37e78e468502b51ebb0f4f2
|
|
|
|
|
2021-10-18 23:20:56 +02:00
|
|
|
// List from: https://github.com/robolectric/robolectric/blob/master/robolectric/src/main/java/org/robolectric/plugins/DefaultSdkProvider.java
|
2020-08-20 23:40:33 +02:00
|
|
|
// This list will need to be updated for new Android SDK versions that come out.
|
2023-09-12 16:39:26 +02:00
|
|
|
|
2020-08-20 23:40:33 +02:00
|
|
|
// Only the versions currently used in AnkiDroid Robolectric tests are active, the rest are commented out
|
2023-09-12 16:39:26 +02:00
|
|
|
// To update these versions, open a terminal in the Anki-Android directory and perform the following steps:
|
|
|
|
// 1. Run `rm -r ~/.m2` to delete the .m2 directory in your home directory.
|
|
|
|
// 2. Run `./gradlew jacocoUnitTestReport` to run all unit tests.
|
|
|
|
// 3. Run `find ~/.m2 -type d -name '*-robolectric-*'`.
|
|
|
|
// 4. Update the lines below to match the output from `find`.
|
2020-08-20 23:40:33 +02:00
|
|
|
def robolectricAndroidSdkVersions = [
|
|
|
|
// [androidVersion: "6.0.1_r3", frameworkSdkBuildVersion: "r1"],
|
2021-10-18 23:20:56 +02:00
|
|
|
// [androidVersion: "7.0.0_r1", frameworkSdkBuildVersion: "r1"],
|
2020-08-20 23:40:33 +02:00
|
|
|
// [androidVersion: "7.1.0_r7", frameworkSdkBuildVersion: "r1"],
|
2022-03-27 18:12:51 +02:00
|
|
|
// [androidVersion: "8.0.0_r4", frameworkSdkBuildVersion: "r1"],
|
2020-08-20 23:40:33 +02:00
|
|
|
// [androidVersion: "8.1.0", frameworkSdkBuildVersion: "4611349"],
|
2023-09-12 16:39:26 +02:00
|
|
|
[androidVersion: "9", frameworkSdkBuildVersion: "4913185-2"],
|
2021-10-18 23:20:56 +02:00
|
|
|
[androidVersion: "10", frameworkSdkBuildVersion: "5803371"],
|
2023-09-12 16:39:26 +02:00
|
|
|
[androidVersion: "11", frameworkSdkBuildVersion: "6757853"],
|
2023-08-18 20:26:01 +02:00
|
|
|
// [androidVersion: "12", frameworkSdkBuildVersion: "7732740"],
|
2023-10-31 16:51:28 +01:00
|
|
|
// [androidVersion: "12.1", frameworkSdkBuildVersion: "8229987"],
|
2023-09-12 16:39:26 +02:00
|
|
|
[androidVersion: "13", frameworkSdkBuildVersion: "9030017"],
|
2023-10-31 16:51:28 +01:00
|
|
|
[androidVersion: "14", frameworkSdkBuildVersion: "10818077"],
|
2020-08-20 23:40:33 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
// Base, public task - will be displayed in ./gradlew robolectricDownloader:tasks
|
2023-11-30 22:01:31 +01:00
|
|
|
tasks.register('robolectricSdkDownload') {
|
2020-08-20 23:40:33 +02:00
|
|
|
group = "Dependencies"
|
|
|
|
description = "Downloads all robolectric SDK dependencies into mavenLocal, for use with offline robolectric"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the configuration and actual copy tasks.
|
|
|
|
robolectricAndroidSdkVersions.forEach { robolectricSdkVersion ->
|
2023-09-12 16:39:26 +02:00
|
|
|
def version = "${robolectricSdkVersion['androidVersion']}-robolectric-${robolectricSdkVersion['frameworkSdkBuildVersion']}-i4"
|
2020-08-20 23:40:33 +02:00
|
|
|
|
|
|
|
// Creating a configuration with a dependency allows Gradle to manage the actual resolution of
|
|
|
|
// the jar file
|
|
|
|
def sdkConfig = configurations.create(version)
|
2023-09-12 16:39:26 +02:00
|
|
|
dependencies.add(version, "org.robolectric:android-all-instrumented:${version}")
|
2020-08-20 23:40:33 +02:00
|
|
|
|
|
|
|
def mavenLocalFile = new File(this.repositories.mavenLocal().url)
|
2023-09-12 16:39:26 +02:00
|
|
|
def mavenRobolectric = new File(mavenLocalFile, "org/robolectric/android-all-instrumented/${version}")
|
2020-08-20 23:40:33 +02:00
|
|
|
// Copying all files downloaded for the created configuration into maven local.
|
2023-11-30 22:01:31 +01:00
|
|
|
tasks.register("robolectricSdkDownload-${version}", Copy) {
|
2020-08-20 23:40:33 +02:00
|
|
|
from sdkConfig
|
|
|
|
into mavenRobolectric
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
ArtifactResolutionResult result = dependencies.createArtifactResolutionQuery()
|
2023-09-12 16:39:26 +02:00
|
|
|
.forModule("org.robolectric", "android-all-instrumented", version)
|
2020-08-20 23:40:33 +02:00
|
|
|
.withArtifacts(MavenModule, MavenPomArtifact)
|
|
|
|
.execute()
|
|
|
|
|
|
|
|
for(component in result.resolvedComponents) {
|
|
|
|
def componentId = component.id
|
|
|
|
|
|
|
|
if(componentId instanceof ModuleComponentIdentifier) {
|
|
|
|
File pomFile = component.getArtifacts(MavenPomArtifact)[0].file
|
|
|
|
File dest = new File(mavenRobolectric, pomFile.name)
|
|
|
|
if (!dest.exists()) {
|
|
|
|
Files.copy(pomFile.toPath(), dest.toPath())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-30 22:01:31 +01:00
|
|
|
robolectricSdkDownload.configure { dependsOn "robolectricSdkDownload-${version}" }
|
2020-08-20 23:40:33 +02:00
|
|
|
}
|
|
|
|
|