Where should I add e.g. Hilt Android and AndroidX Navigation Safe Args Gradle Plugins?
VincentJoshuaET opened this issue ยท 13 comments
Should I add them inside buildSrc folder?
plugins {
`kotlin-dsl`
}
repositories {
google()
mavenCentral()
}
dependencies {
implementation(group = "com.android.tools.build", name = "gradle", version = "7.0.1")
implementation(kotlin(module = "gradle-plugin", version = "1.5.30"))
implementation(group = "com.google.dagger", name = "hilt-android-gradle-plugin", version = "2.38.1")
implementation(group = "androidx.navigation", name = "navigation-safe-args-gradle-plugin", version = "2.3.5")
}
Thanks
Should I add them inside buildSrc folder?
AGP and Kotlin bump, you can do them if you wish.
As for hilt and safe-args, I won't add them for now.
I'm thinking about having a more opinionated branch where some small setup is also included.
Should I add them inside buildSrc folder?
AGP and Kotlin bump, you can do them if you wish.
As for hilt and safe-args, I won't add them for now.
I'm thinking about having a more opinionated branch where some small setup is also included.
Where do you suggest I add them? I can't use the new plugins block with them
I can't use the new plugins block with them
Why not?
I can't use the new plugins block with them
Why not?
https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
https://issuetracker.google.com/issues/64551265
Google's fault
Fixed for the AGP, but not for Navigation or Dagger Hilt
You can always overcome the lack of a plugin marker by specifying a custom resolution strategy. That's actually what this template was doing long before this issue was fixed for AGP:
kotlin-android-template/settings.gradle.kts
Lines 2 to 11 in d66f855
Does not seem to work for Hilt:
The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.
pluginManagement {
resolutionStrategy {
eachPlugin {
when (requested.id.id) {
"androidx.navigation.safeargs.kotlin" -> {
useModule("androidx.navigation:navigation-safe-args-gradle-plugin:${requested.version}")
}
"dagger.hilt.android.plugin" -> {
useModule("com.google.dagger:hilt-android-gradle-plugin:${requested.version}")
}
}
}
}
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.
You're missing the necessary dependencies in order to make Hilt work:
https://stackoverflow.com/a/62882856/3765748
I have those already. I dont have this issue if I use the code in my original post.
I have those already. I dont have this issue if I use the code in my original post.
Don't you mind sharing your project and/or your build.gradle[.kts]
files?
I cannot post the whole files, but here are the important ones.
I omitted the unrelated dependencies. This is working as expected. Once I implement the logic in pluginManagement and remove the Hilt and AndroidX Navigation Safe Args plugins from buildSrc
, and set their versions to the root build.gradle.kts
file, it fails.
build.gradle.kts:
plugins {
`android-app` apply false
`android-library` apply false
`kotlin-android` apply false
`kotlin-kapt` apply false
`kotlin-serialization` version PluginVersions.Kotlin apply false
`kotlin-parcelize` apply false
`hilt-android` apply false
`androidx-navigation-safe-args` apply false
}
allprojects {
group = ""
repositories {
google()
mavenCentral()
}
}
buildSrc/build.gradle.kts
plugins {
`kotlin-dsl`
}
repositories {
google()
mavenCentral()
}
dependencies {
implementation(group = "com.android.tools.build", name = "gradle", version = "7.0.2")
implementation(kotlin(module = "gradle-plugin", version = "1.5.30"))
implementation(group = "com.google.dagger", name = "hilt-android-gradle-plugin", version = "2.38.1")
implementation(group = "androidx.navigation", name = "navigation-safe-args-gradle-plugin", version = "2.3.5")
}
app/build.gradle.kts
plugins {
`android-app`
`kotlin-android`
`kotlin-kapt`
`kotlin-serialization`
`kotlin-parcelize`
`hilt-android`
`androidx-navigation-safe-args`
}
android {
compileSdk = Android.CompileSdkVersion
buildToolsVersion = Android.BuildToolsVersion
ndkVersion = Android.NdkVersion
defaultConfig {
applicationId = ""
minSdk = Android.MinSdk
targetSdk = Android.TargetSdk
versionCode = Android.VersionCode
versionName = Android.VersionName
}
signingConfigs {
register("release") {
enableV1Signing = true
enableV2Signing = true
enableV3Signing = true
enableV4Signing = true
}
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
}
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
ndk {
debugSymbolLevel = "FULL"
}
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
}
buildFeatures {
viewBinding = true
}
lint {
isCheckDependencies = true
}
}
dependencies {
implementation(libs.androidx.hilt.work)
kapt(libs.androidx.hilt.compiler)
implementation(libs.hilt.android)
kapt(libs.hilt.compiler)
}
kapt {
correctErrorTypes = true
}
hilt {
enableAggregatingTask = true
}
Seems like you're using precompiled script plugins right? How comes you have those implementation
dependencies inside buildSrc/build.gradle.kts
?
Originally I had those in the buildscript block in the root directory build.gradle.kts
, but I didn't know where to move them hence this post.
Has this been resolved?
Can someone give the solution on how to setup dagger hilt & navigation in this template?