如何在Android的Studio安装gradle这个提供两种口味不同的最低SDK版本? [英] How to setup gradle in Android Studio to provide two flavors with different minimum SDK versions?
问题描述
问题:我想要两个产品的口味,一个免费的版本,广告和广告没有一个专业版。
广告要求谷歌播放用最小的SDK 9,所以我设置免费的,但我希望我的亲版本有一个SDK分钟8。
Problem: I want two product flavors, a FREE version with ads and a PRO version without ads. Ads require Google Play with a min SDK of 9 so I set that for FREE but I want my pro version to have a min SDK of 8.
免费版作品的生成,但PRO的构建没有。
The build of the FREE version works but the build of PRO does not.
我使用的(稳定)的Android 1.1.0工作室
I am using (stable) Android Studio 1.1.0.
我安装一个空白的活动(Hello World示例)的新项目。
然后我修改(下图)的build.gradle文件以包括两种风格和自由的具体编译依赖,然后修改文件结构到活动的Java和XML布局文件移动到香味结构。因此,该项目具有以下文件结构:
I setup a new project with a blank activity (Hello World example). I then modified the build.gradle file (below) to include the two flavors and FREE-specific compile dependency and then modified the file structure to move the activity's java and layout xml files into the flavor structures. Thus, the project has the following file structure:
app\src\
free\
java\com\sample\adexample\MainActivity.java - This is Hello World.
res\layout\activity_main.xml - This is the Hello World layout.
res\values\strings.xml - Unique Hello World string for free version.
res\AndroidManifest.xml - This is a copy of the manifest in main.
main\
java\com\sample\adexample\ - empty
res\layout\ - empty
res\AndroidManifest.xml - This is the Hello World manifest.
pro\
java\com\sample\adexample\MainActivity.java - This is Hello World.
res\layout\activity_main.xml - This is the Hello World layout.
res\values\strings.xml - Unique Hello World string for free version.
res\AndroidManifest.xml - This is a copy of the manifest in main.
下面是我的build.gradle文件:
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.sample.adexample"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
pro {
applicationId "com.sample.adexample.pro"
minSdkVersion 8
versionName "1.0-Pro"
}
free {
applicationId "com.sample.adexample.free"
minSdkVersion 9
versionName "1.0-Free"
dependencies {
compile 'com.google.android.gms:play-services:6.+'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
构建freeDebug味道正常工作。
但我建立proDebug时收到以下错误:
Building the freeDebug flavor works fine. But I get the following error when building proDebug:
:app:processProDebugManifest
C:\Users\Jeff\AndroidStudioProjects\AdExample\app\src\main\AndroidManifest.xml:0:0 Error:
uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library C:\Users\Jeff\AndroidStudioProjects\AdExample\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.5.87\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.google.android.gms" to force usage
有没有办法来完成要求?
Is there a way to accomplish the requirements?
感谢您的时间。
推荐答案
删除依赖
从免费
关闭。此举编译com.google.android.gms:发挥服务:6 +
到现有的依赖
关闭并使其成为 freeCompile
,而不是编译
。
Remove the dependencies
closure from free
. Move that compile 'com.google.android.gms:play-services:6.+'
into your existing dependencies
closure and make it be freeCompile
rather than compile
.
一个preFIX上的编译
语句是如何使依赖绑打造的变种,而不是使用所有的时间的方式编译
是。所以, debugCompile
将宣布一个依赖于只有调试
生成类型和 freeCompile
将宣布一个依赖于只有免费
产品风味。
A prefix on the compile
statement is how you make dependencies be tied to build variants rather than be used all the time the way compile
is. So, a debugCompile
would declare a dependency for only the debug
build type, and freeCompile
would declare a dependency for only the free
product flavor.
据我所知,这应该适用于多种调味剂尺寸,所以如果你有一种依赖,是只为鸟
味道有关(在一维)和免费
味道(在另一个维度),你可以使用 freeBirdCompile'com.skynyrd.lynyrd:提出 - 打火机:1.0.0
拉,在
AFAIK, this should work for multiple flavor dimensions, so if you had a dependency that was only relevant for the bird
flavor (on one dimension) and the free
flavor (on another dimension), you could use freeBirdCompile 'com.skynyrd.lynyrd:raised-lighter:1.0.0'
to pull that in.
这篇关于如何在Android的Studio安装gradle这个提供两种口味不同的最低SDK版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!