Android Studio - 如何 ZipAlign apk
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21242678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio - How to ZipAlign apk
提问by jtmwanakhu
I have created a signed apk using Android Studio and I'm now going to zipalign it, I have read this: http://developer.android.com/tools/help/zipalign.htmlbut I'm still not sure where to add the lines of code, is it in the Gradle file and where in the file do I add the lines?
我已经使用 Android Studio 创建了一个签名的 apk,我现在要对其进行 zipalign,我已经阅读了:http: //developer.android.com/tools/help/zipalign.html但我仍然不确定在哪里添加代码行,它是否在 Gradle 文件中,我应该在文件中的哪个位置添加这些行?
回答by pyus13
Inside you main module's build.gradle
file you can have multiple build types along with your debug one.
在您的主模块build.gradle
文件中,您可以拥有多种构建类型以及调试类型。
You can specify zipAlign characteristic inside any of your buildTypeby using
你可以在里面你的任何指定的zipalign特征buildType使用
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
zipAlignEnabled true
}
}
Note:Older versions use zipAlign
, instead of zipAlignEnabled
注意:旧版本使用zipAlign
, 而不是zipAlignEnabled
Default gradle tasks always created for debug and release buildTypes whether you define or not. Debug is for debugging purpose and Release for Signed Application (Build >> Generate Signed Apk). You must define your signingConfig for release builds.
无论您是否定义,始终为调试和发布构建类型创建默认的 gradle 任务。调试用于调试目的和签名应用程序发布(构建 >> 生成签名 Apk)。您必须为发布版本定义签名配置。
Check Build Types section in below mentioned link for other properties that you can use in your buildTypes
检查下面提到的链接中的构建类型部分,了解您可以在构建类型中使用的其他属性
http://tools.android.com/tech-docs/new-build-system/user-guide
http://tools.android.com/tech-docs/new-build-system/user-guide
回答by Zhenguo Cui
If you have created an .apk
file (release mode) from Android Studio, your APK is already aligned. The zipalign
step is part of the Build Process in Android Studio.
如果您.apk
从 Android Studio创建了文件(发布模式),则您的 APK 已经对齐。该zipalign
步骤是Android Studio 中构建过程的一部分。
You can check an APK with:
您可以使用以下命令检查 APK:
zipalign -c -v 4 {APP}.apk
To align an APK, run:
要对齐 APK,请运行:
zipalign -v 4 {APP}.apk {ZIPALIGNED_APP}.apk
回答by Neel Mevada
Set classpath from 'com.android.tools.build:gradle:2.2.0-alpha3' to
将类路径从 'com.android.tools.build:gradle:2.2.0-alpha3' 设置为
classpath 'com.android.tools.build:gradle:2.1.2'
类路径 'com.android.tools.build:gradle:2.1.2'
回答by Vrajesh
For complete signing process do follow steps. (Zip align manually after build- signed apk)
要完成签名过程,请按照以下步骤操作。(在构建签名的 apk 后手动 Zip 对齐)
Step 0:Before sign apk add code in your app module.gradle file : set zippAlignEnable and minifyEnable true.
第 0 步:在签署 apk 之前,在您的应用程序 module.gradle 文件中添加代码:将 zppAlignEnable 和 minifyEnable 设置为 true。
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
//zipAlignEnabled true
//uncomment for automatically zip aligned by studio
}
}
Step 1:Sign your APK, relese mode more info
第 1 步:签署您的 APK,发布模式更多信息
Step 2:find location : .\your sdk\build-tools\24.0.0
第 2 步:找到位置:.\your sdk\build-tools\24.0.0
Step 3:copyyour .jks keystore file and signed APK then pasteit here.
第 3 步:复制您的 .jks 密钥库文件和签名的 APK,然后将其粘贴到此处。
Step 4:open command prompt (For windows). set path.of your location where you paste stuff.
第 4 步:打开命令提示符(对于 Windows)。设置路径。您粘贴内容的位置。
Step 5:type command: zipalign -f -v 4 infile.apk outfile.apk
第五步:输入命令: zipalign -f -v 4 infile.apk outfile.apk
here infile is my signed apk and outfile is file which is uploaded on play store.
这里 infile 是我签名的 apk,outfile 是上传到 Play 商店的文件。
Done...!
完毕...!
If cmp will got BUILD failed.
如果 cmp 会导致 BUILD 失败。
See here for more about error(Zipalign build failed) do following
有关错误(Zipalign 构建失败)的更多信息,请参见此处,请执行以下操作
1) Restart and open Android Studio,
1)重启并打开Android Studio,
2) close cmd, then reopen it.
2)关闭cmd,然后重新打开它。
3) Now do above process.
3)现在做上面的过程。
Edit: resources.arsc BAD-1 error found
编辑:发现 resources.arsc BAD-1 错误
set classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
to
到
classpath 'com.android.tools.build:gradle:2.1.2'
Happy Release:)
快乐发布:)
回答by tashi tsering
zipalign is in ADT/sdk/build-tools/android4.4W
zipalign 在 ADT/sdk/build-tools/android4.4W
Copy
android4.4W
folderPaste it in
yourproject/platforms/android/build/outputs/apk
Now, copy
yourkey.keystore and your project.apk
Paste them into
android4.4W
full pathyourproject/platforms/android/build/outputs/apk/android4.4W
then,
$ zipalign -v 4 project.apk wowdone.apk
.
复制
android4.4W
文件夹粘贴进去
yourproject/platforms/android/build/outputs/apk
现在,复制
yourkey.keystore and your project.apk
将它们粘贴到
android4.4W
完整路径中yourproject/platforms/android/build/outputs/apk/android4.4W
然后,
$ zipalign -v 4 project.apk wowdone.apk
。
Visit for more details: http://prehow.com/convert-wordpress-to-android-app-tutorial.html
更多详情请访问:http: //prehow.com/convert-wordpress-to-android-app-tutorial.html
Thats all, hope this answer will help you.
就这些,希望这个回答能帮到你。
回答by li bing zhao
This works for me:
这对我有用:
Copy the last version folder 22.0.1 to yourproject/platforms/android/build/outputs/apk (like version 22.0.1 is my last version)
Copy yourkey.keystore and your project.apk into this verison folder 22.0.1.
Under the path yourproject/platforms/android/build/outputs/apk/22.0.1, run this command:
zipalign -v 4 name_of_current.apk name_of_wanted.apk
The name_of_wanted.apk should be located under yourproject/platforms/android/build/outputs/apk/22.0.1
将最后一个版本文件夹 22.0.1 复制到 yourproject/platforms/android/build/outputs/apk (比如版本 22.0.1 是我的最后一个版本)
将 yourkey.keystore 和您的 project.apk 复制到此版本文件夹 22.0.1 中。
在 yourproject/platforms/android/build/outputs/apk/22.0.1 路径下,运行以下命令:
zipalign -v 4 name_of_current.apk name_of_wanted.apk
name_of_wanted.apk 应该位于 yourproject/platforms/android/build/outputs/apk/22.0.1 下