Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to AndroidX, gradle version and plugin updates #357

Merged
merged 20 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,35 @@ jobs:
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

runs-on: ubuntu-latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties
- name: Print Java version
run: java -version
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Git show commit count
run: git fetch origin master && git rev-list --first-parent --count origin/master
- name: Download Robolectric deps
run: chmod +x download-robolectric-deps.sh && ./download-robolectric-deps.sh
- name: Clean project
run: ./gradlew clean --stacktrace
- name: Build project skipping tests
run: ./gradlew build -x test --stacktrace
- name: Run jacocoTestReport for each module
- name: Run Instrumented Tests manually
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 22
script: ./gradlew jacocoTestReport --stacktrace
script: ./gradlew connectedDebug --stacktrace
- name: Run jacocoTestReport for each module
run: ./gradlew jacocoTestReport --stacktrace --info
- name: Merge jacoco reports from all modules
run: ./gradlew jacocoFullReport --stacktrace
- name: Upload coverage to Coveralls with Gradle
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@

**/jacoco.exec
**/*-journal

# Robolectric dependencies
robolectric-deps/
**/robolectric-deps.properties
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ The library offers a view `KujakuMapView` that provides more functionality than
- For Mapbox related functionality, [go here](https://docs.mapbox.com/android/maps/overview/)
- For extra features provided by this library [go here](./SPECIFICATION.md)

## `Unable to resolve artifact: Missing` while running tests

This is encountered when Robolectric has problems downloading the jars it needs for different Android SDK levels. If you keep running into this you can download the JARs locally and point Robolectric to them by doing:

```
./download-robolectric-deps.sh

## License

Expand Down
90 changes: 64 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@ buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven{ url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.fabric.io/public' }
}

dependencies {

classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'io.fabric.tools:gradle:1.25.4'
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.10.2'
classpath 'com.palantir:jacoco-coverage:0.4.0'
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
//classpath 'com.palantir:jacoco-coverage:0.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

apply plugin: 'com.palantir.jacoco-full-report'
apply plugin: 'com.github.kt3k.coveralls'
apply from: 'configs.gradle'

allprojects {
repositories {
google()
jcenter()
/*maven {
mavenLocal()
maven { url "https://jitpack.io" }
maven {
url "https://dl.cloudsmith.io/public/terraframe/geoprism-registry/maven/"
}
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
Expand All @@ -37,26 +43,19 @@ allprojects {
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
password = localProperties['mapbox.repo.token'] ?: ""
}
}*/
}
}
}

}
/*
task clean(type: Delete) {
delete rootProject.buildDir
}
*/

ext {
supportVersion = '28.0.0'
buildToolsVersion = "28.0.3"
compileSdkVersion = 28
volleyVersion = "1.1.0"
targetSdkVersion = 27
jacocoVersion = "0.7.9"
mapboxSdkVersion = "8.3.3"
mapboxAnnotationPluginVersion = "0.6.0"
}
apply plugin: 'java'

coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoFullReport/jacocoFullReport.xml"
Expand All @@ -66,12 +65,51 @@ coveralls {
, "wrapper/src/main/java"]
}

subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.getkeepsafe.relinker') {
details.useVersion "1.2.2"
task jacocoFullReport(type: JacocoReport, group: 'Coverage reports') {
description = 'Generates an aggregate report from all subprojects'

additionalSourceDirs.from = files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories.from = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories.from = files(subprojects.sourceSets.main.output)


List<File> executionDataPaths = new ArrayList<>()
List<File> classPaths = new ArrayList<>()
List<File> sourcePaths = new ArrayList<>()
List<File> jacocoClasspathPaths = new ArrayList<>()

for (subModule in subprojects) {
def jacocoTestReportTask = subModule.getTasksByName("jacocoTestReport", false)
jacocoTestReportTask.forEach({task ->
if (task instanceof JacocoReport) {
executionDataPaths.addAll((task as JacocoReport).executionData.getFiles())
classPaths.addAll((task as JacocoReport).classDirectories)
sourcePaths.addAll((task as JacocoReport).sourceDirectories)
jacocoClasspathPaths.addAll((task as JacocoReport).jacocoClasspath)
}
}
})
}

executionData.from = executionDataPaths
sourceDirectories.from = sourcePaths
classDirectories.from = classPaths

getReports().getXml().setDestination(file("${buildDir}/reports/jacoco/jacocoFullReport/jacocoFullReport.xml"))
getReports().getHtml().setDestination(file("${buildDir}/reports/jacoco/jacocoFullReport/html"))

reports {
html.enabled true
xml.enabled true
}

jacocoClasspath = files(jacocoClasspathPaths)
}


task printClasspath {
doLast {
this.printClasspath
}

//def task = org.gradle.testing.jacoco.tasks.JacocoReport()
}
150 changes: 150 additions & 0 deletions configs.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@

ant.condition(property: 'os', value: 'windows') {
os(family: 'windows')
}
ant.condition(property: 'os', value: 'unix') {
os(family: 'unix')
}

// Based on http://stackoverflow.com/questions/17097263#24121734
def getMasterCommitCount = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch (ant.properties.os) {
case 'windows':
commandLine 'cmd', '/c', 'git', 'rev-list', '--first-parent', '--count', 'master'
break
case 'unix':
commandLine 'git', 'rev-list', '--first-parent', '--count', 'origin/master'
break
}
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
} catch (ignored) {
return -1
}
}

def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch (ant.properties.os) {
case 'windows':
commandLine 'cmd', '/c', 'git', 'describe', '--tags', '--dirty', '--always'
break
case 'unix':
commandLine 'git', 'describe', '--tags', '--dirty', '--always'
break
}
standardOutput = stdout
}
return stdout.toString().trim()
} catch (ignored) {
return null
}
}

ext.getMasterCommitCount = getMasterCommitCount
ext.getVersionName = getVersionName


// LOAD PROPERTIES FILE
Properties properties = new Properties()
String[] propertyKeys = ["cgr.username", "cgr.password", "cgr.url", "mapbox.sdk.token", "mapbox.repo.token"]


if (project.rootProject.file("local.properties").exists()) {
properties.load(project.rootProject.file("local.properties").newDataInputStream())

if (properties != null) {
boolean containsAllKeys = true
ArrayList<String> missingKeys = new ArrayList<>()

for (String propertyKey: propertyKeys) {
if (!properties.containsKey(propertyKey)) {
missingKeys.add(propertyKey)
containsAllKeys = false
}
}

if (!containsAllKeys) {
println(("One of the required config variables is not set in your local.properties. Make sure you have " + missingKeys.join(", ")))
}
} else {
println("Properties was null!! The file does not exist or contains nothing")
}
} else {
println("local.properties does not exist")
}

if (properties == null) {
properties = new Properties()
}

for (String propertyKey: propertyKeys) {
if (!properties.containsKey(propertyKey)) {
properties.put(propertyKey, "\"\"")
}
}

ext.localProperties = properties


/**

Dependencies


*/

ext {

// Dependency and other versions
androidxTestCoreVersion = "1.4.0"
buildToolsVersion = "30.0.3"
compileSdkVersion = 28
jacocoVersion = "0.8.8"
junitVersion = "4.12"
mapboxAnnotationPluginVersion = "0.9.0"
mapboxSdkVersion = "9.7.1"
robolectricShadowsMultidexVersion = "4.3.1"
robolectricVersion = "4.3.1"
supportVersion = "1.0.0"
volleyVersion = "1.2.0"
targetSdkVersion = 27

// Dependency names
androidxTestCore = "androidx.test:core:$androidxTestCoreVersion"
junit = "junit:junit:$junitVersion"
mapboxSDK = "com.mapbox.mapboxsdk:mapbox-android-sdk:$mapboxSdkVersion"
mapboxSDKTurf = "com.mapbox.mapboxsdk:mapbox-sdk-turf:4.8.0"
mapboxAnnotationPlugin = "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:$mapboxAnnotationPluginVersion"
robolectric = "org.robolectric:robolectric:$robolectricVersion"
robolectricShadowsMultidex = "org.robolectric:shadows-multidex:$robolectricShadowsMultidexVersion"
}


//ext.mapboxSDK = "com.mapbox.maps:android:10.7.0"

ext.mapboxDependencies = { instance, configuration ->

configuration.implementation("com.mapbox.maps:android:$mapboxSdkVersion") {
transitive = true;
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-fragment'
}


// The local build has an issue fetching this library for some reason which
// is a dependency of the mapbox-android-sdk. The mapbox-sdk-turf is declared as
// a runtime dependency
configuration.implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.8.0'
configuration.implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:${instance.mapboxAnnotationPluginVersion}"

}

//ext.mapboxDependencies = mapboxDependencies
16 changes: 16 additions & 0 deletions download-robolectric-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
mkdir robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar -P robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/8.1.0-robolectric-4611349/android-all-8.1.0-robolectric-4611349.jar -P robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/8.0.0_r4-robolectric-r1/android-all-8.0.0_r4-robolectric-r1.jar -P robolectric-deps

wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/6.0.1_r3-robolectric-r1/android-all-6.0.1_r3-robolectric-r1.jar -P robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/7.0.0_r1-robolectric-r1/android-all-7.0.0_r1-robolectric-r1.jar -P robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/7.1.0_r7-robolectric-r1/android-all-7.1.0_r7-robolectric-r1.jar -P robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/9-robolectric-4913185-2/android-all-9-robolectric-4913185-2.jar -P robolectric-deps
wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all/11-robolectric-6757853/android-all-11-robolectric-6757853.jar -P robolectric-deps

cp robolectric-deps.properties library/src/test/resources
cp robolectric-deps.properties utils/src/test/resources
cp robolectric-deps.properties sample/src/test/resources
cp robolectric-deps.properties wrapper/src/test/resources
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ POM_SETTING_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_SETTING_LICENCE_DIST=repo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to bump up the artefact version for tagging on git and publishing the snapshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do that here but I prefer to have this on separate PRs for better tracking since releases were not always done after every PR https://github.com/onaio/kujaku/pulls?q=is%3Apr+sort%3Aupdated-desc+is%3Aclosed+release

POM_SETTING_DEVELOPER_ID=opensrp
POM_SETTING_DEVELOPER_NAME=OpenSRP Onadev
android.useAndroidX=true
android.enableJetifier=true

android.jetifier.ignorelist=shadows,bcprov-jdk15on
#android.jetifier.blacklist=shadows,bcprov-jdk15on

# android.debug.obsoleteApi=true

6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Feb 28 14:26:07 CET 2019
#Sun Aug 21 19:58:31 EAT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
zipStoreBase=GRADLE_USER_HOME
Loading