android-studio - Android Studio中如何让Gradle自动执行Task
ringa_lee
ringa_lee 2017-04-17 17:43:15
0
5
532

我在app中的build.gradle中定义了如下一个task:

task importHTML(type: Copy){
    println('start import htmls')
    from('../web')
    into('./app/src/main/assets')
    include('**/*')
}

我试过在右侧gradle标签下可以定义excute before Syncexcute after Sync等等。。
但是每次运行app的时候,都不会执行这个task,只有在SyncMake的时候才有用。

如何让app每次运行的时候都去执行这个task操作呢?

ringa_lee
ringa_lee

ringa_lee

reply all(5)
阿神

There are pre-run tasks in the running configuration. The default is gradle assembly. You can add your tasks before this task.

大家讲道理

The task of assembleDebug is executed by default when executing the app, so you only need

tasks.findByName('assembleDebug').doLast {
    println '++++++++ app last +++++++++'
}

Just add the above code to the build.

巴扎黑

task importHTML(type: Copy, dependOn:'assmbleDebug'), write different compilation stages in dependsOn according to your own needs

黄舟

To understand the operating mechanism of gradle, it is recommended to read "gradle for android"

Ty80

Recommend a blog post: Gradle basic knowledge points and common configurations

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template