Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: DefaultAndroidSourceDirectorySet to File using toString() method has been deprecated

I want to update the Gradle plug-in of an Android library project. The new version is 0.10.4. The Gradle wrapper is at 1.10. The following warning appears when I run ./gradlew install on the project.

Converting class com.android.build.gradle.internal.api. \
DefaultAndroidSourceDirectorySet to File using toString() method has 
been deprecated and is scheduled to be removed in Gradle 2.0. 
Please use java.io.File, java.lang.String, java.net.URL, or java.net.URI instead.

I am not sure but the marked lines should the cause:

// build.gradle

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java // <----
}

task androidJavadocsJar(type: Jar) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java // <----
}

How can I rewrite the code to get rid of the warning?

like image 924
JJD Avatar asked Jun 15 '14 00:06

JJD


1 Answers

android.sourceSets.main.java doesn't have the type you expect. You're passing it to something that expects a File[], but it actually has the type com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet. If you look at the API for Android sourceSets at you'll find that there's a sourceDirs method that returns what you want. So set up your tasks like this:

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
}
like image 101
Scott Barta Avatar answered Oct 05 '22 19:10

Scott Barta