mirror of
https://github.com/tuskyapp/Tusky
synced 2024-12-12 17:17:09 +01:00
dc4ca06551
Hilt is an annotation processor built on top of Dagger which allows to remove all the Android dependency injection boilerplate code (currently around 900 lines) by writing it for us. Hilt can use KSP instead of Kapt so Kapt can be completely removed from the project. Kapt is slow, deprecated and has a few compatibility issues. Removing Kapt will improve build times since no Java stubs have to be generated for Kotlin classes anymore (Note that KSP also processes annotations in Java classes so it can completely replace Kapt). - Remove all modules related to manual dependency injection configuration. - Rename `AppModule` to `StorageModule` since it now only contains configuration to retrieve the DataBase and SharedPreferences. - Annotate all entry points (Activities, Fragments, BroadcastReceivers and Services) with `@AndroidEntryPoint`. - Annotate all injected ViewModels with `@HiltViewModel` and replace the custom ViewModel Factory with the default one (which integrates with the one generated by Hilt). - Add a public field to allow overriding the default ViewModelProvider.Factory in `BaseActivity` in tests. - Annotate tested Activities with `@OptionalInject` since Activity tests currently rely on the Activities not being injected automatically. - Annotate injected `Context` arguments with `@ApplicationContext`. Hilt provides the `Context` binding automatically but requires to specify if the Application or Activity Context is wanted. - Add WorkManager Hilt integration so all Workers are injected by Hilt automatically using `HiltWorkerFactory`. - Lazily initialize WorkManager in `TuskyApplication`. - Remove Kapt and Kapt workarounds. - ~~Remove toolchain configuration for Java 21. Toolchains force the Java bytecode to match the JDK version used to build the project, and apparently Hilt doesn't run inside the toolchain so cannot process the source code if the JDK version of the toolchain is higher than the JDK used to run Gradle. [And configuring a toolchain for an older Java version causes other issues](https://jakewharton.com/gradle-toolchains-are-rarely-a-good-idea/). **Removing toolchains configuration doesn't prevent the project from being built using JDK 21** or more recent versions but allows to build the project using older JDKs as well.~~ Added a fix to allow Hilt to properly use the JDK toolchain. - ~~Set the Java and Kotlin bytecode target to Java 17. The standard bytecode target for Android projects is usually Java 8 or 11 (any higher version doesn't provide any benefit but may cause compatibility issues). However, since the app currently uses a library built against Java 17 bytecode (`networkresult-calladapter`), it needs to target at least Java 17 bytecode as well.~~ - Update the Dagger 2 URL in the licenses screen. Hilt is part of Dagger 2 so the label wasn't changed.
195 lines
5.6 KiB
Groovy
195 lines
5.6 KiB
Groovy
plugins {
|
|
alias(libs.plugins.android.application)
|
|
alias(libs.plugins.google.ksp)
|
|
alias(libs.plugins.hilt.android)
|
|
alias(libs.plugins.kotlin.android)
|
|
alias(libs.plugins.kotlin.parcelize)
|
|
}
|
|
|
|
apply from: 'getGitSha.gradle'
|
|
|
|
final def gitSha = ext.getGitSha()
|
|
|
|
// The app name
|
|
final def APP_NAME = "Tusky"
|
|
// The application id. Must be unique, e.g. based on your domain
|
|
final def APP_ID = "com.keylesspalace.tusky"
|
|
// url of a custom app logo. Recommended size at least 600x600. Keep empty to use the Tusky elephant friend.
|
|
final def CUSTOM_LOGO_URL = ""
|
|
// e.g. mastodon.social. Keep empty to not suggest any instance on the signup screen
|
|
final def CUSTOM_INSTANCE = ""
|
|
// link to your support account. Will be linked on the about page when not empty.
|
|
final def SUPPORT_ACCOUNT_URL = "https://mastodon.social/@Tusky"
|
|
|
|
android {
|
|
compileSdk 34
|
|
namespace "com.keylesspalace.tusky"
|
|
defaultConfig {
|
|
applicationId APP_ID
|
|
namespace "com.keylesspalace.tusky"
|
|
minSdk 24
|
|
targetSdk 34
|
|
versionCode 121
|
|
versionName "25.2"
|
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
vectorDrawables.useSupportLibrary = true
|
|
|
|
resValue "string", "app_name", APP_NAME
|
|
|
|
buildConfigField("String", "CUSTOM_LOGO_URL", "\"$CUSTOM_LOGO_URL\"")
|
|
buildConfigField("String", "CUSTOM_INSTANCE", "\"$CUSTOM_INSTANCE\"")
|
|
buildConfigField("String", "SUPPORT_ACCOUNT_URL", "\"$SUPPORT_ACCOUNT_URL\"")
|
|
}
|
|
buildTypes {
|
|
debug {
|
|
isDefault true
|
|
}
|
|
release {
|
|
minifyEnabled true
|
|
shrinkResources true
|
|
proguardFiles 'proguard-rules.pro'
|
|
|
|
kotlinOptions {
|
|
freeCompilerArgs = [
|
|
"-Xno-param-assertions",
|
|
"-Xno-call-assertions",
|
|
"-Xno-receiver-assertions"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
flavorDimensions += "color"
|
|
productFlavors {
|
|
blue {}
|
|
green {
|
|
resValue "string", "app_name", APP_NAME + " Test"
|
|
applicationIdSuffix ".test"
|
|
versionNameSuffix "-" + gitSha
|
|
isDefault true
|
|
}
|
|
}
|
|
|
|
lint {
|
|
lintConfig file("lint.xml")
|
|
// Regenerate by deleting the file and running `./gradlew app:lintGreenDebug`
|
|
baseline = file("lint-baseline.xml")
|
|
}
|
|
|
|
buildFeatures {
|
|
buildConfig true
|
|
resValues true
|
|
viewBinding true
|
|
}
|
|
|
|
testOptions {
|
|
unitTests {
|
|
returnDefaultValues = true
|
|
includeAndroidResources = true
|
|
}
|
|
unitTests.all {
|
|
systemProperty 'robolectric.logging.enabled', 'true'
|
|
systemProperty 'robolectric.lazyload', 'ON'
|
|
}
|
|
}
|
|
sourceSets {
|
|
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
|
|
}
|
|
|
|
// Exclude unneeded files added by libraries
|
|
packagingOptions.resources.excludes += [
|
|
'LICENSE_OFL',
|
|
'LICENSE_UNICODE',
|
|
]
|
|
|
|
bundle {
|
|
language {
|
|
// bundle all languages in every apk so the dynamic language switching works
|
|
enableSplit = false
|
|
}
|
|
}
|
|
dependenciesInfo {
|
|
includeInApk false
|
|
includeInBundle false
|
|
}
|
|
applicationVariants.configureEach { variant ->
|
|
variant.outputs.configureEach {
|
|
outputFileName = "Tusky_${variant.versionName}_${variant.versionCode}_${gitSha}_" +
|
|
"${variant.flavorName}_${buildType.name}.apk"
|
|
}
|
|
}
|
|
}
|
|
|
|
ksp {
|
|
arg("room.schemaLocation", "$projectDir/schemas")
|
|
arg("room.generateKotlin", "true")
|
|
arg("room.incremental", "true")
|
|
}
|
|
|
|
configurations {
|
|
// JNI-only libraries don't play nicely with Robolectric
|
|
// see https://github.com/tuskyapp/Tusky/pull/3367
|
|
testImplementation.exclude group: "org.conscrypt", module: "conscrypt-android"
|
|
testRuntime.exclude group: "org.conscrypt", module: "conscrypt-android"
|
|
}
|
|
|
|
// library versions are in PROJECT_ROOT/gradle/libs.versions.toml
|
|
dependencies {
|
|
implementation libs.kotlinx.coroutines.android
|
|
|
|
implementation libs.bundles.androidx
|
|
implementation libs.bundles.room
|
|
ksp libs.androidx.room.compiler
|
|
|
|
implementation libs.android.material
|
|
|
|
implementation libs.bundles.moshi
|
|
ksp libs.moshi.kotlin.codegen
|
|
|
|
implementation libs.bundles.retrofit
|
|
implementation libs.networkresult.calladapter
|
|
|
|
implementation libs.bundles.okhttp
|
|
implementation libs.okio
|
|
|
|
implementation libs.conscrypt.android
|
|
|
|
implementation libs.bundles.glide
|
|
ksp libs.glide.compiler
|
|
|
|
implementation libs.hilt.android
|
|
ksp libs.hilt.compiler
|
|
implementation libs.androidx.hilt.work
|
|
ksp libs.androidx.hilt.compiler
|
|
|
|
implementation libs.sparkbutton
|
|
|
|
implementation libs.touchimageview
|
|
|
|
implementation libs.bundles.material.drawer
|
|
implementation libs.material.typeface
|
|
|
|
implementation libs.image.cropper
|
|
|
|
implementation libs.bundles.filemojicompat
|
|
|
|
implementation libs.bouncycastle
|
|
implementation libs.unified.push
|
|
|
|
implementation libs.bundles.xmldiff
|
|
|
|
testImplementation libs.androidx.test.junit
|
|
testImplementation libs.robolectric
|
|
testImplementation libs.bundles.mockito
|
|
testImplementation libs.mockwebserver
|
|
testImplementation libs.androidx.core.testing
|
|
testImplementation libs.kotlinx.coroutines.test
|
|
testImplementation libs.androidx.work.testing
|
|
testImplementation libs.truth
|
|
testImplementation libs.turbine
|
|
|
|
androidTestImplementation libs.espresso.core
|
|
androidTestImplementation libs.androidx.room.testing
|
|
androidTestImplementation libs.androidx.test.junit
|
|
}
|