【发布时间】:2019-04-16 22:56:12
【问题描述】:
我需要查看一个旧项目,该项目需要我下载构建工具版本 23.0.0 以获得一些代码,然后我将它加载到我更新的 android studio 中。
现在布局文件不会在我设计的任何工作项目上或在加载旧项目之前的新项目上显示任何预览 以下是我在开始一个新项目时遇到的错误:
NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts.
和
找不到以下类:
- ProjectState(修复构建路径,编辑 XML) - 组件(修复构建路径,编辑 XML) - 配置(修复构建路径,编辑 XML) - 配置(修复构建路径,编辑 XML) - 配置(修复构建路径,编辑 XML) - 设备(修复构建路径,编辑 XML) - 条目(修复构建路径,编辑 XML) - 展开(修复构建路径,编辑 XML) - 文件(修复构建路径,编辑 XML) - 项目(修复构建路径,编辑 XML) - 叶(修复构建路径,编辑 XML) - 列表(修复构建路径,编辑 XML) - 选项(修复构建路径,编辑 XML) - 路径(修复构建路径,编辑 XML) - 项目(修复构建路径,编辑 XML) - projectState(修复构建路径,编辑 XML) - projects_view(修复构建路径,编辑 XML) - 选择(修复构建路径,编辑 XML) - 共享(修复构建路径,编辑 XML) - 状态(修复构建路径,编辑 XML) - 系统(修复构建路径,编辑 XML) - tree_state(修复构建路径,编辑 XML) 提示:尝试构建项目。提示:尝试刷新布局。
还有
渲染问题:无法加载 AppCompat ActionBar 并出现未知错误
和
无法实例化一个或多个类
无法实例化以下类: - android.support.v7.app.WindowDecorActionBar(打开类,显示异常,清除缓存) 提示:在自定义视图中使用 View.isInEditMode() 可跳过代码或在 IDE 中显示示例数据。如果这是意外错误,您也可以尝试构建项目,然后手动刷新布局。
Image shows MainActivity as Unresolved class in tool:context=".MainActivity"
我尝试解决此问题的方法:
- 使缓存失效并重新启动
- 清理并重建项目
- 将 sdk 版本从 28.0.0 更改为 27.1.1(我一直在使用 sdk 28.0.0 进行项目,在加载之前没有任何问题 旧项目)
- 重装整个android studio,删除sdk以外的缓存
- 强制刷新布局
- 将设置中的构建工具版本设置为 28.0.3
build.gradle(模块:app):
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(project:project-name)
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
【问题讨论】:
-
你的项目同步了吗?
-
是的,先生,我有
-
在您的 XML 中您忘记设置任何视图的宽度或高度,这就是您收到此消息并发布您的 xml 的原因。
-
其实我没有错过任何属性,我已经完成的项目像魅力一样工作现在不加载布局预览,但当应用程序在手机或模拟器上运行时工作正常跨度>
-
删除xml中的工具,然后检查。
标签: android xml android-studio layout preview