Androidstudio 打包配置

【Androidstudio 打包配置】在project目录下新建配置文件keystore.properties内容如下

KEY_STORE_FILE=你的密钥路径 KEY_STORE_PWD=你的密码 KEY_ALIAS_NAME=你的密码别名 KEY_ALIAS_PWD=你的ALIAS PWD

apply plugin: 'com.android.application'//引用之前配置的keystore配置文件 def keystorePropertiesFile = rootProject.file("keystore.properties") def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile))//获取时间,用于apk命名区分打包时间 static def releaseTime() { return new Date().format("yyyy_MM_dd_HH_mm_ss", TimeZone.getTimeZone("UTC")) } android { compileSdkVersion 26 defaultConfig { applicationId "com.sigel.test" minSdkVersion 24 targetSdkVersion 26 versionCode VersionCode as Integer versionName VersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }signingConfigs { release { storeFile file(keystoreProperties['KEY_STORE_FILE']) storePassword keystoreProperties['KEY_STORE_PWD'] keyAlias "测试科技" keyPassword keystoreProperties['KEY_ALIAS_PWD'] } }buildTypes { release { zipAlignEnabled true//优化zipAlign minifyEnabled true//是否混淆 shrinkResources true//移除无用的资源文件shrinkResources依赖于minifyEnabled,必须和minifyEnabled一起用 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'//加载默认的混淆配置文件 signingConfig signingConfigs.releaseapplicationVariants.all { variant -> variant.outputs.all { output -> def outputFlie = output.outputFile if (outputFlie != null && outputFlie.name.endsWith(".apk")&& variant.buildType.name.equals("release")){ def fileName ="Test_${variant.versionName}_${variant.versionCode}_${releaseTime()}_release.apk" outputFileName = fileName }} } }debug { minifyEnabled false signingConfig signingConfigs.release proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }//这个是我用了databindng。没有使用的不用添加 dataBinding{ enabled true }} //定义一个位置存放apk,有时候为了不难找apk可以指定一个位置放打包后的apk task copyAPK(type: Copy) { include '**/*.apk' from '/build/outputs/apk' into 'APK/' }//在task被添加的时候定义依赖关系,copyApk任务总是在打包完成后执行 tasks.whenTaskAdded { task -> if (task.name.startsWith("assemble")) { task.finalizedBy copyAPK } }dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.github.sigale:FlowLineView:v1.0.0'api project(path: ':base')} 第一句代码大家都应该知道,这里就不说了


    推荐阅读