如何使用android studio将复制任务运行到assets文件夹中 [英] How to run copy task with android studio into assets folder

查看:35
本文介绍了如何使用android studio将复制任务运行到assets文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已将以下内容添加到build.gradle"的末尾

So far I have added the following to the end of my "build.gradle"

task copyFiles(type: Copy)

copyFiles {
    description = 'Copies html5 files from the common library...'
    from '../../www'
    into 'assets/www'
    include('**/*')
}

现在我只需要一些关于如何在每次(之前)编译 android 源代码时执行此任务的帮助.我可以从命令行手动运行复制任务,但是当我在 android studio 中单击运行"时,我想让它运行.

Now I just need some help on how o make this task get executed everytime (before) compiling the android source. I can run the copy task manually from command line, but Id like to have it run when I click "run" in android studio.

在以下建议的帮助下,我添加了

With the help of suggestion below, I have added

clean.dependsOn copyFiles
clean.mustRunAfter copyFiles

有了这个添加,我可以通过重建 -> 运行来运行我的复制任务.总比没有好,但跳过重建步骤会很好.

And with this addition I can get my copy task to run by doing rebuild -> run. It's better than nothing but it would be nice to skip the rebuild step.

这是我在 android studio 中使用的整个 build.gradle.

Here is the whole build.gradle that im using with android studio.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}


apply plugin: 'android'

dependencies {
    compile files('/libs/acra-4.3.0.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src','libs']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }
}


task copyFiles(type: Copy)

copyFiles {
    description = 'Copies html5 files from the common library...'
    from '../../www'
    into 'assets/www'
    include('**/*')
}

clean.dependsOn copyFiles
clean.mustRunAfter copyFiles

推荐答案

这样我就可以在我的 android-gradle 构建系统中自定义复制文件资产

This way I do custom copying of file assets in my android-gradle build system

preBuild.dependsOn copyFiles

这篇关于如何使用android studio将复制任务运行到assets文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