简体   繁体   English

使用 Android Studio 生成签名 APK 时出错

[英]Getting error while generating signed APK using Android studio

Here is the error that keeps coming up on the event log:这是事件日志中不断出现的错误:

Generate Signed APK: Errors while building APK.生成签名 APK:构建 APK 时出错。 You can find the errors in the 'Messages' view您可以在“消息”视图中找到错误

And this in the messages:这在消息中:

Android resource compilation failed Output: Android 资源编译失败输出:

C:\\Users\\me\\AndroidStudioProjects\\SimpleCalculator2\\app\\src\\main\\res\\mipmap-xxhdpi\\ic_launcher.png: error: failed to read PNG signature: file does not start with PNG signature.

Command:命令:

 C:\Users\me\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971- windows.jar\6c29a9fd1a7f2d4d5ddcbb0cbfa348c6\aapt2-3.2.0-4818971-windows\aapt2.exe compile --legacy\-o\

C:\Users\me\AndroidStudioProjects\SimpleCalculator2\app\build\intermediates\res\merged\release \

C:\Users\me\AndroidStudioProjects\SimpleCalculator2\app\src\main\res\mipmap-xxhdpi\ic_launcher.png

Daemon: AAPT2 aapt2-3.2.0-4818971-windows Daemon #0守护进程:AAPT2 aapt2-3.2.0-4818971-windows 守护进程#0

Just paste this in your build.gradle file只需将其粘贴到您的 build.gradle 文件中

android {
    ....
    aaptOptions {
        cruncherEnabled = false
    }
    ....
}

This happens when you either rename an image or when you just cut and paste an image anywhere in the app folders, At Build time the compiler will complain about this.当您重命名图像或将图像剪切并粘贴到应用程序文件夹中的任何位置时,就会发生这种情况,在构建时编译器会抱怨这一点。

Seeing your logs and as Praveen suggested:查看您的日志并按照 Praveen 的建议:

I feel some PNG files are corrupted and were not parsed.我觉得有些 PNG 文件已损坏且未解析。 Sometimes the images have an extension but are not real PNG.有时图像有扩展名,但不是真正的 PNG。

You can check if the images in your project are real PNGs with the below command :您可以使用以下命令检查项目中的图像是否为真正的 PNG:

find . -type f -name "*.png" | xargs -L 1 -I{} file  -I {} | grep -v 'image/png; charset=binary$'

After getting the list use this site to convert them to PNG.获取列表后,使用站点将它们转换为 PNG。

Cause: It might be because you Stored the Image in another format with a .png extension. Cause:这可能是因为您以另一种格式存储了带有 .png 扩展名的图像。 Solution: Don't just rename the file extension Convert your image file to .png format Solution:不要只是重命名文件扩展名将您的图像文件转换为 .png 格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM