Custom old Android project structure in Gradle

帅比萌擦擦* 提交于 2019-12-13 02:38:16

问题


We have a project structure of the form
src
src_flavor1
src_flavor2
res
res_flavor1
res_flavor2

The core logic and resources are placed in src and res folder resp. The flavoured folders only contains few files which separate the two flavors.
Im trying to define this project structure withing the build.gradle file but havnt found any success. Also Im trying to use the prductFlavor tags to create simultaneous builds of the two flavors but no success. Doing all this within the Android Studio latest build


回答1:


Assuming you have define your flavors like this:

productFlavors {
    flavor1 {
        ...
    }
    flavor2 {
        ...
    }
}

You can modify the sourceSets of each flavor

android.sourceSets.flavor1 {
    java.srcDirs = ['src_flavor1']
    resources.srcDir = ['res_flavor1']
}

android.sourceSets.flavor2 {
    java.srcDirs = ['src_flavor2']
    resources.srcDir = ['res_flavor2']
}

I hope this help... (don't hesitate to add more details about your problems since it will help us to help you)

Last remark: according my experience, Android-Studio is not very stable yet and not full-featured yet regarding gradle<-->IDE sync. So I strongly suggest you to always test your gradle scripts from the command line.



来源:https://stackoverflow.com/questions/17022773/custom-old-android-project-structure-in-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!