Android终端命令执行编译命令()
16lz
2021-01-23
在Android Studio 中,在进行测试的使用,使用Run ,当需要生成Release 多渠道版本时,使用命令。
window 的打包命令为:
gradlew assembleRelease
mac:
./gradlew assembleRelease
这样就输出了多个渠道的apk
Gradle 学习笔记
android中的两种打包方式,及多渠道打包
# build.gradle
android { aaptOptions { cruncherEnabled = false useNewCruncher = false } //在android 标签下,唯一的属性就是compileSdkVersion,buildToolsVersion compileSdkVersion 25 buildToolsVersion '25.0.0' defaultConfig { applicationId rootProject.ext.android["applicationId"] minSdkVersion rootProject.ext.android["minSdkVersion"] targetSdkVersion rootProject.ext.android["targetSdkVersion"] versionCode rootProject.ext.android["versionCode"] versionName rootProject.ext.android["versionName"] testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true ndk {// abiFilters "arm64-v8a","armeabi", "armeabi-v7a", "x86", "x86_64","mips","mips64"// abiFilters "armeabi", "x86", "x86_64","mips","mips64"// abiFilters "armeabi", "x86" abiFilters "armeabi", "x86", "mips"// vivo xplay6 的cpu是 arm64-v8a } }/*解决 com.android.dex.DexIndexOverflowException: Cannot merge new index 65730 into a non-jumbo instruction!问题*/ dexOptions { jumboMode true } //umeng添加的sign文件 signingConfigs { debug { storeFile file('umeng.keystore') storePassword "android" keyAlias "androiddebugkey" keyPassword "android" } release { keyAlias 'kenway' keyPassword '123456' storeFile file('/Users/xiaokai/Documents/Alpha gd project/tony/keystore/alphaapp.jks') storePassword '123456' } } buildTypes { release { //移除无用resource文件 shrinkResources true //开启zip对齐 zipAlignEnabled true //混淆 minifyEnabled true //添加签名文件,测试umeng signingConfig signingConfigs.debug proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "int", "buildTime", getDebugVersionNameSuffix() } debug { debuggable true //生成的apk名字添加-debug,如 BuildConfig.VERSION_NAME=="v 1.1.0-debg" versionNameSuffix "-debug" //为debug版本的包名添加.debug后缀 applicationIdSuffix ".debug" //添加签名文件,测试umeng signingConfig signingConfigs.debug } } //多渠道打包 productFlavors { wandoujia {} baidu {} c360 {} uc {} productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } } //对生成的apk 进行一些简单的配置 applicationVariants.all { varint -> varint.outputs.each { output -> def outputFile = output.outputFile def buildType if (varint.buildType.name.equals("release")) { buildType="release" }else if(varint.buildType.name.equals("debug")){ buildType="debug" } if(outputFile !=null&&outputFile.name.endsWith(".apk")){ //输出apk名称为配置的名字+".apk" def fileName="superwavings_${getDate()}_${defaultConfig.versionName}_${varint.productFlavors[0].name}_${buildType}.apk" //将apk输出到指定路径 def appDir="/Users/xiaokai/Documents/Alpha gd project/tony/keystore";// output.outputFile=new File(outputFile.parent+buildType,fileName) output.outputFile=new File(appDir,fileName) } } } greendao { schemaVersion 2 daoPackage 'com.alpha.alphaapp.db'//这个是生成代码保存的包名 targetGenDir 'src/main/java'//保存到java代码路径 }}//版本编译时间def String getDebugVersionNameSuffix() { Date buildTime = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); String buildTimeStr = simpleDateFormat.format(buildTime); return buildTimeStr;}//获取时间戳def getDate() { def date = new Date() def formattedDate = date.format('yyyyMMdd') return formattedDate}
如果出现 The xxx.apk not exist .
,处理方法Android 开发中出现的错误解决方法 --安装错误
更多相关文章
- Android 学习笔记8---SAX和DOM解析XML文件
- android音乐文件乱码显示问题解决
- android webview 使用以及一些异常处理及上传文件问题
- Android 使用Okhttp进行文件下载
- android通用文件操作
- Android如何通过https协议下载自己的https网站上的文件/apk等
- Android Studio主要目录及文件简介
- Android软件测试的日志文件抓取简介
- Android中的版本适配