Tupaschoal Tupaschoal - 1 year ago 172
Android Question

Android studio not rendering layout preview

I've been using Android Studio 0.8.6 to develop apps and am having problems with the layout preview when using API21. I get the following error:

Rendering Problems:
The following classes could not be instantiated:
- android.support.v7.widget.Toolbar

I have SDK Build tools up-to-date (21.0.2) as well as the full API21 downloaded and installed. My targetSDKVersion is set to 21 on the gradle file.
If I change the preview to render with API20, everything seems fine. Exception details are provided below.


Exception Details java.lang.ClassNotFoundException:
android.support.v4.content.ContextCompatApi21   at
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)   at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)   at
  at android.support.v7.widget.Toolbar.(Toolbar.java:248)   at
android.support.v7.widget.Toolbar.(Toolbar.java:190)   at
java.lang.reflect.Constructor.newInstance(Constructor.java:408)   at
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)   at

Answer Source

The most recent version of Android Studio is 0.8.14 and this fixes a number of issues with API21. Note that as per the Android Studio 0.8.12 announcement (under 'No patches'):

We've found and fixed several significant bugs in the patching mechanism. One of these bugs meant that upgrading to a new version, while resulting in a functionally identical installation, would also result in slightly different binary contents (for example, some timestamps inside .jar files would differ). This meant that the actual binary signatures would not match, which broke for example the application signature checks.

We have now found and fixed that bug, but because there are many different binary variations of a given previous version, we cannot create a single patch to update to the new version. Therefore, for this version we will require a full download of the IDE. From this version forward we should be able to accurately install updates while preserving the application signatures.

So you'll need to manually install the latest build.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download