Android studio打包方式:
1.手动打包:通过Build-->Generate Signed APK方式,这种方式打包,需要手动添写签名文件信息
2.通过命令:gradlew assembleRelease,这种方式打包,直接读取build.grade配置进行打包,可同时打包不同名称的apk;
例如:下面的Bate版本和Releases,这两种都是release版本的包
build.grade文件配置如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
dexOptions {
javaMaxHeapSize "6g" //java虚拟机的堆内存大小。
}
//在编译apk的时默认配置
defaultConfig {
applicationId "com.demo" //应用包名
minSdkVersion 16
targetSdkVersion 22
versionCode 1
manifestPlaceholders = [JPUSH_APP_KEY: TEST_JPUSH_APP_KEY, //打包时替换Androidmenifest.xml中的值
app_name : "@string/app_name",
]
//<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APP_KEY}"
}
signingConfigs {
//debug版本的包
debug {
// No debug config
}
//打签名包时的配置,release版本的包
release {
storeFile file("C:\\Android\\workspace\\demo\\my.keystore")
storePassword "123456"
keyAlias "name"
keyPassword "123456"
}
}
buildTypes {
release {
minifyEnabled false
pseudoLocalesEnabled false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
//打签名包时,需要添加此设置
signingConfig signingConfigs.release
}
}
//apk多渠道打包
productFlavors {
Bate{
applicationId "com.demo.beta"
manifestPlaceholders = [app_name: "测试Beta版"]
//在java代码中具体的使用方式为:context.getResources().getString(R.string.strKey);
resValue("string", "strKey", "beta版本")//打包后apk的安装名称
}
Releases {
manifestPlaceholders = [JPUSH_APP_KEY: JPUSH_APP_KEY]
resValue("string", "strKey", "release版本")//打包后apk的安装名称
}
}
lintOptions {
disable 'ResourceType'
abortOnError false
checkReleaseBuilds false
// 防止在发布的时候出现因MissingTranslation导致Build Failed!
disable 'MissingTranslation'
}
}
repositories {
// ...
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.bigkoo:convenientbanner:2.0.5'
}
1.手动打包:通过Build-->Generate Signed APK方式,这种方式打包,需要手动添写签名文件信息
2.通过命令:gradlew assembleRelease,这种方式打包,直接读取build.grade配置进行打包,可同时打包不同名称的apk;
例如:下面的Bate版本和Releases,这两种都是release版本的包
build.grade文件配置如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
dexOptions {
javaMaxHeapSize "6g" //java虚拟机的堆内存大小。
}
//在编译apk的时默认配置
defaultConfig {
applicationId "com.demo" //应用包名
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
//dex突破65535的限制
manifestPlaceholders = [JPUSH_APP_KEY: TEST_JPUSH_APP_KEY, //打包时替换Androidmenifest.xml中的值
app_name : "@string/app_name",
]
//<meta-data
android:name="JPUSH_APPKEY"
android:value="${JPUSH_APP_KEY}"
}
signingConfigs {
//debug版本的包
debug {
// No debug config
}
//打签名包时的配置,release版本的包
release {
storeFile file("C:\\Android\\workspace\\demo\\my.keystore")
storePassword "123456"
keyAlias "name"
keyPassword "123456"
}
}
buildTypes {
release {
minifyEnabled false
pseudoLocalesEnabled false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
//打签名包时,需要添加此设置
signingConfig signingConfigs.release
}
}
//apk多渠道打包
productFlavors {
Bate{
applicationId "com.demo.beta"
manifestPlaceholders = [app_name: "测试Beta版"]
//在java代码中具体的使用方式为:context.getResources().getString(R.string.strKey);
resValue("string", "strKey", "beta版本")//打包后apk的安装名称
}
Releases {
manifestPlaceholders = [JPUSH_APP_KEY: JPUSH_APP_KEY]
resValue("string", "strKey", "release版本")//打包后apk的安装名称
}
}
lintOptions {
disable 'ResourceType'
abortOnError false
checkReleaseBuilds false
// 防止在发布的时候出现因MissingTranslation导致Build Failed!
disable 'MissingTranslation'
}
}
repositories {
// ...
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.bigkoo:convenientbanner:2.0.5'
}