Last active
August 29, 2015 14:23
-
-
Save atomd-zz/5c7e7e3deadd3823f2ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 本文件存放在project目录下。 | |
RELEASE_STORE_FILE={path to your keystore} | |
RELEASE_STORE_PASSWORD=***** | |
RELEASE_KEY_ALIAS=***** | |
RELEASE_KEY_PASSWORD=***** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 本文件真正的文件名为:build.gradle。本文件存放在module目录下。 | |
apply plugin: 'com.android.application' | |
android { | |
// 编译环境。 | |
compileSdkVersion 19 | |
// 编译工具版本。 | |
buildToolsVersion "19.1.0" | |
defaultConfig { | |
// 默认的包名。将会替换AnroidManifest.xml中的packageName。 | |
applicationId "aa.bb.cc" | |
// 最低支持的android版本。 | |
minSdkVersion 10 | |
// 目标版本。 | |
targetSdkVersion 19 | |
// 程序版本号。 | |
versionCode 1 | |
// 程序版本名称。 | |
versionName "1.0" | |
} | |
signingConfigs { | |
release { | |
// 签名配置。 | |
// 签名文件。 | |
storeFile file('keystore') | |
// 签名文件密码。 | |
storePassword 'helloworld' | |
// 签名别号。 | |
keyAlias 'Android Release Key' | |
// 签名密码。 | |
keyPassword 'helloworld' | |
// 使用环境变量中配置的签名信息。 | |
// storeFile file(System.getenv("KEYSTORE_WKTV")) | |
// storePassword System.getenv("KEYSTORE_PWD_WKTV") | |
// keyAlias System.getenv("KEY_ALIAS_WKTV") | |
// keyPassword System.getenv("KEYSTORE_PWD_WKTV") | |
// 使用项目主目录下的gradle.properties。 | |
// storeFile file(RELEASE_STORE_FILE) | |
// storePassword RELEASE_STORE_PASSWORD | |
// keyAlias RELEASE_KEY_ALIAS | |
// keyPassword RELEASE_KEY_PASSWORD | |
// | |
// gradle.properties文件需要配置以下内容: | |
// RELEASE_STORE_FILE={path to your keystore} | |
// RELEASE_STORE_PASSWORD=***** | |
// RELEASE_KEY_ALIAS=***** | |
// RELEASE_KEY_PASSWORD=***** | |
} | |
} | |
buildTypes { | |
release { | |
// 是否使用代码混淆。 | |
minifyEnabled false | |
// 代码混淆文件。 | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
// 是否压缩对齐。 | |
zipAlignEnabled true | |
// 剔除没有使用到的资源文件。需要设置minifyEnabled 为 true 。 | |
shrinkResources true | |
// 程序签名。 | |
signingConfig signingConfigs.release | |
// buildTypes中不能直接设置包名和版本名称。 | |
// 程序包名后追加字段。 | |
applicationIdSuffix '.release' | |
// 版本名称后追加内容。 | |
versionNameSuffix '.release' | |
// 在BuildConfig中定义常量字段。 | |
buildConfigField 'String', 'TYPE', '\"release\"' | |
} | |
free.initWith(buildTypes.release) | |
free { | |
applicationIdSuffix '.free' | |
versionNameSuffix '.free' | |
buildConfigField 'String', 'TYPE', '\"free\"' | |
} | |
pro.initWith(buildTypes.release) | |
pro { | |
applicationIdSuffix '.pro' | |
versionNameSuffix '.pro' | |
buildConfigField 'String', 'TYPE', '\"pro\"' | |
} | |
} | |
productFlavors { | |
baidu { | |
// productFlavors中不能使用applicationIdSuffix、versionNameSuffix。 | |
// 设置包名(也可以使用packageName)。将会替换defaultConfig中的applicationId。 | |
applicationId "my.android.baidu" | |
// 设置版本号。将会替换defaultConfig中的versionCode。 | |
versionCode 7 | |
// 设置版本名称。将会替换defaultConfig中的versionName。 | |
versionName '1.bb' | |
// BuildConfig类中定义常量字段。 | |
buildConfigField 'String', 'PLATFORM_LABEL', '\"baidu\"' | |
// 设置友盟统计。 | |
// 在AndroidManifest.xml中配置: | |
// <meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}"/> | |
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"] | |
} | |
wandoujia { | |
packageName "my.android.wandoujia" | |
versionCode 7 | |
versionName '1.b' | |
buildConfigField 'String', 'PLATFORM_LABEL', '\"wandoujia\"' | |
} | |
} | |
} | |
dependencies { | |
// 引入 lib 包。 | |
// 引用某一个特定的jar。 | |
compile files('libs/xx.jar') | |
// 引用libs文件夹下除xx.jar以外所有的jar。 | |
compile fileTree(dir: 'libs', include: ['*.jar'], exclude: ['xx.jar']) | |
// so包在0.8版本的Android Studio中的目录更改为@{ModuleName}/src/main/jniLibs。且可以不用在此处配置so了。 | |
// 从 maven 库中引入。 | |
//compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:0.9.2' | |
// 引用 lib 工程。 | |
compile project(':moduleName') | |
// 引用users-library。users-library作用是,在编译时使用,但是jar不会打包到apk中,由Android或Android上安装的服务提供需要的内容。 | |
// 使用场景: | |
// 1. 使用Android的framework-classes.jar中的一些隐藏的API。 | |
// 2. Google的服务框架或者其他服务框架。需要在AndroidMainFest.xml中配合uses-library使用。 | |
provided files('libs/xx.jar') | |
provided 'aaa:bbb:x.x.x' | |
// 在测试环境下引用依赖。 | |
// 引用jar文件。 | |
androidTestCompile files('libs/xx.jar') | |
// 引用Maven。 | |
androidTestCompile 'junit:junit:4.11' | |
// 在baidu productFlavors分支下引用依赖。 | |
// 引用jar文件。 | |
baiduCompile files('libs/xx.jar') | |
// 引用Maven。 | |
baiduCompile 'aaa:bbb:x.x.x' | |
// 在release buildTypes分支下引用依赖。 | |
// 引用jar文件。 | |
releaseCompile files('libs/xx.jar') | |
// 引用Maven。 | |
releaseCompile 'aaa:bbb:x.x.x' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 本文件真正的文件名为:build.gradle。本文件存放在project目录下。 | |
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
repositories { | |
// 依赖仓库。 | |
jcenter() | |
// 在老版本中,此处为mavenCentral()。 | |
// mavenCentral()别名,表示依赖是从Central Maven 2 仓库中获取的。 | |
// jcenter()别名,表示依赖是从Bintary’s JCenter Maven 仓库中获取的。 | |
// mavenLocal()别名,表示依赖是从本地的Maven仓库中获取的。 | |
// 在中国,默认的maven源无法访问,可以通过以下的方式设置其他的maven源。 | |
// maven { | |
// url "http://xx.xxx.com/xxx" | |
// } | |
// 开源中国的源地址为: | |
// http://maven.oschina.net/content/groups/public/ | |
// 开源中国的thirdparty源地址为: | |
// http://maven.oschina.net/content/repositories/thirdparty/ | |
// 同样,你也可以设置依赖本地库。 | |
// | |
// 一个项目可以有好几个库。 | |
// Gradle 会根据依赖定义的顺序在各个库里寻找它们。 | |
// 在第一个库里找到就不会再在第二个库里进行寻找。 | |
} | |
dependencies { | |
// 一般升级AS或者导入从Eclipse中生成的项目时需要修改下面gradle版本。 | |
// 具体的版本对应关系,请[点击](http://tools.android.com/tech-docs/new-build-system/version-compatibility)。 | |
classpath 'com.android.tools.build:gradle:1.0.0' | |
} | |
} | |
allprojects { | |
repositories { | |
jcenter() | |
// 在老版本中,此处为mavenCentral()。 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 本文件真正的文件名为:settings.gradle。本文件存放在project目录下。 | |
// 声明module app | |
include ':app' | |
// 声明其他目录下的module | |
include ':app2' | |
project(':app2').projectDir = new File('dirName/app2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment