Last active
November 29, 2016 02:19
-
-
Save wutianlong/4a76f01fbd635dcb1a2e4d22b81f58b4 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
1. 项目根目录下 build.gradle 配置 | |
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:1.3.0' | |
classpath 'com.tencent.bugly:symtabfileuploader:latest.release' | |
} | |
//当升级sdk、build tool、target sdk等,几个module都要更改,先在project的根目录下的build.gradle定义ext全局变量,然后每次修改project级别的build.gradle即可实现全局统一配置。 | |
ext { | |
compileSdkVersion = 21 | |
buildToolsVersion = "23.0.2" | |
minSdkVersion = 11 | |
targetSdkVersion = 21 | |
versionCode = 5610000 | |
versionName = "5.6.1" | |
} | |
} | |
allprojects { | |
repositories { | |
jcenter() | |
} | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} | |
2. 主module build.gradle 配置 | |
apply plugin: 'com.android.application' | |
def releaseTime() { | |
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) | |
} | |
/** 自定义版本号写法 开始 | |
def cmd = 'git rev-list HEAD --first-parent --count' | |
def gitVersion = cmd.execute().text.trim().toInteger() | |
android { | |
defaultConfig { | |
versionCode gitVersion | |
} | |
} 自定义版本号写法 结束 | |
*/ | |
def getDateTime() { | |
DateFormat df = new SimpleDateFormat("yyyyMMddHHmm"); | |
return df.format(new Date()); | |
} | |
android { | |
compileSdkVersion rootProject.ext.compileSdkVersion | |
buildToolsVersion rootProject.ext.buildToolsVersion | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_7 | |
targetCompatibility JavaVersion.VERSION_1_7 | |
} | |
signingConfigs { | |
padSigning { | |
storeFile file('../build_tools/keystore/Pad/sohu_video_pad_keystore') | |
storePassword "sohuvideopad" | |
keyAlias "sohu_video_pad_keystore" | |
keyPassword "sohuvideopad" | |
} | |
} | |
defaultConfig { | |
applicationId "com.sohu.tv" | |
minSdkVersion rootProject.ext.minSdkVersion | |
targetSdkVersion rootProject.ext.targetSdkVersion | |
versionCode = rootProject.ext.versionCode | |
versionName = rootProject.ext.versionName | |
multiDexEnabled true | |
signingConfig signingConfigs.padSigning | |
ndk { | |
// 设置支持的SO库架构 | |
abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a' | |
} | |
renderscriptTargetApi 19 | |
renderscriptSupportModeEnabled true // 如果用到renderscript做高斯模糊需要开启 | |
} | |
buildTypes { | |
release { | |
buildConfigField("boolean","SHOW_LOG","false") | |
signingConfig signingConfigs.padSigning | |
shrinkResources true | |
minifyEnabled true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../build_tools/jenkins/proguard.cfg' | |
zipAlignEnabled true | |
debuggable false | |
resValue "string", "app_name", "搜狐视频HD" | |
} | |
debug { | |
buildConfigField("boolean","SHOW_LOG","true") | |
signingConfig signingConfigs.padSigning | |
debuggable true | |
minifyEnabled true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../build_tools/jenkins/proguard.cfg' | |
resValue "string", "app_name", "搜狐视频HD_debug" | |
} | |
} | |
dexOptions { | |
incremental true | |
} | |
// 移除lint检查的error | |
lintOptions { | |
checkReleaseBuilds false | |
abortOnError false | |
} | |
dexOptions { | |
incremental true | |
} | |
packagingOptions { | |
exclude 'LICENSE.txt' | |
exclude 'META-INF/DEPENDENCIES' | |
exclude 'META-INF/dependencies' | |
exclude 'META-INF/DEPENDENCIES.txt' | |
exclude 'META-INF/dependencies.txt' | |
exclude 'META-INF/LGPL2.1' | |
exclude 'META-INF/LICENSE' | |
exclude 'META-INF/license' | |
exclude 'META-INF/LICENSE.txt' | |
exclude 'META-INF/license.txt' | |
exclude 'META-INF/NOTICE' | |
exclude 'META-INF/notice' | |
exclude 'META-INF/NOTICE.txt' | |
exclude 'META-INF/notice.txt' | |
exclude 'META-INF/README.txt' | |
exclude 'META-INF/services/javax.annotation.processing.Processor' | |
exclude '!META-INF/MANIFEST.MF' | |
exclude 'META-INF/MANIFEST.MF' | |
} | |
android.applicationVariants.all { variant -> | |
if (variant.buildType.name == android.signingConfigs.release.getName()) { | |
variant.outputs.each { output -> | |
def outputFile = output.outputFile | |
if (outputFile != null && outputFile.name.endsWith('.apk')) { | |
//这里修改apk文件名 | |
def fileName = "qfsdk_demo_${defaultConfig.versionCode}.${defaultConfig.versionName}_${getDateTime()}_release.apk" | |
output.outputFile = new File(outputFile.parent, fileName) | |
} | |
} | |
} | |
if (variant.buildType.name == android.signingConfigs.debug.getName()) { | |
variant.outputs.each { output -> | |
def outputFile = output.outputFile | |
if (outputFile != null && outputFile.name.endsWith('.apk')) { | |
//这里修改apk文件名 | |
def fileName = "qfsdk_demo_${defaultConfig.versionCode}.${defaultConfig.versionName}_${getDateTime()}_debug.apk" | |
output.outputFile = new File(outputFile.parent, fileName) | |
} | |
} | |
} | |
} | |
/** | |
* 这个选项基本不用. | |
* lt;a href="http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits"gt;官方说lt;/agt;: 使用 splits 可以比使用 flavor 更加有效创建多 apk. | |
* 目前而言, 仅支持 Density 和 ABIs 这两个分类. | |
*/ | |
// 只是放置一个armabi版本 | |
splits { | |
// 按屏幕尺寸 | |
density { | |
enable true | |
// 默认包含全部分辨率, 这里是剔除一些我们不要的 | |
exclude "ldpi", "mdpi", "xxxhdpi", "400dpi", "560dpi", "tvdpi" | |
} | |
// 按架构 | |
abi { | |
enable true | |
// 使用 `reset()` 后, 我们就相当于不包含任何架构, 这种情况下我们就可以通过 `include` 指定想要使用的架构 | |
reset() | |
include 'x86', 'armeabi-v7a' | |
universalApk true // 是否同时生成一个包含全部 Architecture 的包 | |
} | |
} | |
} | |
repositories { | |
flatDir { | |
dirs 'libs' | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: '*.jar') | |
compile(name:'qfvrcore', ext:'aar') | |
compile project(':Commonlibrary') | |
compile 'com.jakewharton:butterknife:7.0.1' | |
// 当出现依赖重复时候,需要从一个库中剔除一个 | |
debugCompile ('io.github.skyhacker2:sqliteonweb:1.0.1'){ // 一定要戴着小括号 | |
exclude module: 'gson' //by artifact name | |
exclude group: 'com.google.code.gson' //by group | |
exclude group: 'com.google.code.gson', module: 'gson' //by both name and group | |
} | |
} | |
3. library module build.gradle 配置 主要都同上,特殊如下: | |
apply plugin: 'com.android.library' | |
android{ | |
buildTypes { | |
release { | |
minifyEnabled true // 这个一定要为true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
// 项目根目录执行 ./gradlew makeReleaseJar , 生成aar文件在build/outputs/aar | |
task makeReleaseJar(type: Jar, dependsOn: 'assembleRelease') { | |
delete 'build/libs/VolleyNetLibrary.jar' // VolleyNetLibrary 为library module 名字 | |
from fileTree(dir: 'build/intermediates/classes/release') //指定具体classes位置 | |
into('build/libs/') // 生成jar放到此module文件目录 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment