如何在Android Studio中运行不同的产品风味 [英] How to Run Different Product Flavors in Android Studio
问题描述
我正在编写我的第一个android应用程序,而我刚开始使用产品口味.我有一个受广告支持的Beta版应用,正在编写没有广告的付费版本.我认为我可以编译两种口味.打开gradle窗口时,会看到诸如编译AdsDebugSources"和编译PremiumDebugSources"之类的目标.
I'm writing my first android app, and I'm just getting started with product flavors. I have an ad-supported app in beta, and I'm writing a paid version with no ads. I can compile both flavors, I think. When I open the gradle window, I see targets like "compile AdsDebugSources" and "compile PremiumDebugSources."
现在,如果我双击其中任何一个,构建都会顺利完成,而不会出现错误,但是我无法弄清楚如何运行结果.如果单击屏幕顶部绿色的运行"箭头,则永远无法运行高级应用程序.
Now, if I double-click on either of those, the build runs to completion without error, but I can't figure out how to run the results. If I click on the green "Run" arrow at the top of the screen, I can never run the premium app.
只有一个条目"app"会导致apk在所连接的设备上安装并运行,并且是AdsDebug版本.我想我需要添加一个新配置,但是找不到任何甚至提到味道"一词的文档.
There's only one entry, "app" that results in a an apk being installed and run on the attached device, and it's the AdsDebug version. I guess I need to add a new configuration, but I can't find any documentation that even mentions the word "flavor."
我尝试添加配置,但是我不明白这些问题的含义.我查看了默认应用程序的设置,但它们似乎意义不大.如何告诉我我想要我的应用程序的高级版本?
I've tried adding a configuration, but I don't understand what the questions mean. I looked at the settings for the default app, but they don't seem to mean much. How do I tell it that I want the premium version of my app?
还是我的问题与配置无关?我注意到,当我查看 Build/Edit Flavors
(构建/编辑风味)时,列出了两种风味,但是没有填写任何数据字段.我以为可以从清单中复制这些风味.我忽略了什么吗?
Or does my problem have nothing to do with configurations? I've noticed that when I look at the Build/Edit Flavors
the two flavors are listed, but none of the data fields are filled in. I would have thought that these would be copied from the manifest. Have I neglected something?
我要做的所有设置工作就是将这段代码添加到应用程序级别的build.gradle文件中:
All I did to set up the flavors was to add this code to the app level build.gradle file:
flavorDimensions "dummy"
productFlavors {
ads {
dimension "dummy"
applicationId 'com.example.myApp.ads'
}
premium {
dimension "dummy"
applicationId 'com.example.myApp.premium'
}
}
我还需要做什么?
推荐答案
在Android Studio中打开Build Variants工具.默认情况下,它停靠在左侧.
Open the Build Variants tool in Android Studio. By default, this is docked on the left.
它将显示项目中的模块列表,每个模块都有一个下拉列表,指示将由运行"按钮使用的构建变体.
It will show a list of modules in your project, with a drop-down for each indicating the build variant that will be used by the Run button.
这篇关于如何在Android Studio中运行不同的产品风味的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!