小结
最近Android应用开发中碰到的几个问题,进行了解决。
问题及解决
One or more layouts are missing the layout_width or layout_height attributes
渲染问题: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts.
参考Stackoverflow: Rendering Problems NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts,此种问题有建议是清除缓存。
最终的解决办法是加上缺少的属性。
导入库(Library)
首先导入库,File ->Project Structure -> App-> dependencies -> + ->add library
,接下来在build.gradle
里添加dependencies
。
dependencies {
// Internal application-level dependencies
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Internal application library/module dependencies
implementation project(':libPrinter')
// Internal application pre-built library/module dependencies
implementation project(':libraries:libInquiry')
...
以下省略
Task ‘wrapper’ not found in project ‘:app’
报错: Task 'wrapper' not found in project ':app'
解决办法,在相应的build.gradle里添加:
task wrapper(type: Wrapper){
gradleVersion = '7.2'
}
Task ‘prepareKotlinBuildScriptModel’ not found in project ‘:app’
报错:Task 'prepareKotlinBuildScriptModel' not found in project ':app'
解决办法,在相应的build.gradle里添加:
task prepareKotlinBuildScriptModel {
}
error: resource color类型错误
报错: error: resource color/purple_500 not found
解决办法,在color.xml中把颜色类型添加上:
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
参考
Stackoverflow: Rendering Problems NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts
Stackoverflow: access jar in project from imported library – gradle / android studio
Stackoverflow: How do I fix this error: Task ‘wrapper’ not found in project ‘:app’
Stackoverflow: Task ‘prepareKotlinBuildScriptModel’ not found in project ‘:app’
CSDN: AAPT: error: resource color类型错误