我卸载了以前版本的android并且只安装了version3.0.1我在android studio scratch中创建了一个新的应用程序我没有修改任何代码但是当我尝试构建项目时我得到以下错误
Error:resource style/Theme.AppCompat.Light.DarkActionBar (aka com.example.android.my:style/Theme.AppCompat.Light.DarkActionBar) not found.
C:\AndroidStudioProjects\MyAPP\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Error:(101) error: style attribute 'attr/colorPrimary (aka com.example.android.my:attr/colorPrimary)' not found.
Error:(102) error: style attribute 'attr/colorPrimaryDark (aka com.example.android.com.example.android.my:attr/colorPrimaryDark)' not found.
Error:(103) error: style attribute 'attr/colorAccent (aka com.example.android.my:attr/colorAccent)' not found.
Error:(101) style attribute 'attr/colorPrimary (aka com.example.android.my:attr/colorPrimary)' not found.
Error:(102) style attribute 'attr/colorPrimaryDark (aka com.example.android.my:attr/colorPrimaryDark)' not found.
Error:(103) style attribute 'attr/colorAccent (aka com.example.android.my:attr/colorAccent)' not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
这是我的build.gradle
文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.android.my"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'p
roguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
}
这是我的values.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr format="reference" name="constraintSet"/>
<attr format="integer" name="layout_constraintBaseline_creator"/>
..... some codes here ....
<attr format="dimension" name="layout_goneMarginTop"/>
<attr name="layout_optimizationLevel">
<flag name="none" value="1"/>
<flag name="all" value="2"/>
<flag name="basic" value="4"/>
<flag name="chains" value="8"/>
</attr>
<color name="colorAccent">#FF4081</color>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<declare-styleable name="ConstraintLayout_Layout"><attr name="android:orientation"/><attr name="android:minWidth"/>
.... some more attributes here ....
<string name="app_name">MyAppName</string>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
似乎这个错误是android studio中的一些奇怪的行为我已经使缓存失效并重新启动了项目但问题仍然存在, 我该如何解决这个问题?
答案 0 :(得分:4)
如果任何人阅读此书都遇到相同的问题,这是我最近发生的,这是由于xml标头被错误地写入了两次:
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?> <!-- Remove this one -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/mug_blue"/>
<corners android:radius="@dimen/featured_radius" />
</shape>
我遇到的错误与该文件完全无关,因此很难找到。只需确保所有新的xml文件都没有类似这样的错误(因为它不会显示为错误)。
答案 1 :(得分:2)
您的gradle文件中有重复的行。休闲是一样的
compile 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
删除以下行:
compile 'com.android.support:appcompat-v7:26.1.0'
答案 2 :(得分:0)
我在执行android tutorial on support libraries
时收到此错误问题出在您的styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
**<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>**
</style>
只需删除上面的这4个项目行,它将起作用。 也许是因为您使用的是Compat库,但未定义主题。
答案 3 :(得分:0)
您不需要更改依赖项中的任何内容。如果要组合多模块,也许它们冲突,则必须添加前缀“ android:”。在这种情况下,我认为您只需更新文件styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
</style>
</resources>
与我的资料来源一起使用。