search

Home  >  Q&A  >  body text

android-studio - Android Studio中如何让Gradle自动执行Task

我在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_leeringa_lee2772 days ago540

reply all(5)I'll reply

  • 阿神

    阿神2017-04-17 17:45:15

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:45:15

    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.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:45:15

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

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:45:15

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:45:15

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

    reply
    0
  • Cancelreply