API 'variant.getJavaCompiler()' has been replaced with 'variant.getJavaCompileProvider'

隨著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)好多文章都是說降級降級降級,能解決問題嗎?還不如點點看看源碼。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容