问题描述
看来 Gradle zipAlign 任务对我不起作用,不确定我做错了什么.我试过包括 zipAlign 任务,但不包括它,但它似乎没有什么区别.我的 gradle 脚本输出了一个发布"版本,但是当我尝试上传我的 .apk 时,它从未根据开发人员控制台进行 zipAligned.
It appears the Gradle zipAlign task isn't working for me, not sure what I'm doing wrong. I've tried including the zipAlign task, and not including it, but it doesn't seem to make a difference. My gradle scripts spit out a "release" build, but it's never zipAligned according to the developer console when I try to upload my .apk.
这是我的构建脚本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile project(':facebook-android-sdk-3.0.1:facebook')
compile project(':google-play-services_lib')
compile project(':nineoldandroids')
compile project(':SlidingMenu-master:library')
compile project(':ViewPagerIndicator')
compile project(':volley')
compile project(':windowed-seek-bar')
compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
}
android {
buildToolsVersion "17.0"
compileSdkVersion 17
signingConfigs {
debug {
storeFile file('keystores/debug.keystore')
}
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
release {
zipAlign true
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
}
感谢任何帮助!
推荐答案
您的发布版本类型未配置用于签名.
Your release build type is not configured for signing.
如果您手动签署您的 apk,您还需要手动运行 ZipAlign.ZipAlign 必须在签名之后发生.
If you are signing your apk manually, you need to run ZipAlign manually as well. ZipAlign must happen after signing.
Gradle 只会在可以签名的情况下对 apk 进行 zipalign.
Gradle will zipalign an apk only if it can sign as well.
要为发布配置设置签名,您需要先创建一个新的签名配置,然后将其分配给构建类型.
To setup signing for the release config, you'll need to first create a new signing config, then assign it to the build type.
android {
signingConfigs {
release {
storeFile file("/path/to/keystore")
storePassword "??"
keyAlias "??"
keyPassword "??"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
请注意,签名配置中的所有 4 个参数都是必需的,否则它会认为缺少某些值,甚至不会尝试签名.
Note that all 4 parameters in the signing config are required, otherwise it'll consider some values are missing and it won't even attempt to sign.
这篇关于Gradle zipAlign 任务不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!