35
votes

I'm having lots of problems with Gradle and Android Studio.

Making changes in any resource in the project can randomly give an exception during compilation, this is what i see in Android Studio:

Gradle: Error while executing aapt command
Gradle: Execution failed for task ':App Code:processReleaseResources'.

And this is what i see executing Gradle manually:

"/Applications/Android Studio.app/sdk/tools/templates/gradle/wrapper/gradlew" asD
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:App Code:preBuild UP-TO-DATE                                 
:App Code:preDebugBuild UP-TO-DATE  
:App Code:preReleaseBuild UP-TO-DATE  
:libraries:facebook:compileLint             
:libraries:facebook:copyReleaseLint UP-TO-DATE  
:libraries:facebook:mergeReleaseProguardFiles UP-TO-DATE  
:libraries:facebook:packageReleaseAidl UP-TO-DATE  
:libraries:facebook:preBuild UP-TO-DATE  
:libraries:facebook:preReleaseBuild UP-TO-DATE  
:libraries:facebook:prepareReleaseDependencies             
:libraries:facebook:compileReleaseAidl UP-TO-DATE  
:libraries:facebook:compileReleaseRenderscript UP-TO-DATE  
:libraries:facebook:generateReleaseBuildConfig UP-TO-DATE  
:libraries:facebook:mergeReleaseAssets UP-TO-DATE  
:libraries:facebook:mergeReleaseResources UP-TO-DATE  
:libraries:facebook:processReleaseManifest UP-TO-DATE  
:libraries:facebook:processReleaseResources UP-TO-DATE  
:libraries:facebook:generateReleaseSources UP-TO-DATE  
:libraries:facebook:compileRelease UP-TO-DATE  
:libraries:facebook:processReleaseJavaRes UP-TO-DATE  
:libraries:facebook:packageReleaseJar UP-TO-DATE  
:libraries:facebook:packageReleaseLocalJar UP-TO-DATE  
:libraries:facebook:packageReleaseRenderscript UP-TO-DATE  
:libraries:facebook:packageReleaseResources UP-TO-DATE  
:libraries:facebook:bundleRelease UP-TO-DATE  
:App Code:prepareComAndroidSupportAppcompatV71800Library UP-TO-DATE  
:App Code:prepareComGoogleAndroidGmsPlayServices3136Library UP-TO-DATE  
:App Code:prepareLatestUpdateLibrariesFacebookUnspecifiedLibrary UP-TO-DATE  
:App Code:prepareDebugDependencies             
:App Code:compileDebugAidl             
:App Code:compileDebugRenderscript             
:App Code:generateDebugBuildConfig             
:App Code:mergeDebugAssets             
:App Code:mergeDebugResources             
:App Code:processDebugManifest             
:App Code:processDebugResources FAILED      

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':App Code:processDebugResources'.
> Failed to run command:
        /Applications/Android Studio.app/sdk/build-tools/android-4.2.2/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-17/android.jar -M /Users/oslinux/Documents/workspace/Appme-android/latest-update/App Code/build/manifests/debug/AndroidManifest.xml -S /Users/oslinux/Documents/workspace/Appme-android/latest-update/App Code/build/res/all/debug -A /Users/oslinux/Documents/workspace/Appme-android/latest-update/App Code/build/assets/debug -m -J /Users/oslinux/Documents/workspace/Appme-android/latest-update/App Code/build/source/r/debug -F /Users/oslinux/Documents/workspace/Appme-android/latest-update/App Code/build/libs/App Code-debug.ap_ --debug-mode --custom-package com.floaty.App --output-text-symbols /Users/oslinux/Documents/workspace/Appme-android/latest-update/App Code/build/symbols/debug
  Error Code:
        139


* Try:    
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 20.268 secs
host-005:App Code oslinux$ 

Executing Gradle with --stacktrace this is the output exception:

 * Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':VMS Code:processDebugResources'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
        at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter.execute(CacheLockReleasingTaskExecuter.java:33)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.execute(ContextualisingTaskExecuter.java:34)
        at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter$1.run(CacheLockAcquiringTaskExecuter.java:39)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
        at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter.execute(CacheLockAcquiringTaskExecuter.java:37)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:282)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:48)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:27)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
        at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
        at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:48)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:39)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        /Applications/Android Studio.app/sdk/build-tools/android-4.2.2/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-17/android.jar -M /Users/oslinux/Documents/workspace/vmsme-android/latest-update/VMS Code/build/manifests/debug/AndroidManifest.xml -S /Users/oslinux/Documents/workspace/vmsme-android/latest-update/VMS Code/build/res/all/debug -A /Users/oslinux/Documents/workspace/vmsme-android/latest-update/VMS Code/build/assets/debug -m -J /Users/oslinux/Documents/workspace/vmsme-android/latest-update/VMS Code/build/source/r/debug -F /Users/oslinux/Documents/workspace/vmsme-android/latest-update/VMS Code/build/libs/VMS Code-debug.ap_ --debug-mode --custom-package com.floaty.vms --output-text-symbols /Users/oslinux/Documents/workspace/vmsme-android/latest-update/VMS Code/build/symbols/debug
