1. android studio是3.1.3
2.第一次打包,此时没有jks文件
2.1 build-->generate signed apk
2.1.1 key store path-->Create new...
2.1.1.1 key store path设置/home/bri/android_dev_keystore_bri_20180802.jks
2.1.1.2 Password "123"
2.1.1.3 key
2.1.1.3.1 Alies:"key0" Password:"456"
2.1.1.4 Cetificates
2.1.1.4.1 First and Last Name: "bri"
2.1.2 next
2.1.2.1 选择v2签名
2.2 此时编译出来的是MyFirstApplication/app/release下的app-release.apk
2.3 增加日期和版本号
配置build.gradle文件如下
-----------------------
apply plugin: 'com.android.application'
def versionTag() {
def time = new Date().format("YYYY-MM-dd", TimeZone.getTimeZone("UTC"))
def decoratedTime
if (time.startsWith("0")) {
decoratedTime = time.replaceFirst("0", "")
} else {
decoratedTime = time
}
return decoratedTime
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.bri.myapp"
minSdkVersion 23
targetSdkVersion 23
//每次升级版本versionCode必须加1,必须改,不改安装会出错
versionCode 2
//每次升级versionName也必须改,至少改动其中一个,不改安装会出错
versionName "1.0.2"+"-"+versionTag()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android.applicationVariants.all { variant ->
variant.outputs.all {
//outputFileName = "${variant.name}-${variant.versionName}.apk"
outputFileName = "Client" + "-" + buildType.name + "-" + defaultConfig.versionName + '.apk'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
//implementation 'com.android.support:appcompat-v7:23.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
-----------------------
此时,打包出来的apk在release目录下的Client-release-1.0.2-2018-08-02.apk
3.如果已经有jks文件,2.1.1步骤,导入既可。