随着AndroidX的迁移,gradle升级,Gradle难免有一些API已经过时。
我的环境
Android Studio 3.5.1
gradle 5.4.1
gradle build-tools 3.5.3
aspectJ 1.8.13
//之前可能是这样的
android.applicationVariants.all { variant ->
JavaCompile javaCompile = variant.getJavaCompiler()
javaCompile.doLast {
}
}
//----------------------------------------------------------------------------------------
//现在直接替换掉API getJavaCompiler --> getJavaCompileProvider
// 返回值为 TaskProvider,直接放进去一个Action即可
android.applicationVariants.all { variant ->
TaskProvider<JavaCompile> taskProvider = variant.getJavaCompileProvider()
taskProvider.configure { javaCompile ->
javaCompile.doLast {
}
}
}
BaseVariant
/**
* Returns the Java Compilation task
*
* @deprecated Use {@link #getJavaCompileProvider()}
*/
@NonNull
@Deprecated
JavaCompile getJavaCompile();
/**
* Returns the {@link TaskProvider} for the Java Compilation task
*
* <p>Prefer this to {@link #getJavaCompile()} as it triggers eager configuration of the task.
*/
@NonNull
TaskProvider<JavaCompile> getJavaCompileProvider();
TaskProvider
**
* Providers a task of the given type.
*
* @param <T> Task type
* @since 4.8
*/
public interface TaskProvider<T extends Task> extends NamedDomainObjectProvider<T> {
/**
* Configures the task with the given action. Actions are run in the order added.
*
* @param action A {@link Action} that can configure the task when required.
* @since 4.8
*/
void configure(Action<? super T> action);
/**
* The task name referenced by this provider.
* <p>
* Must be constant for the life of the object.
*
* @return The task name. Never null.
* @since 4.9
*/
String getName();
}
唉。发现好多文章都是说降级降级降级,能解决问题吗?还不如点点看看源码。