5

My project can't render the layout in preview. My Android Studio version 3.1.2. Im using API 28. This my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/frame_container">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Hello World"
    android:gravity="center"/>
</android.support.constraint.ConstraintLayout>

It's simple, just to print Hello World to layout, but it can't show. The error like below : Preview error

I search the solve problem, the solution is using API 26. And i try, everything is normal, preview success. But i create Fragment Activity, the problems come back, preview can't show. If you have new solution, please help me!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
syaifulhusein
  • 269
  • 2
  • 8
  • 18

3 Answers3

5

I met the same problem recently despite it being a wizard simple project.

I tried with 23 level (Mashmallow) without any changes. I uninstalled Android Studio, reinstalled it, it made no changes, error was still there...

Then I realized the problem was coming from a dependency (probably recently updated from Google with an error). The solution is to use the previous release.

Go to File -> Project Structure -> Modules app -> Dependencies Tab. The default used by wizard during project creation is com.android.support:appcompat-v7:28.0.0-alpha3

Simply modify to com.android.support:appcompat-v7:27.1.1

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JLC
  • 66
  • 2
  • 2
    This solved it for me. I changed `build.gradle` and used `compileSdkVersion 27` and` `implementation 'com.android.support:appcompat-v7:27.1.1'` Then invalidate caches/restart. – A.W. Jun 16 '18 at 11:20
  • Thanks this worked for me! I am curious why an update to the v7 appcompat library broke rendering and wasn't caught in a unit test when they pushed this update – committedandroider Jul 10 '18 at 06:24
  • Android studio 3.1.4 uses com.android.support:appcompat-v7:28.0.0-rc2 so I solved with @Atara 's solution. For future readers it can be the workaround they're looking for – Matteo Meil Sep 21 '18 at 08:37
5

in app\res\values\styles.xml change

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

to

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

(Render error in Android Studio 3.0 Layout Editor)

Atara
  • 3,523
  • 6
  • 37
  • 56
0

Everything is fine; just clean project and run it again.

Clean project option is under Build .

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
RahulSingh
  • 11
  • 6