Android Studio 3.2.1:加载旧项目后布局预览不适用于所有项目

Android Studio 3.2.1: Layout preview not working for all projects, after loading an old project

我需要查看一个旧项目,该项目要求我下载构建工具版本 23.0.0 以获得一些代码,我将其加载到我更新的 android 工作室中。

现在布局文件不会在我设计的任何工作项目上或在加载旧项目之前在新项目上显示任何预览 这是我在开始新项目时遇到的错误:

NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts.

The following classes could not be found:
- ProjectState (Fix Build Path, Edit XML) - component (Fix Build Path, Edit XML) - config (Fix Build Path, Edit XML) - configuration (Fix Build Path, Edit XML) - configurations (Fix Build Path, Edit XML) - device (Fix Build Path, Edit XML) - entry (Fix Build Path, Edit XML) - expand (Fix Build Path, Edit XML) - file (Fix Build Path, Edit XML) - item (Fix Build Path, Edit XML) - leaf (Fix Build Path, Edit XML) - list (Fix Build Path, Edit XML) - option (Fix Build Path, Edit XML) - path (Fix Build Path, Edit XML) - project (Fix Build Path, Edit XML) - projectState (Fix Build Path, Edit XML) - projects_view (Fix Build Path, Edit XML) - select (Fix Build Path, Edit XML) - shared (Fix Build Path, Edit XML) - state (Fix Build Path, Edit XML) - system (Fix Build Path, Edit XML) - tree_state (Fix Build Path, Edit XML) Tip: Try to build the project. Tip: Try to refresh the layout.

Render Problem: Failed to load AppCompat ActionBar with unknown error

Failed to instantiate one or more classes
The following classes could not be instantiated: - android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.

Image shows MainActivity as Unresolved class in tool:context=".MainActivity"

我尝试解决这个问题的方法:

  1. Invalidate cache and restart
  2. Clean and Rebuild project
  3. Change sdk version from 28.0.0 to 27.1.1 (I've been working on a project with sdk 28.0.0 earlier without any issue before loading that old project)
  4. Reinstalled entire android studio, deleting caches except sdk
  5. Force refresh layout
  6. Set build-tools version in settings to 28.0.3

build.gradle(模块:应用):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "<Name Removed>"
    minSdkVersion 28
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

build.gradle(项目:项目名称)

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
}
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

合并清单

Manifest Sources 

app main manifest (this file)
 Other Manifest Files (Included in merge, but did     not contribute any elements) animated-vector-    drawable:28.0.0 manifest, appcompat-v7:28.0.0 manifest,     support:asynclayoutinflater:28.0.0 manifest,     constraint-layout:1.1.3 manifest,     support:coordinatorlayout:28.0.0 manifest,     support:cursoradapter:28.0.0 manifest,     support:customview:28.0.0 manifest,     support:documentfile:28.0.0 manifest,     support:drawerlayout:28.0.0 manifest,     support:interpolator:28.0.0 manifest,     lifecycle:livedata:1.1.1 manifest, livedata-core:1.1.1     manifest, support:loader:28.0.0 manifest,     support:localbroadcastmanager:28.0.0 manifest,     support:print:28.0.0 manifest, core:runtime:1.1.1     manifest, lifecycle:runtime:1.1.1 manifest,     support:slidingpanelayout:28.0.0 manifest, support-    compat:28.0.0 manifest, support-core-ui:28.0.0     manifest, support-core-utils:28.0.0 manifest, support-    fragment:28.0.0 manifest, support-vector-    drawable:28.0.0 manifest,     support:swiperefreshlayout:28.0.0 manifest,     support:versionedparcelable:28.0.0 manifest,     lifecycle:viewmodel:1.1.1 manifest,         support:viewpager:28.0.0 manifest 

我遇到了与 Android Studio 3.2.1 类似的问题。项目构建成功,没有问题,但我的布局预览视图中没有显示任何内容。已尝试 clean/rebuild、使 cache/restart、close/open 项目无效、强制刷新布局、将项目与 gradle 文件同步。唯一帮助我恢复布局设计预览的是删除 .AndroidStudio3.2\system.

中的 caches 文件夹