1

I just upgraded Android studio to the latest version :

Android Studio 3.2.1 Build #AI-181.5540.7.32.5056338, built on October 9, 2018 JRE: 1.8.0_152-release-1136-b06 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

and this meant also an update for the build tools to 28.0.3 . Since then I am not able to compile my project that was OK.

I am stuck with an error

error: cannot find symbol variable radio_animator

This error points to my java file where I try to get AnimationDrawable from resource xml file:

ContextCompat.getDrawable(this, R.drawable.radio_animator) 

Before the upgrade all worked fine...

Now the same resource seems not to be visible as a resource. I did not change a single letter in code..., I did not move or replace the xml resource file.

When I click the R.drawable.radio_animator in the editor it opens the animation list xml so it is visible for the editor...

I checked Google documentation on AnimationDrawable and I adhere to the example provided, no change.

Not sure what I am doing wrong . Is there any (not yet) documented change coming with the latest Android studio upgrade and the latest build tools?

I am targeting the app yet to Android 7.0, API 24 and perhaps there is some incompatibility.

I also tried to setBackgroundResource to a view and get it from there as shown here: Google documentation

The same result with error.

The only solution I found so far was removing the part of the code referring to the AnimationDrawable resource getter and I can compile the app with the loss of animation functionality as a result :-)

Any hint ?

Thanks

My animation list xml file is defined like: enter image description here

and it resides in res/drawable as per documentation

Majo
  • 423
  • 4
  • 14
  • Resource suddenly missing is usually fixed by performing a clean build. Did you try to rebuild your project? Go to Build -> Rebuild Project. That will clean and build the project again. Let's know if the issue still happens after that – guipivoto Oct 22 '18 at 16:29
  • @W0rmH0le yes, I did also clean build several times... as mentioned, removing this part of the code helps. Adding it back raises the same issue with missing symbol – Majo Oct 22 '18 at 17:38
  • "xmlns:android="http://schemas.android.com/apk/res/android"" is duplicated in radio_animator.xml. Could you please test again after removing the duplicated line? – guipivoto Oct 22 '18 at 18:00
  • that one is my fault/typo , I was cleaning up the example and moved this part to start when I was writing this question but left it at the end too... It has no impact. I deleted the second one and still the same result ;-) Is there a way to get more detailed info why the symbol is missing? (Compilation failed; see the compiler error output for details-> error: cannot find symbol variable radio_animator. ) – Majo Oct 22 '18 at 19:36

1 Answers1

1

Despite I could not figure out the exact reason, I found a workaround solution for this case.

I tried to create a new app in the new environment just to test the AnimationDrawable functionality using exact code and files from my failing project. This worked well. I noticed that the resource gets a positive resource id integer, while my failing app has a negative integer id. I could not find this is in R.java.class neither in my failing app.

When I replaced the drawable XML with an existing jpg recourse for test the compilation finished w/o error and the resource got a positive ID. This hinted me to

drop this xml to ALL density folders of the drawable res (drawable-hdpi, etc. folders)

This helped the project to be compiled and my animation drawable xml was suddenly discovered by compiler and assigned it a positive integer ID and could be found in R.java too.

There seems to be some logic error when you port your multiple density/ older Android version supported projects to the new environment . Even "Clean Project" would not solve the issue as it did in the past, and there is something in the folders left from older compile methods that cause the drawable resource unrecoverable

Strange enough that you do not have to add the xml to all density folders in a clean new project.

So either you build a scratch new project in the latest Studio, or in case the project is already robust (as in my case) you spend hours with test fail-success experiments losing your newly grayed hair...

So if you are in doubt if you should already download the latest updates to your studio, do it in a testing pc before you end up with sleepless nights.

Majo
  • 423
  • 4
  • 14