Preview is unavailable until a successful build

Viewed 52908

I tried fixing this for ages now, but I don't know what to do. How do I get it to display a preview? Here is a screenshot of the code:

img

8 Answers

From Menu Open file option and choose option Close Project.

then restart your project android.

this will resolve your issue.

The attached screenshot shows your Project is not sync properly. Here are some of the possible steps:

  1. Use Sync Project with Gradle Files for more Here is answer with more detail.
  2. If you made huge changes to project or changed package names etc. use rebuild
    In menu Build => Rebuild Project.
  3. Preview may not show if an API is selected that is not properly installed. Check Answer here.

One of the above should fix the problem. If none of the above work try restarting IDE (Android Studio).

Close the android studio and reopen the project again. If not work replace all 'compile' with 'implementation' from build.gradle file. Because it is obsolete now and will be removed at the end of 2018. I solved this kind of problem like that.

I tried above answers. But, sometimes they work and sometimes not.

I tried -

File -> Invalidate Caches/ Restart -> Invalidate and restart

And it always works for me.

I do this to solved the problem:

  1. type Ctrl + Shift + A to open the "Actions" search window

  2. input "Sync Project with Gradle Files" , then type Enter

  3. wait for Sync finished

Related