I have a problem with 9 patch images.
There are around 30 9 patch images in my res folder. On earlier versions of Android Studio, errors told me exactly which one of the images was bad, but on newer versions I just get error
Error:Execution failed for task
':app:mergePhotoKeyboardThemeChangerDebugResources'.
Error: java.lang.RuntimeException: Some file crunching failed, see logs for details
Is there an option for that in Android Studio settings? It is a lot of work to check images one by one and see which one is bad.
Some times the error will come with jpg images, try to convert the jpg images to png images.
convert online from online png converter.
Suggestion#1:
Relocate your project and the build will succeed.
Resource Link: https://stackoverflow.com/a/25209204
Suggestion#2:
Sometimes .png images are corrupted. you need to replace in drawable
Resource Link: https://stackoverflow.com/a/41380118
Suggestion#3:
change build directory
For example:
allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
jcenter()
}
}
Rebuild and happy coding.
Resource Link: https://stackoverflow.com/a/41877283
Last Suggestion
Add
aaptOptions {
cruncherEnabled = false
}
in your gradle(app) file in android{ } scope
it will work fine
Related
I am trying to convert my Android app to JAR.
While clicking the build option in the GRADLE toolbar, it shows this error:
Fix the issues identified by lint or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
Now I added these lines to my build.gradle but JAR has not been created and not showing any errors too. Pls help
try using the creteFullJarDebug or createFullJarRelease that are located in the other on the same tab
Apparently, there is a bug with fetching lintOptions. Maybe your problem is related to that. Try to change the order of repositories, move google() to the top in your project gradle and app gradle(if it exists) as well.
I have downloaded a file from our nexus server by following this post: gradle - download and unzip file from url in my android project, first specifying the target:
compile 'net.myapp.gwt:MyAppGWT:1.0:android#zip'
and then I have this unzip task:
task unzip(type: Copy) {
def zipPath = project.configurations.compile.find {it.name.startsWith("net.myapp.gwt")}
println zipPath
def zipFile = file(zipPath)
def outputDir = file('src/main/assets/')
from zipTree(zipFile)
into outputDir
}
The problem is that the line
project.configurations.compile
generates the weirdest error. Applying it gives me following error:
Error:Could not find com.android.support:appcompat-v7:23.0.1.
Searched in the following locations:
file:/Applications/AndroioStudio.app/Contents/gradle/m2repository/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
file:/Applications/AndroidStudio.app/Contents/gradle/m2repository/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
https://maven.fabric.io/public/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
https://maven.fabric.io/public/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
https://nexus.domain.net/content/repositories/apps-releases/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
https://nexus.domain.net/content/repositories/apps-releases/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
Required by:
apps-android:app:unspecified
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
Now, all of a sudden it can't find
com.android.support:appcompat-v7:23.0.1
which isn't a problem if I remove that line.
#RaGe was right. Adding the libraries to our local repo server did the trick. Even though, as you state, this is a workaround and perhaps in the long run would be nice to find a better solution.
appcompat comes from your local sdk folder. But when you try to access configs.compile, gradle is trying to resolve all dependencies including appcompat from the external repos, and fails when it (unsurprisingly) doesn't find appcompat.
I'm not sure what the "right" solution is, but a possible workaround is to publish android sdk dependencies to your local maven or nexus repo. Here's one way to do that: github.com/simpligility/maven-android-sdk-deployer
Some answers from here might help too.
Lastly, it might be possible to treat your SDK folder as a local maven repo. See here.
So I have a custom_rules.xml file Im trying to rebuild in gradle. so far I have no problem figuring everything else out but the last part Im trying to accomplish is running a special apk signing tool for widevine drm on the unsigned apk that I generate with my gradle build process. Ive been looking online and in the gradle documentation all day but I have yet to find how to run an executable jar file from gradle. I know I have to create a task but thats about it. Any help would be much appreciated.
PS. Ive read a lot of the gradle documentation so please spare me any read the docs responses
EDIT:
this is what my task looks like at the moment and it compiles but Im not sure its actually doing anything
task (runApkSigTool , dependsOn: 'android', type: JavaExec) {
classpath files('apksigtool.jar')
main 'com.widevine.tools.android.apksigtool.ApkSigTool'
args[0] = apkLocation
args[1] = 'private_key.der'
args[2] = 'my.crt'
}
Im not sure if I have to use it like a method in the android section of my build.gradle file or what.
You could probably use the JavaExec task. Something like this:
task signApk(type: JavaExec) {
classpath files('path/to/executable.jar')
main 'com.foo.MainClass'
args ['-foo', 'bar']
}
I just Imported a project from Eclipe to Android Studio. Just a plain and simple project. But the project folder is showing one error .
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.
Here is 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
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.
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.
You can use cruncherEnabled.
Returns true if the PNGs should be crunched, false otherwise.
android
{
aaptOptions
{
cruncherEnabled = false
}
}
Hope this helps you.
Try this in build.gradle
android {
....
aaptOptions {
cruncherEnabled = false
}
....
}
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 .png extension, 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.
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 paste again to drawable folders. It works for me
AND PLEASE LOOK AT THE ISSUE WHICH I SUBMITTED TO THE ANDROID STUDIO TEAM
Hope it will help you all .
If you are using Mac OS, follow the steps below to get a png
Open image in preview
Go to file -> Export
Set format as png
Click on save
This will give you a valid png
Mere renaming or changing extension won't work in Mac OS.
"PNG" in the error is clearly written in caps. So you need to see that the image has .PNG extension (in Capital).
Step 1: Open the image in Paint.
Step 2: Save the image Save as .PNG shown as below
Click here to see how to save the image in PNG
Step 3: Refresh your project
Step 4: You should see like this -> See here
Please do reply if the issue is still not resolved
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.
Try to use another png files. It seems something wrong with png's metadata. I had the same issue. Then I used some other png files and it fixed my issue.
How do I prevent the Android "build process" from optimizing .png images?
I have an Android project with the following res directories:
- /res/
- /res/drawable
- /res/drawable-hdpi
- /res/drawable-hdpi-v5
- /res/drawable-ldpi
- /res/drawable-ldpi-v5
- /res/drawable-mdpi
- /res/drawable-mdpi-v5
These directories contain many .png files. I optimize PNG sizes with PNGOUTWin, and the overall size is reduced by more than 20%. When I build the .apk file, the images are "optimized" by the build process and the overall size is now 10% above the initial size, or 30% above my/PNGOUTWin optimized size.
My goal is to reduce the .apk size, even if it will affect the final performance, memory requirements, etc. How do I prevent the "build process" from optimizing .png images?
I'm targeting Android 2.2 and above.
P.S.: I am currently building my Android project from Eclipse, but I will switch to the automated build later (Ant?).
Note about JPG images: JPG will not work, because they do not have transparency.
Finally there is an official way to disable the PNG cruncher with Gradle which hasn't been mentioned here yet:
Edit main build.gradle to require gradle version 1.1.3 (or newer):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
In the individual apps's build.gradle, section android {}, insert:
aaptOptions {
cruncherEnabled = false
}
Reference:
https://code.google.com/p/android/issues/detail?id=65335
Specifying PNG crunching is now a BuildType property and is disabled by default on debug builds:
android {
…
buildTypes {
release {
crunchPngs false // or true
}
}
}
Note: It's available from Android Studio 3.0 Canary 5 .
As mentioned in the Android documentation: http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables
Note: Image resources placed in res/drawable/ may be automatically optimized with lossless image compression by the aapt tool during the
build process. For example, a true-color PNG that does not require
more than 256 colors may be converted to an 8-bit PNG with a color
palette. This will result in an image of equal quality but which
requires less memory. So be aware that the image binaries placed in
this directory can change during the build.
So if you want to reduce the size of your application you should either reduce the color-depth of your PNG files (this helps a lot) or switch to .JPG files wherever possible.
Android Studio: Since Gradle Android plugin 1.0.0:
android {
...
aaptOptions {
useNewCruncher false
}
....
}
Eclipse: Override the crunch task writing this in your build.xml:
<target name="-crunch">
<echo message="This will skip PNG optimization"/>
</target>
buildTypes {
release {
crunchPngs false // or true
}
}
add above the line on android block in
in ionic/Cordova project : root_folder_Of_App/platforms/android/app/build.gradle
in Android project: app/build.gradle
For More Information Visit: https://androidstudio.googleblog.com/2017/06/android-studio-30-canary-5-is-now.html
Google recently introduced a new PNG processor in aapt 0.9.1 in the Android SDK Build Tools that fixes this issue of increased PNG sizes after aapt optimization.
With this update, it is now possible for Android Studio & Gradle to switch between the PNG processors with the following change in your build.gradle configuration file:
android {
..
..
aaptOptions.useAaptPngCruncher = false
}
By adding this line, aapt uses the new PNG processor in which it checks to see if the "optimized" PNG files are smaller than the original PNG files. I was able to reduce 4.8 MB in my compiled APK and have not encountered any bugs/issues with the new build configuration.
UPDATE: This has been deprecated in later versions of Android Studio. Please refer to the answer provided by ChrisG.