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

风格不统一 提交于 2019-12-07 04:38:28

问题


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?


回答1:


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
}


来源:https://stackoverflow.com/questions/24225557/gradle-defaultandroidsourcedirectoryset-to-file-using-tostring-method-has-bee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!