Android Studio 2.3 Beta 1 + Support 25.1.0 = Preview broken

心不动则不痛 提交于 2019-12-04 10:19:51

问题


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

.. Etc.

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-

UPDATE

Looks like I'm not the only one. Found a bug logged here, starred by many people already:

https://code.google.com/p/android/issues/detail?id=230183

UPDATE 2

Still an issue with AS 2.3 Beta 1. Still can't see my layouts. Same java.lang.NoSuchFieldError: ViewBackgroundHelper error everywhere.


回答1:


According to the issue tracker, as of Jan 10, 2017:

https://code.google.com/p/android/issues/detail?id=230183

For those of you using the 2.3.0-beta1 Gradle plugin could you please disable the build cache by adding

android.enableBuildCache=false

to your gradle.properties file and let us know if that fixes the issue for you. After adding the line to your gradle.properties, please rebuild the project.

Thanks.

Has proven to solve the issue for some users.




回答2:


Everything works now.

  1. I upgraded today to the newest Android Studio: 2.3 Beta 3
  2. I was prompted to update to the latest com.android.tools.build:gradle:2.3.0-beta3

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.




回答3:


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.




回答4:


Change your AppTheme style to this:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
</style>



回答5:


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.




回答6:


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


来源:https://stackoverflow.com/questions/41134107/android-studio-2-3-beta-1-support-25-1-0-preview-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!