sver
sver

Reputation: 942

android.compileSdkVersion is missing while using a custom plugin task

I have a task to create javadocs :

Task tCreateJavadocs = addTask(project, 'createJavadocs', Javadoc.class)
tCreateJavadocs.configure{
source = android.sourceSets.main.java.srcDirs
   classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}

Now, I have a custom plugin where I move all my tasks and create a library as a result so I can apply the library to all projects. So, I want to move this task to custom plugin project as well. I write the task in custom plugin project like below:

Task tCreateJavadocs = addTask(project, 'createJavadocs', Javadoc.class)
tCreateJavadocs.configure{
source = project.android.sourceSets.main.java.srcDirs
   classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator))
failOnError false
}

When I compile this with an Android Studio project, I get error 'Cause: android.compileSdkVersion is missing'.

Upvotes: 0

Views: 422

Answers (3)

sver
sver

Reputation: 942

If I write my task definition inside project.afterEvaluate closure, the issue is resolved.

Upvotes: 0

sver
sver

Reputation: 942

As suggested in the answer above, I added these:

project.android.compileSdkVersion = 'android-23'
project.android.buildToolsVersion = '23.0.1'

and project is building

Upvotes: 1

Vampire
Vampire

Reputation: 38734

I'd say you try to use stuff that is not yet set.
Either apply you plugin later, after you've set the compileSdkVersion, or maybe delay configuration of your task with afterEvaluate, so that other configurations are already done, or if possible only delay evaluation of the problematic value with a closure.

Last option is probably the best one. Find out which line is problematic and look whether you can give it a Closure instead, as those are usually evaluated lazily.

Upvotes: 2

Related Questions