I'm writing a Gradle plugin for Android, which uses new Transform API.
Unfortunately, I faced a problem with adding Android plugin as a dependency
to my plugin. A simplified Gradle configuration of my plugin looks like
this:
*plugin/build.gradle:*
apply plugin: "groovy"
dependencies {
compile gradleApi()
compile localGroovy()
compile "com.android.tools.build:gradle:1.4.0-beta2"
}
And that's a simplified configuration of an application project that uses
my Gradle plugin:
*application/build.gradle:*
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:1.4.0-beta2"
classpath "my-plugin:my-plugin:1.0.0"
}
}
apply plugin: "com.android.application"
apply plugin: "my-plugin"
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId 'com.myapplication'
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName version
}
}
With this configuration everything works fine but I also want my plugin to
work properly with projects that use previous versions of Android plugin.
So I tried to change Android plugin version in my application's
configuration file:
*application/build.gradle (with Android plugin 1.3.1):*
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:1.3.1"
classpath "my-plugin:my-plugin:1.0.0"
}
}
/* Everything else is the same. */
But in this case Android plugin 1.4.0-beta2 is still used. I believe it
happens because when Gradle resolves classpath dependencies, it prefers
1.4.0-beta2 over 1.3.1 so the whole project starts using version
1.4.0-beta2 of Android plugin.
I've also tried to add Android plugin as a runtime dependency but after
making this change my plugin stops compiling because of 'unable to resolve'
errors like this one:
Unable to resolve class com.android.build.gradle.api.BaseVariant @ line 19,
column 1.
import com.android.build.gradle.api.BaseVariant
Is there a way to build my plugin against the latest version of Android
plugin but at runtime use a version of Android plugin provided by the build
environment?
The same question on StackOverflow:
http://stackoverflow.com/q/32756983/170842
--
You received this message because you are subscribed to the Google Groups
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.