Hello, I am discovering the new `plugins` declarat...
# gradle
n
Hello, I am discovering the new
plugins
declaration. Applying below in the root Gradle file
Copy code
plugins {
    id("com.android.application") version "7.2" apply false
    id("com.android.library") version "7.2" apply false
}
But I also need to apply
Gradle
plugin in
buildSrc
so I have this in there
Copy code
implementation("com.android.tools.build:gradle:7.2.0")
but then IDE throws an exception
Error resolving plugin [id: ‘com.android.application’, version: ‘7.2.0’, apply: false]
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
How do I have the same plugin works for the both places?
v
Just delete it in root build file. As you have
apply false
it is not applied but only added to class path anyway, so no point in doing it again. Alternatively you could switch from
buildSrc
to composite build. I think with an included build the compatibility check should work.
n
Thanks, but I apply them in submodules. Shouldn't I keep them in the root file?
v
Read my message again
n
Sorry struggling to understand how it works 🙂 Deleted it in the root build file but now
app
module doesn’t compile
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun CompileOptions.debug(vararg debugArgs: Pair<String, Any?>): CompileOptions defined in org.gradle.kotlin.dsl
I use
debug
accessor for build type
Copy code
buildTypes {
    debug {
        ...
v
I have no idea about Android shenenigans, sorry
👍 1
a
Change
implementation
to
compileOnly
in buildSrc. Also you can use
com.android.tools.build:gradle-api
instead of
com.android.tools.build:gradle
.
n
Thanks @Albert Chang it almost worked! But I am now getting below. Do you have any assumption?
Copy code
A problem occurred evaluating script.
> com/android/build/gradle/AppPlugin
Caused by: java.lang.NoClassDefFoundError: com/android/build/gradle/AppPlugin
I need
AppPlugin
in one of classes in
buildSrc
Copy code
import com.android.build.gradle.AppPlugin
I changed
implementation
to
compileOnly
for
com.android.tools.build:gradle
a
You don't need the plugin class. You can just use the id (
com.android.application
).
1077 Views