Error Code:
        139

        at com.android.ide.common.internal.CommandLineRunner.runCmdLine(CommandLineRunner.java:98)
        at com.android.ide.common.internal.CommandLineRunner.runCmdLine(CommandLineRunner.java:69)
        at com.android.builder.AndroidBuilder.processResources(AndroidBuilder.java:617)
        at com.android.builder.AndroidBuilder$processResources.call(Unknown Source)
        at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.groovy:91)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.groovy:71)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
        at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
        at com.android.build.gradle.tasks.ProcessAndroidResources_Decorated.invokeMethod(Unknown Source)
        at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:526)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:509)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 70 more


BUILD FAILED

Total time: 14.276 secs
host-005:VMS Code oslinux$ 

I'm using Android Studio 0.2.13

How can i solve those problems?

EDIT: this is my build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
        classpath 'com.newrelic.agent.android:agent-gradle-plugin:2.397.0'
    }
}

repositories {
    mavenCentral()
    maven {
        url 'http://www.bugsense.com/gradle/'
    }
}

apply plugin: 'android'
apply plugin: 'newrelic'

dependencies {
    compile 'com.newrelic.agent.android:android-agent:2.397'
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.intellij:annotations:12.+'
    compile 'com.bugsense.trace:bugsense:3.5'
    compile 'com.google.android.gms:play-services:3.1.+'
    compile 'net.hockeyapp.android:HockeySDK:3.0.+'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':libraries:facebook')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }

    signingConfigs {
        release {
            storeFile file("/Users/oslinux/Documents/Chiavi Android/Sv01")
            storePassword "******"
            keyAlias "sv01"
            keyPassword "******"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            debuggable true
            jniDebugBuild false
        }
    }
}

UPDATE

I tried manually executing aapt, getting the full command from the error message that gradle spits, it failed with:

Segmentation fault: 11

But once in a while it runs correctly and creates the package.

No errors other than "Segmentation fault: 11" are shown.

This is the command i'm trying to execute:

"/Applications/Android Studio.app/sdk/build-tools/android-4.2.2/aapt" 
package -vv -f -a --no-crunch 
-I "/Applications/Android Studio.app/sdk/platforms/android-17/android.jar" 
-M "/Users/oslinux/Documents/workspace/app-android/latest-update/App Code/build/manifests/release/AndroidManifest.xml" 
-S "/Users/oslinux/Documents/workspace/app-android/latest-update/App Code/build/res/all/release" 
-A "/Users/oslinux/Documents/workspace/app-android/latest-update/App Code/build/assets/release" 
-m -J "/Users/oslinux/Documents/workspace/app-android/latest-update/App Code/build/source/r/release" 
-F "/Users/oslinux/Documents/workspace/app-android/latest-update/App Code/build/libs/App Code-release.ap_" 
--debug-mode --custom-package com.appandroid.app 
--output-text-symbols "/Users/oslinux/Documents/workspace/app-android/latest-update/App Code/build/symbols/release"

FINAL UPDATE

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:

  • +id in Styles
  • Duplicated resources / libraries
  • unknown, like mine

So it would be useful to: 1. Find a way to identify the real cause of this error 2. Wait for an update to AAPT that returns some error message 3. Write a list of possible common causes.

12
show your build.gradleVarun
@Luca: Interesting finds! Would be great if you add your final update as an answer to make it more visible to others. Also I would be interested in the links you found :)sunadorer
Just did that, i'm trying to find again those links ;)Luca Vitucci
Same problem, and same solution. I had originally started out the project with an actionbar, and then realized using a drawer for main navigation may be a better fit. I kept the original files around (renaming them all from 'main', of course) to port logic over, and in the event I wanted to revert back to using the tabs. Keeping all that in the project caused the same error you listed, and deleting the class, activities, and layouts resolved it for me.JGarrido

12 Answers

23
votes

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.

12
votes

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.

5
votes

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/'

4
votes

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.

2
votes

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!

1
votes

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.

1
votes

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" >
1
votes

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. :)

0
votes

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.
0
votes

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...

0
votes

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

0
votes

run this command in your terminal in respective project.

./gradlew assembleDebug

this will give information about the error.(go line by line to verify)

In my case the error is related to JAR file that i have included in my gradle file.Finally removing the jar file solved the problem.