简体   繁体   中英

Android Gradle SourceSet Resources not copying base dir

I'm currently working on automating an android build via gradle but my build.gradle file isn't copying the entire res/ or assets/ dirs into my produced apk.

Clarification: The contents of the needed res/ & assets/ dirs are copied into the apk, but the actual res/ and assets/ dirs are nowhere to be found. For this automation to match the manual process in place, I need a seemless transition from manual build process to automated build process. (no difference in produced apk)

I know it has to be how I'm addressing the sourceSets and resources, but I can't find any direction/advice on what I'm doing wrong.

Here's my build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src','../res','../assets']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

    }

    defaultConfig {
        applicationId "***************"
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            zipAlignEnabled true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            zipAlignEnabled true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

My directory structure(loosely represented):

AppBase/
+res/
+assets/
-gradle files
+AndroidApp
    +src/
    -gradle files

I think you should be doing something like this, though, I am not too sure about the relative paths.

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res','../res']
        assets.srcDirs = ['assets', '../assets']
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM