0

My project built with no errors, but when I try to run my app on my phone or on the emulator I get the error: "Failed to complete Gradle execution. Cause: ".

I looked at this answer: Android Studio: failed to complete gradle execution, cause is empty. I tried to do a clean but that didn't work. I tried to change the GradleVM setting, but that didn't work either. I then read in one of the answers that there may be an error in one of the resource files. I have found an error in a resource file:

1.

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false"
    >
    <item
        android:drawable="@drawable/loading_01"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_02"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_03"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_04"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_05"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_06"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_07"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_08"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_09"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_10"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_11"
        android:duration="100"
        />

    <item
        android:drawable="@drawable/loading_12"
        android:duration="100"
        />

</animation-list>

The error I get here is "Element animation-list doesn't have required attribute android:layout_height and layout_width". I followed the example given in the documentation (https://developer.android.com/guide/topics/graphics/drawable-animation.html) but it still gives me this error. I didn't think that animation-lists needed a height and width.... am I wrong? Any help would be great! Thank you.

UPDATE:

Here is where it is used in code:

    if (isPrintJob)
    {   
        image_printJobThumb.setImageResource(R.layout.animation_loading);
        ....
    }
    else 
    {
        image_cutJobThumb.setImageResource(R.layout.animation_loading);
    }
Community
  • 1
  • 1
erics
  • 111
  • 11

1 Answers1

0

You cannot setImageResource with passing argument, which is layout, you must set drawable.

Depends on API version it will be:

image_printJobThumb.setImageResource(getResources().getDrawable(R.drawable.animation_loading,null));

or

image_printJobThumb.setImageResource(getResources().getDrawable(R.drawable.animation_loading));

Check this: http://developer.android.com/reference/android/widget/ImageView.html#setImageResource%28int%29

Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
  • This app that I am working on is already available. It wasn't until I migrated over to Android Studio that I have come across this. Any idea why? Are animated-lists considered "drawable"? Is the solution as simple as putting the xml file in the drawable directory in place of the layout directory? – erics Jul 04 '15 at 03:21
  • Yes. Android Studio is very strict about it. Every `xml` file in `layout` directory it threats as layout, which needs `android:layout_height` and `android:layout_width`. So move your `animation_loading.xml` to `drawable` folder and `setImageResource` as I said in answer. Tell me the result, it should help. – Damian Kozlak Jul 04 '15 at 10:29
  • Ok for some reason it initially got rid of the errors, but then I tried to do a project clean and it gave me the same error failure to complete gradle execution. I then invalidated the caches and restarted AS. Now my project is unable to resolve the symbol 'R', in all of my files..... whats wrong? any ideas? – erics Jul 04 '15 at 17:20
  • i just tried to sync and it failed with the same error as above: failure to complete gradle execution. cause: ..... – erics Jul 06 '15 at 15:17
  • Ok, I found the source of that error. When I moved the xml file to the drawable folder, there were still some references to it within the layout folder, in other xml files. So now it builds with no errors. However, when I try to run the app on my device, it throws the same error that it failed to complete gradle execution. Any ideas? – erics Jul 06 '15 at 17:07
  • Are you able to place your project on github, for example, so I would be able to pick it and check by myself? – Damian Kozlak Jul 06 '15 at 17:08
  • Unfortunately, I am unable to do so because it is not my property to post (I can ask though). I am able to do some type of Skype call and share my screen with you. – erics Jul 06 '15 at 19:04
  • I fixed the issue by upgrading Android Studio to 1.3 beta – erics Jul 08 '15 at 15:08