Android Studio 2.3 Canary 3. Support libraries 25.1.0.
Layout previews are totally broken. Anything that contains a support-related View seems to break during preview.
In all cases, this is the beginning of the stack:
Exception Details java.lang.NoSuchFieldError: ViewBackgroundHelper at android.support.v7.widget.AppCompatBackgroundHelper.loadFromAttributes(AppCompatBackgroundHelper.java:46) at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:63) at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56) ....
Doesn’t matter what the layout is like, I’m now getting this bloody
ViewBackgroundHelper-related issue come up. Doesn’t seem to matter what kind of layout is is or what views are in it.. anything that seems to go through AppCompat hits this error in the preview.
Have never seen this before. Previously had Android Studio 2.3 Canary 2 + Support libs 25.0.1.
Seems like it’s just not possible to ever upgrade Android Studio or its support libs without spending hours on this type of stuff, hey?
Thanks for any hints, thanks-
Looks like I’m not the only one. Found a bug logged here, starred by many people already:
Still an issue with AS 2.3 Beta 1. Still can’t see my layouts. Same
java.lang.NoSuchFieldError: ViewBackgroundHelper error everywhere.
According to the issue tracker, as of Jan 10, 2017:
For those of you using the 2.3.0-beta1 Gradle plugin could you please
disable the build cache by adding
gradle.propertiesfile and let us know if that fixes the issue
for you. After adding the line to your gradle.properties, please
rebuild the project.
Has proven to solve the issue for some users.
Everything works now.
- I upgraded today to the newest Android Studio: 2.3 Beta 3
- I was prompted to update to the latest
Restarted, invalidated, rebuilt; everything is finally rendering perfectly in the preview pane for the first time in 6 weeks.
Looks like they’ve fixed it. Finally.
I filed the issue on the tracker. Other participants have discovered that removing some other non-android library dependencies causes the issue to go away. Based on that I found a solution (reposted from the issue thread):
Additional information after investigating this further:
Android Studio 2.2.3
Build #AI-145.3537739, built on December 2, 2016
JRE: 1.8.0_76-release-b03 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Support libs: 25.1.0
Build tools: 25.0.2
After being able to reproduce this on the above studio version (2.2.3 Stable), I began removing other library dependencies based on the information provided by others in this thread. After removing the Calligraphy library (https://github.com/chrisjenx/Calligraphy) and associated code, the layout preview began to work correctly again.
Interestingly enough, I was able to re-add the Calligraphy library and the layout preview continued working. Maybe this points to some sort of caching problem with the android gradle plugin?
For others encountering this problem, I suggest the following:
1. Pinpoint the library causing the problem
2. Remove the library dependency and associated code
3. Do a full clean and build
4. Verify the layout preview works
5. Re-add the library dependency
6. Do a full clean and build
7. Verify the layout preview works
Note: I suspected Calligraphy was causing the problem because it relies on a custom xml attribute called “fontPath”, as well as some Context manipulation. If you have any libraries that do View manipulation under the hood, I suggest removing those first.
Change your AppTheme style to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> </style>
I have a Solution the problem is not the version of Android Studio.
The problem is the Gradle Version go back to stable version 2.2.3 it work for me after a few test. It is a Bug in gradle beta version and it is already reported to google.
I resolved this problem in the next steps
- Remove <project>/<module>/build/build/intermediates/exploded-aar
- Rebuild project
- Check that there is only one version support-library in exploded-aar