libpng 错误:Android Studio 中显示的不是 PNG 文件错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23366222/
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
libpng error: Not a PNG file Error Showing In Android Studio
提问by IntelliJ Amiya
I just Imported a project from Eclipe to Android Studio
. Just a plain and simple project. But the project folder is showing one error .
我刚刚从Eclipe to Android Studio
. 只是一个简单而简单的项目。但项目文件夹显示一个错误。
May I know what is the correct way to achieve my objective? I am new in Android-studio .Does any guys meet this issue?Any help would be greatly appreciated.
我可以知道实现目标的正确方法是什么吗?我是 Android 工作室的新手。有没有人遇到这个问题?任何帮助将不胜感激。
Here is Logcat
:
这是Logcat
:
Execution failed for task ':app:mergeDebugResources'.
> Error: Failed to run command:
/home/amiya/android-studio/sdk/build-tools/android-4.4.2/aapt s -i /home/amiya/vola/app/src/main/res/drawable-mdpi/call.png -o /home/amiya/vola/app/build/res/all/debug/drawable-mdpi/call.png
Error Code:
42
Output:
libpng error: Not a PNG file
Here is my build.gradle
这是我的 build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 17
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.google.android.gms:play-services:+'
compile files('libs/google-play-services.jar')
compile files('libs/livesdk.jar')
}
I am not using this file anywhere in my project with that name !! There are many other png files in my project though.
我没有在我的项目中的任何地方使用这个文件名!不过,我的项目中还有许多其他 png 文件。
回答by IntelliJ Amiya
You should follow below steps.
您应该按照以下步骤操作。
Cut-paste the image on my desktop.
Opened it in an editor saved it as png. without renaming the file name.
Copy-pasted the
.png
image into the drawable folder.
将图像剪切粘贴到我的桌面上。
在编辑器中打开它保存为 png。无需重命名文件名。
将
.png
图像复制粘贴到 drawable 文件夹中。
You can use cruncherEnabled
.
您可以使用cruncherEnabled
.
Returns true if the PNGs should be crunched, false otherwise.
如果 PNG 应该被压缩,则返回 true,否则返回 false。
android
{
aaptOptions
{
cruncherEnabled = false
}
}
Hope this helps you.
希望这对你有帮助。
回答by Dormon Zhou
Try this in build.gradle
在 build.gradle 中试试这个
android {
....
aaptOptions {
cruncherEnabled = false
}
....
}
回答by vbevans94
Try run command
尝试运行命令
find . -type f -name "*.png" | xargs -L 1 -I{} file -I {} | grep -v 'image/png; charset=binary$'
in your root project directory, it will show you all files that have .pngextension, but are not pngs. Then you can resave them as png in some image editor. Before running this command clean project, to speed up the process.
在您的项目根目录中,它将显示所有具有.png扩展名但不是 png 的文件。然后你可以在一些图像编辑器中将它们重新保存为 png。在运行此命令之前清理项目,以加快进程。
回答by Spry Techies
It might be because of renaming problem of the Image just cut the images and paste any where in the system and open each with the respective editor and save as the same but of PNG
format
and then copy and pasteagain to drawable folders. It works for me
这可能是因为图像的重命名问题,只需剪切图像并粘贴到系统中的任何位置,然后使用相应的编辑器打开每个图像并另存为相同但PNG
格式,然后再次复制并粘贴到可绘制文件夹。这个对我有用
AND PLEASE LOOK AT THE ISSUE WHICH I SUBMITTED TO THE ANDROID STUDIO TEAM
Hope it will help you all .
希望对大家有所帮助。
回答by Android Mason
If you are using Mac OS, follow the steps below to get a png
如果您使用的是 Mac OS,请按照以下步骤获取 png
- Open image in preview
- Go to file -> Export
- Set format as png
- Click on save
- 在预览中打开图像
- 转到文件 -> 导出
- 设置格式为png
- 点击保存
This will give you a valid png
这会给你一个有效的 png
Mere renaming or changing extension won't work in Mac OS.
仅重命名或更改扩展名在 Mac OS 中不起作用。
回答by dmellos
"PNG" in the error is clearly written in caps. So you need to see that the image has .PNG extension (in Capital).
错误中的“PNG”显然是用大写字母写的。所以你需要看到图像有 .PNG 扩展名(大写)。
Step 1: Open the image in Paint.
第 1 步:在Paint 中打开图像。
Step 2: Save the image Save as .PNGshown as below Click here to see how to save the image in PNG
第 2 步:将图像另存为 .PNG如下所示 单击此处查看如何将图像保存为 PNG
Step 3: Refresh your project
第 3 步:刷新您的项目
Step 4: You should see like this -> See here
第 4 步:您应该会看到这样 ->请看这里
Please do reply if the issue is still not resolved
如果问题仍未解决,请回复
回答by knocte
As for me, what was happening is that I cloned the repository on Windows, and those PNG files were symlinks in Linux/Mac, but on Windows they were just invalid files. Once I did proper copies of the files instead of being symlinks, the build worked.
至于我,发生的事情是我在 Windows 上克隆了存储库,而那些 PNG 文件在 Linux/Mac 中是符号链接,但在 Windows 上它们只是无效文件。一旦我做了文件的正确副本而不是符号链接,构建就开始工作了。
回答by bizimunda
Try to use another pngfiles. It seems something wrong with png's metadata. I had the same issue. Then I used some other pngfiles and it fixed my issue.
尝试使用另一个png文件。png 的 metadata似乎有问题。我遇到过同样的问题。然后我使用了其他一些png文件,它解决了我的问题。