Gradle 的配置
16lz
2022-03-31
apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
compileSdkVersion 23
main {
jniLibs.srcDirs = ['libs']
}
}
dexOptions {
javaMaxHeapSize "4g"//编译时内存不足的问题
统一配置
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
引入第三方so库时需要配置sourceSets
main {
jniLibs.srcDirs = ['libs']
}
}
dexOptions {
javaMaxHeapSize "4g"//编译时内存不足的问题
}
配置包名版本等
defaultConfig { applicationId "com.packname" minSdkVersion 14 targetSdkVersion 17 versionCode 1 versionName "1.0.0" // dex突破65535的限制 multiDexEnabled true // 默认是umeng的渠道 manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"] }
自动签名打包
signingConfigs { debug { keyAlias '。。。' keyPassword 'passwd' storePassword 'passwd' storeFile file('项目keystore') } release { keyAlias '...' keyPassword 'passwd' storePassword '1passwd' storeFile file('项目keystore.jks') } }
构建类型,分debug、release
buildTypes { debug { // 显示Log buildConfigField "boolean", "LOG_DEBUG", "true" buildConfigField "boolean", "API_ENV", "true" buildConfigField "String", "API_SERVER_URL", "\"http://test...\"" buildConfigField "String", "API_WEB_URL","\"http://test...\"" buildConfigField "String", "API_3G_URL","\"http://www...\"" buildConfigField "String", "IMAGE_TYPE", "\".jpg,.png,.gif\"" versionNameSuffix "-debug" minifyEnabled false shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.debug debuggable true } release { // 不显示Log buildConfigField "boolean", "LOG_DEBUG", "false" buildConfigField "boolean", "API_ENV", "false" buildConfigField "String", "API_SERVER_URL", "\"http://apps..."" buildConfigField "String", "API_3G_URL","\"http://www..."" buildConfigField "String", "API_WEB_URL","\"http://apps...\"" buildConfigField "String", "IMAGE_TYPE", "\".jpg,.png,.gif\"" debuggable false
minifyEnabled //使用混淆 zipAlignEnabled true // 移除无用的resource文件 shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { def fileName = "v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk" output.outputFile = new File(outputFile.parent, fileName) } } } } }
多渠道打包
productFlavors { baidu {} _360 {} wandoujia {} yingyongbao{} yingyonghui{} jifeng{} lenovo{} yidong{} huawei{} xiaomi {}
} 统一配置
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
第三方库依赖管理
.jar和.aar文件,添加.aar文件还需要配置respositories
repositories { flatDir { dirs 'libs' }}
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'org.greenrobot:eventbus:3.0.0' compile 'com.squareup.picasso:picasso:2.5.2' //.aar文件 compile name: ' 文件name', ext: 'aar'}
更多相关文章
- AndroidManifest.xml文件详解(uses-configuration)
- Android4.0中修改挂断键(ENDCALL)的默认行为
- 禁止状态栏下拉
- Android(安卓)intent 传递数组对象序列化
- Android(安卓)文件打开方式
- android 首页fragment切换
- 更换工程的sdk或者google apis
- Android腾讯微薄客户端开发十四:首页menu菜单
- NPM 和webpack 的基础使用