Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
950 views
in Technique[技术] by (71.8m points)

gradle - How to run copy task with android studio into assets folder

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('**/*')
}

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.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

preBuild.dependsOn copyFiles

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...