Closed ashar-7 closed 2 years ago
Its as if the Android Gradle Plugin was not being applied.
Have you try adding it in your buildscript closure?
buildscript {
// ...
dependencies {
classpath "com.android.tools.build:gradle:$agp_version" // <--- HERE
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
I got this issue when update 2.37 to 2.38.1 Any idea about this?
Same here, using:
com.android.tools.build:gradle:7.1.0-alpha02
com.google.dagger:hilt-android-gradle-plugin:2.38.1
gradle-wrapper: gradle-7.1.1-bin.zip
An exception occurred applying plugin request [id: 'dagger.hilt.android.plugin']
> Failed to apply plugin 'dagger.hilt.android.plugin'.
> com.android.build.api.extension.AndroidComponentsExtension.androidTests(com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1)
Android Studio Arctic Fox | 2020.3.1
Build #AI-203.7717.56.2031.7583922, built on July 26, 2021
Runtime version: 11.0.10+0-b96-7281165 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.4
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 4
Registry: ide.windowSystem.autoShowProcessPopup=true, external.system.auto.import.disabled=true, debugger.watches.in.variables=false, ide.images.show.chessboard=true
Non-Bundled Plugins: com.intellij.marketplace, mobi.hsz.idea.gitignore, com.atlassian.bitbucket.references, com.thoughtworks.gauge, org.jetbrains.kotlin, com.google.mad-scorecard, com.jetbrains.kmm, com.squareup.sqldelight
@GuilhE can you try bumping your AGP version? 7.1.0-alpha05 is available. Its really hard to keep track of the compatibility changes between the alpha versions of AGP but once stable we guarantee to support them.
@GuilhE can you try bumping your AGP version? 7.1.0-alpha05 is available. Its really hard to keep track of the compatibility changes between the alpha versions of AGP but once stable we guarantee to support them.
@danysantiago completely understandable 👍🏼 , and yes, with 7.1.0-alpha05
it's working.
I created a new project with Android Studio Bumblebee Canary 5 and by default the plugins were defined in settings.gradle
. I'm not familiar with that approach but if I add the AGP in my build.gradle
, I get an error:
An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.android', version: '1.5.10']
> Failed to apply plugin 'org.jetbrains.kotlin.android'.
> Extension with name 'android' does not exist. Currently registered extension names: [ext, kotlin, kotlinTestRegistry]
same error , same setup, using 7.1.0-alpha05, no docs on using gradle settings like in the project template, can't add dagger hilt plugin
edit:
i was able to resolve it by adding
resolutionStrategy {
eachPlugin {
if( requested.id.id == 'dagger.hilt.android.plugin') {
useModule("com.google.dagger:hilt-android-gradle-plugin:2.38.1")
}
}
}
to pluginManagement in settings.gradle i'm not 100% sure yet everything works as it should but the error disappeared in any case.
Per Gradle's documentation: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_management in order to specify the coordinates of a plugin you need to use the resolutionStrategy
DSL.
Like this:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
plugins {
id 'com.android.application' version '7.1.0-alpha06'
id 'com.android.library' version '7.1.0-alpha06'
// No need to define the Hilt plugin here.
}
resolutionStrategy {
eachPlugin {
// Use `resolutionStrategy` to define the Hilt plugin and its coordinate
if (requested.id.id == 'dagger.hilt.android.plugin') {
useModule('com.google.dagger:hilt-android-gradle-plugin:2.38.1')
}
}
}
}
This is needed for external plugins without a plugin marker or that are not uploaded into Gradle's Plugin Portal.
In order to avoid using resolutionStrategy
we need to publish a plugin marker (https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers). I'm not super familiar with it but I'll try to make one so users don't need to use the resolution strategy.
I'm not super familiar with it but I'll try to make one so users don't need to use the resolution strategy.
Hi, any updates on this?
Also interested
@danysantiago Is it fixed for all versions or only for the next release? I think the issue should be reopened until the next release is published.
The fix will be in the next release, if you would like to try it you can use the SNAPSHOT releases.
// In settings.gradle.kts
pluginManagement {
repositories {
// Add Sonatype snapshot repo
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
}
}
// In the build.gradle where the plugin is applied (notice the id is different)
plugins {
id("com.google.dagger.hilt.android") version "HEAD-SNAPSHOT"
}
Tried HEAD-SNAPSHOT
and I get following error when syncing Gradle project:
Could not apply requested plugin [id: 'com.google.dagger.hilt.android', version: 'HEAD-SNAPSHOT'] as it does not provide a plugin with id 'com.google.dagger.hilt.android'. This is caused by an incorrect plugin implementation. Please contact the plugin author(s).
> Plugin with id 'com.google.dagger.hilt.android' not found.
@plnice can you double-check your configuration? I tried it in this sample project and it worked fine for me.
Oh, now it started to work for me 🙂 Maybe I had some previous version cached, or something. Sorry for bothering you.
For me, pasting classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39'
into the dependencies object in the app module solved this issue. Simple solution instead of defining the plugin on app-level.
I just updated to Android Studio Bumblebee Canary 4, created a new project, and getting this error when trying to add hilt plugin:
I get this with both 2.37 and 2.38. Not sure if it's an Android Studio issue build.gradle:
app/build.gradle:
settings.gradle: