Skip to content

Commit

Permalink
Modernize build (Java 8 compatiblity, fix build warnings, remove dead…
Browse files Browse the repository at this point in the history
… code) (#2297)
  • Loading branch information
mateuszkwiecinski committed Jun 13, 2023
1 parent fd3845d commit cc8fbca
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Build app
run: ./gradlew snapshot-tests:assembleDebug snapshot-tests:assembleDebugAndroidTest --no-daemon
- name: Run tests
uses: emulator-wtf/run-tests@master
uses: emulator-wtf/run-tests@v0.9.6
with:
api-token: ${{ env.EW_API_TOKEN }}
app: snapshot-tests/build/outputs/apk/debug/snapshot-tests-debug.apk
Expand Down
51 changes: 33 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
import org.ajoberstar.grgit.Grgit

buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath libs.grgit.plugin
classpath libs.android.gradle.plugin
classpath libs.kotlin.gradle.plugin
classpath libs.gradle.maven.publish.plugin
classpath libs.dokka.gradle.plugin
}
}
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'net.ltgt.errorprone' apply false
id "com.google.devtools.ksp" apply false
id "org.ajoberstar.grgit" apply false
id "com.android.library" apply false
id "org.jetbrains.kotlin.jvm" apply false
id "com.vanniktech.maven.publish" apply false
id "org.jetbrains.dokka" apply false
}

allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
def compileJavaVersion = JavaVersion.VERSION_17
def targetJavaVersion = JavaVersion.VERSION_1_8
pluginManager.withPlugin("java") {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(compileJavaVersion.majorVersion))
}
}
tasks.withType(JavaCompile).configureEach {
options.release.set(targetJavaVersion.majorVersion)
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.android") {
kotlin {
jvmToolchain(compileJavaVersion.majorVersion.toInteger())
}
tasks.withType(KotlinCompile).configureEach {
kotlinOptions.jvmTarget = targetJavaVersion.toString()
}
}
["com.android.library", "com.android.application"].forEach { androidPlugin ->
pluginManager.withPlugin(androidPlugin) {
android {
sourceCompatibility targetJavaVersion
targetCompatibility targetJavaVersion
}
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Generated by $ ./gradlew refreshVersionsCatalog

[libraries]
android-gradle-plugin = "com.android.tools.build:gradle:_"

androidx-activity-compose = "androidx.activity:activity-compose:_"
androidx-appcompat = "androidx.appcompat:appcompat:_"
androidx-browser = "androidx.browser:browser:_"
Expand Down Expand Up @@ -34,21 +36,18 @@ compose-ui-test-manifest = "androidx.compose.ui:ui-test-manifest:_"
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
dagger = "com.google.dagger:dagger:_"
dagger-compiler = "com.google.dagger:dagger-compiler:_"
dokka-gradle-plugin = "org.jetbrains.dokka:dokka-gradle-plugin:_"
epoxy = "com.airbnb.android:epoxy:_"
epoxy-processor = "com.airbnb.android:epoxy-processor:_"
errorprone-core = "com.google.errorprone:error_prone_core:_"
errorprone-javac = "com.google.errorprone:javac:_"
glide = "com.github.bumptech.glide:glide:_"
google-material = "com.google.android.material:material:_"
gradle-maven-publish-plugin = "com.vanniktech:gradle-maven-publish-plugin:_"
grgit-plugin = "org.ajoberstar.grgit:grgit-gradle:_"
gson = "com.google.code.gson:gson:_"
javac = "com.google.errorprone:javac:_"
jjwt = "io.jsonwebtoken:jjwt:_"
junit4 = "junit:junit:_"
kotlin-annotation-processing-gradle = "org.jetbrains.kotlin:kotlin-annotation-processing-gradle:_"
kotlin-gradle-plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:_"
kotlin-parcelize-compiler = "org.jetbrains.kotlin:kotlin-parcelize-compiler:_"
kotlin-parcelize-runtime = "org.jetbrains.kotlin:kotlin-parcelize-runtime:_"
kotlinx-coroutines-android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:_"
Expand Down
9 changes: 1 addition & 8 deletions issue-repro-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import static de.fayard.refreshVersions.core.Versions.versionFor

plugins {
id 'com.android.application'
id "kotlin-android"
id "org.jetbrains.kotlin.android"
}

android {
Expand All @@ -15,13 +15,6 @@ android {
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
buildFeatures {
compose true
}
Expand Down
3 changes: 1 addition & 2 deletions issue-repro-compose/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.airbnb.lottie.issues.compose">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:icon="@mipmap/ic_launcher"
Expand Down
6 changes: 1 addition & 5 deletions issue-repro/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
}

android {
Expand All @@ -13,10 +13,6 @@ android {
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
buildFeatures {
viewBinding true
}
Expand Down
7 changes: 1 addition & 6 deletions lottie-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import static de.fayard.refreshVersions.core.Versions.versionFor

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
id 'com.vanniktech.maven.publish'
}

Expand All @@ -20,12 +20,7 @@ android {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
freeCompilerArgs += [
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
]
Expand Down
24 changes: 1 addition & 23 deletions lottie/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ android {
textReport true
textOutput 'stdout'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
testOptions {
unitTests {
includeAndroidResources = true
Expand Down Expand Up @@ -54,25 +50,7 @@ dependencies {
androidTestImplementation libs.androidx.test.espresso
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set('sources')
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
configurations.implementation.setCanBeResolved(true)
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.implementation
}

tasks.withType(Javadoc) {
// This started failing with the following when upgrading to AGP 7 and JDK 11.
// TODO: investigate why once AGP 7 is stable.
// javadoc: error - The code being documented uses modules but the packages defined in https://developer.android.com/reference/ are in the unnamed module.
failOnError false
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
// remove the if condition if you want to run NullAway on test code
if (!name.toLowerCase().contains("test")) {
options.errorprone {
Expand Down
2 changes: 1 addition & 1 deletion lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ public <T> void addValueCallback(
*/
public <T> void addValueCallback(KeyPath keyPath, T property,
final SimpleLottieValueCallback<T> callback) {
addValueCallback(keyPath, property, new LottieValueCallback<>() {
addValueCallback(keyPath, property, new LottieValueCallback<T>() {
@Override
public T getValue(LottieFrameInfo<T> frameInfo) {
return callback.getValue(frameInfo);
Expand Down
6 changes: 0 additions & 6 deletions sample-compose-benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ android {
namespace 'com.airbnb.lottie.sample.compose.benchmark'
compileSdk 33

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import kotlin.time.ExperimentalTime

Expand Down Expand Up @@ -48,7 +49,6 @@ class LottieBaselineBenchmark {
benchmark(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require))
}

@OptIn(ExperimentalTime::class)
fun benchmark(compilationMode: CompilationMode) {
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
Expand Down Expand Up @@ -78,25 +78,22 @@ class LottieBaselineBenchmark {
}
}

@OptIn(ExperimentalTime::class)
private fun UiScrollable.waitUntilReady() {
this.waitUntil {
// We know that there are at least 9 children
childCount >= EXPECTED_ITEM_INDEX_COUNT
}
}

@OptIn(ExperimentalTime::class)
private fun UiObject.clickAndWait(maxWaitTime: Duration = Duration.seconds(5)) {
private fun UiObject.clickAndWait(maxWaitTime: Duration = 5.seconds) {
val maxWaitTimeMs = maxWaitTime.toLong(DurationUnit.MILLISECONDS)
click()
device.waitForIdle(maxWaitTimeMs)
Thread.sleep(maxWaitTimeMs)
device.pressBack()
}

@OptIn(ExperimentalTime::class)
private fun <T> T.waitUntil(maxWaitTime: Duration = Duration.seconds(5), condition: (T) -> Boolean) {
private fun <T> T.waitUntil(maxWaitTime: Duration = 5.seconds, condition: (T) -> Boolean) {
var waitTime = 0L
val maxWaitTimeMs = maxWaitTime.toLong(DurationUnit.MILLISECONDS)
val incrementalDelay = 150L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import kotlin.time.ExperimentalTime

Expand All @@ -36,7 +37,6 @@ class LottieBaselineProfiles {
}

@Test
@OptIn(ExperimentalTime::class)
fun baselineProfiles() {
baselineProfileRule.collectBaselineProfile(
packageName = PACKAGE_NAME,
Expand All @@ -59,25 +59,22 @@ class LottieBaselineProfiles {
}
}

@OptIn(ExperimentalTime::class)
private fun UiScrollable.waitUntilReady() {
this.waitUntil {
// We know that there are at least 9 children
childCount >= EXPECTED_ITEM_INDEX_COUNT
}
}

@OptIn(ExperimentalTime::class)
private fun UiObject.clickAndWait(maxWaitTime: Duration = Duration.seconds(5)) {
private fun UiObject.clickAndWait(maxWaitTime: Duration = 5.seconds) {
val maxWaitTimeMs = maxWaitTime.toLong(DurationUnit.MILLISECONDS)
click()
device.waitForIdle(maxWaitTimeMs)
Thread.sleep(maxWaitTimeMs)
device.pressBack()
}

@OptIn(ExperimentalTime::class)
private fun <T> T.waitUntil(maxWaitTime: Duration = Duration.seconds(5), condition: (T) -> Boolean) {
private fun <T> T.waitUntil(maxWaitTime: Duration = 5.seconds, condition: (T) -> Boolean) {
var waitTime = 0L
val maxWaitTimeMs = maxWaitTime.toLong(DurationUnit.MILLISECONDS)
val incrementalDelay = 150L
Expand Down
7 changes: 1 addition & 6 deletions sample-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import static de.fayard.refreshVersions.core.Versions.versionFor

plugins {
id 'com.android.application'
id "kotlin-android"
id "org.jetbrains.kotlin.android"
id 'kotlin-kapt'
}

Expand All @@ -24,12 +24,7 @@ android {
debuggable false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
freeCompilerArgs += [
"-Xallow-jvm-ir-dependencies",
"-Xskip-prerelease-check",
Expand Down
15 changes: 5 additions & 10 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import static de.fayard.refreshVersions.core.Versions.versionFor

plugins {
id 'com.android.application'
id "kotlin-android"
id 'kotlin-parcelize'
id "org.jetbrains.kotlin.android"
id 'org.jetbrains.kotlin.plugin.parcelize'
id 'com.google.devtools.ksp'
}

Expand Down Expand Up @@ -40,17 +42,9 @@ android {
textOutput 'stdout'
baseline file("lint-baseline.xml")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
freeCompilerArgs += ["-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"]
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
Expand All @@ -66,6 +60,7 @@ dependencies {
implementation libs.androidx.appcompat
implementation libs.androidx.recyclerview
implementation libs.androidx.paging.runtime.ktx
implementation libs.androidx.viewmodel.ktx
implementation libs.androidx.cardview
implementation libs.androidx.core.ktx
implementation libs.androidx.constraintlayout
Expand Down
Loading

0 comments on commit cc8fbca

Please sign in to comment.