build notes
signingConfigs {
test{
keyAlias 'key'
keyPassword '123456'
storeFile file('chengzj.jks')
storePassword '123456'
}
}
buildTypes {
release {
// 是否进行混淆
minifyEnabled false
// 签名
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
useProguard false
debuggable true
}
}
lintOptions {
abortOnError false //发生错误也继续打包
}
//生成不同渠道包
productFlavors {
zte { // 签名
signingConfig signingConfigs.release
}
}
//修改生成包的包名
android.applicationVariants.all {
variant -> variant.outputs.each {
output -> output.outputFile = new File(output.outputFile.parent,
"Zparking_"+ defaultConfig.versionCode +
"_v_" + defaultConfig.versionName +
"_"+ buildType.name + ".apk");
}
}
dexOptions {
incremental true //优化编译速度
}
android studio项目设定打包出来的APK只包含armeabi类型
我们只需要在我们的app—-> build.gradle中添加这个 即可。
ndk {
abiFilters 'armeabi' //只生成armv的so
}
具体添加位置:
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 63
versionName '2.038'
useLibrary 'org.apache.http.legacy'
multiDexEnabled true
ndk {
abiFilters 'armeabi' //只生成armv的so
}
}
INSTALL_FAILED_NO_MATCHING_ABIS 解决方案
错误原因:是由于使用了native libraries 。该native libraries 不支持当前的cpu的体系结构。
解决方案1:
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a','x86_64'
universalApk true
}
解决方案1: 使用对应cpu架构的模拟器。
定义编译出的包名名称
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (variant.buildType.name.equalsIgnoreCase("release") && outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "WeCare_v${versionName}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
def getTime() {
return new java.text.SimpleDateFormat("yyyyMMdd").format(new Date());
}
Plugin 3.0.0之前的打包命名修改
// 自定义APK安装包名
android.applicationVariants.all {
variant ->
variant.outputs.each {
output ->
if (buildType.name.equals("debug")) {
output.outputFile = new File(output.outputFile.parent,
"app-debug.apk")
}
if (buildType.name.equals("release")) {
output.outputFile = new File(output.outputFile.parent,
"app-release.apk")
}
}
}
现在修改为
// 自定义APK安装包名
android.applicationVariants.all {
variant ->
variant.outputs.all {
output ->
def outputFile = output.outputFile
if (outputFile.name.contains("debug")) {
outputFileName = new File("../debug/", "app-debug.apk")
}
}
}
plugin 3.0.0 新增了variant.outputs.all(Closure action)方法,测试时发现,variant.outputs.each(…)方法中找不到outputFileName ,只有variant.outputs.all(Closure action)才能找到outputFileName 变量
动态修改versionName版本
def getTime() {
return new java.text.SimpleDateFormat("yyyyMMddHHmm").format(new Date());
}
android {
...
defaultConfig {
...
versionName "3.0.${getTime()}"
}