Cannot build android project using Android Studio - Gradle 1.7

后端 未结 12 1205
抹茶落季
抹茶落季 2020-12-05 17:06

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

相关标签:
12条回答
  • 2020-12-05 17:53

    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 讨论(0)
  • 2020-12-05 17:53

    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 讨论(0)
  • 2020-12-05 17:53

    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.

    0 讨论(0)
  • 2020-12-05 17:59

    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.

    0 讨论(0)
  • 2020-12-05 18:04

    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.

    0 讨论(0)
  • 2020-12-05 18:06

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

    0 讨论(0)
提交回复
热议问题