Cannot build android project using Android Studio - Gradle 1.7

北城余情 提交于 2019-11-27 21:01:59
Luca Vitucci

I'm copying here my final update as an answer.

It finally seems like i solved this issue cleaning up my resources, removing some unused XML and an unused theme. This obviously does not answer this question that i guess is of common interest.

Navigating the web i found that AAPT is know to fail with SegFault11, and often it does not give any information about the real error which can be caused by:

As Dale Cooper suggested, you could also try to run Lint and see if it finds any warning about resources.

I'm trying to find links to users experiencing those other causes (It's been some time since the original question), i will update this answer when i'll find them back.

Victor Häggqvist

I just had sort of the same problem, but on the processDebugResources step. After a couple of hours I started to try running diffrent verisons of aapt (/build-tools/[version]/aapt) and it turns out that they give one hell of different error messages. The one I was originally using was 19.0.1 which only gave me Segmentation fault but when i tried out 18.1.1 I was suddenly pointed to a line in a menu.xml which had a resource missmatch. The problem turns out to be that I hade removed the default @string/action_settings because I thought I didn't use it.

Conclusion, trying different versions of aapt may help you find a resource missmatch.

Yeah, I was just struggling with similiar issue. It turned out that I've got some non-finished code in menu.xml file:

   <item android:id="@+id/action_search"
    android:title="@string/action_search"
    android:icon="@drawable/"
    app:showAsAction="ifRoom|collapseActionView"
    />

exactly this line was missing drawable reference:

 android:icon="@drawable/"

I found it through running Lint (Analyze -> Inspect code) and it was in Android -> Android Resource Validation as Cannot resolve symbol '@drawable/'

I had the same issue and it was a very very hard to locate it.

I want to share the steps I made to locate and solve this problem.

My gradle ouput looks like this:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':libs:base:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /opt/android-sdk/build-tools/18.1.1/aapt package -f --no-crunch -I /opt/android-sdk/platforms/android-19/android.jar -M /home/m039/WorkProjects/libs/base/build/bundles/debug/AndroidManifest.xml -S /home/m039/WorkProjects/libs/base/build/res/all/debug -A /home/m039/WorkProjects/libs/base/build/bundles/debug/assets -m -J /home/m039/WorkProjects/libs/base/build/source/r/debug -F /home/m039/WorkProjects/libs/base/build/libs/base-debug.ap_ --debug-mode --non-constant-id --output-text-symbols /home/m039/WorkProjects/libs/base/build/bundles/debug
  Error Code:
    139

First of all I switched to 18.1.1 version, it didn't helped a lot. Then I tried to add -v flag and run this command:

/opt/android-sdk/build-tools/18.1.1/aapt package -f --no-crunch -I /opt/android-sdk/platforms/android-19/android.jar -M /home/m039/WorkProjects/libs/base/build/bundles/debug/AndroidManifest.xml -S /home/m039/WorkProjects/libs/base/build/res/all/debug -A /home/m039/WorkProjects/libs/base/build/bundles/debug/assets -m -J /home/m039/WorkProjects/libs/base/build/source/r/debug -F /home/m039/WorkProjects/libs/base/build/libs/base-debug.ap_ --debug-mode --non-constant-id --output-text-symbols /home/m039/WorkProjects/libs/base/build/bundles/debug -v

It helped a little, but didn't give a clue about the problem. Then I tried strace and it helped a lot:

strace -s 100 /opt/android-sdk/build-tools/18.1.1/aapt package -f --no-crunch -I /opt/android-sdk/platforms/android-19/android.jar -M /home/m039/WorkProjects/libs/base/build/bundles/debug/AndroidManifest.xml -S /home/m039/WorkProjects/libs/base/build/res/all/debug -A /home/m039/WorkProjects/libs/base/build/bundles/debug/assets -m -J /home/m039/WorkProjects/libs/base/build/source/r/debug -F /home/m039/WorkProjects/libs/base/build/libs/base-debug.ap_ --debug-mode --non-constant-id --output-text-symbols /home/m039/WorkProjects/libs/base/build/bundles/debug 

In the output of previous command I've found this line:

open("/home/m039/WorkProjects/libs/base/build/res/all/debug/values/values.xml", O_RDONLY|O_LARGEFILE) = 5

In values.xml file I've found all resources, then I started remove tag by tag from the end of the file and execute aapt command above until I found the problem.

My problem was in id resource.

I had this issue after importing the eclipse project. Issue was from my side. In eclipse, I put a png image in drawable which was actually a jpg image (I just renamed the extension from .jpg to .png). It was working fine with eclipse but was failing when imported to Android Studio.

Execution failed for task ':app:mergeDebugResources'. Crunching Cruncher d.png failed

I just deleted the d.png and added a original png file. It worked!

If you've have imported your Project from Eclipse, then on the Android studio delete resource menu/main.xml and be sure you not have any invalid string resources.

For some reason the gradle cannot validate the menu/main.xml file.

I removed an accidentally added header in the menu xml:

Remove this:

<?xml version="1.0" encoding="utf-8"?>

Leave this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

So since I had a similar issue I would like to post my solution: After this error:

failed to capture snapshot of output files for task…

I cleaned my project and it worked again. Why I don't have a clue but it worked. :)

Benoit

It has happened to me for an Activity declared in the manifest whose title was remove from the string file.

This bug can be Anything related to resources. The best way to find the error is:

  1. Save your code.
  2. Return to the last commit that worked.
  3. Add your resources changes one by one until it fails again.

I have had a similiar issue. I guess it generally happens when there is some incomplete tag or something in the xml or some thing malformed..In my case there issue was with the theme. In design view in android studio in my xml file..i selected a new theme...that way it resolved the issues...hope this helps for all...

I ran into the same problem and issue was with my build directory, currently Android Studio supports directory path less than 100 characters.

Found solution for this:

In root build.gradle

allprojects {
    buildDir = "/path/to/build/${rootProject.name}/${project.name}"
}

and docs https://gradle.org/docs/current/userguide/writing_build_scripts.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!