简体   繁体   English

Android Gradle编译项目的特定风格

[英]Android Gradle compile project's specific flavor

I am having troubles with product flavors, my project contains library named Core and application named ie App . 我在产品口味方面遇到麻烦,我的项目包含名为Core的库和名为ie App的应用程序

In build.gradle file of my App module I am compiling this library project like this: 在我的App模块的build.gradle文件中,我正在像下面这样编译该库项目:

 dependencies {
   compile project(':Core')
 }

This is working fine but issue comes when I want to introduce specific product flavors in both my library project " Core " and my application module " App ". 这可以正常工作,但是当我想在我的库项目“ Core ”和我的应用程序模块“ App ”中引入特定的产品风格时,就会出现问题。

In Core buid.gradle file I have defined one product flavor : 在Core buid.gradle文件中,我定义了一种产品口味:

productFlavors {
    flavor1 {

    }
}

sourceSets.flavor1 {

        java {
            exclude '**/SomeFilePath/*'
        }
}

Now once I've added this new flavor to my Core library, I want to change build.gradle in my App application module so that I can compile only this productFlavor named flavor1 from my Core project. 现在,将这种新的风味添加到我的Core库后,我想在我的App应用程序模块中更改build.gradle,以便我只能从我的Core项目中编译名为product1的productFlavor。

I tried something like this, but it fails with error "No configuration with named "flavor1Release" found." 我尝试过类似的操作,但失败,并显示错误“找不到名为“ flavor1Release”的配置”。

dependencies {
  compile project(path: ':Core', configuration: 'flavor1Release')
}

Just to sum it all, I want to have multiple flavors in my App application module and each of this flavors would compile different flavor from my Core library project. 综上所述,我想在我的App应用程序模块中拥有多种风味,并且每种风味将编译与我的Core库项目不同的风味。 This way every flavor from my App module would have different files included in build from this Core library. 这样,我的App模块中的每个样式都会在此Core库的构建中包含不同的文件。

Does anyone know how can I accomplish this? 有谁知道我该怎么做?

As I can see you are explicitly providing the configuration to compile your project. 如我所见,您明确提供了用于编译项目的配置。 But you don't need to do that because "Android Studio" already provide that option 但是您不需要这样做,因为“ Android Studio”已经提供了该选项

To work on files from a particular flavor, click on Build Variants on the left of the IDE window and select the flavor you want to modify in the Build Variants panel, 要处理来自特定风味的文件,请单击IDE窗口左侧的Build Variants,然后在Build Variants面板中选择要修改的风味,

在此处输入图片说明

For product flavors you need to specify following things: 对于产品口味,您需要指定以下内容:

productFlavors {
        demo {
            applicationId "com.buildsystemexample.app.demo"
            versionName "1.0-demo"
        }
        full {
            applicationId "com.buildsystemexample.app.full"
            versionName "1.0-full"
        }
    }

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

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