简体   繁体   English

Gradle中的自定义旧Android项目结构

[英]Custom old Android project structure in Gradle

We have a project structure of the form 我们有一个表单的项目结构
src SRC
src_flavor1 src_flavor1
src_flavor2 src_flavor2
res 水库
res_flavor1 res_flavor1
res_flavor2 res_flavor2

The core logic and resources are placed in src and res folder resp. 核心逻辑和资源放在src和res文件夹中。 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. 我试图用build.gradle文件定义这个项目结构,但havnt发现任何成功。 Also Im trying to use the prductFlavor tags to create simultaneous builds of the two flavors but no success. 我也试图使用prductFlavor标签创建两种口味的同时构建,但没有成功。 Doing all this within the Android Studio latest build 在Android Studio最新版本中完成所有这些操作

Assuming you have define your flavors like this: 假设你已经定义了这样的口味:

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

You can modify the sourceSets of each flavor 您可以修改每种风格的sourceSets

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. 最后一点:根据我的经验,Android-Studio还不是很稳定, 而且 还没有关于gradle < - > IDE同步的全功能。 So I strongly suggest you to always test your gradle scripts from the command line. 所以我强烈建议您始终从命令行测试您的gradle脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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