隨著AndroidX的遷移塘揣,gradle升級,Gradle難免有一些API已經(jīng)過時安吁。
我的環(huán)境
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 {
}
}
//----------------------------------------------------------------------------------------
//現(xiàn)在直接替換掉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();
}
唉。發(fā)現(xiàn)好多文章都是說降級降級降級脖咐,能解決問題嗎?還不如點點看看源碼汇歹。