Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android生成错误链接资源失败_Android_Android Studio - Fatal编程技术网

android生成错误链接资源失败

android生成错误链接资源失败,android,android-studio,Android,Android Studio,我卸载了以前版本的android,只安装了版本3.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:\AndroidStudio

我卸载了以前版本的android,只安装了版本3.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>

..... 这里有一些代码。。。。
#FF4081
#3F51B5
#303F9F
.... 这里还有一些属性。。。。
MyAppName
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
这个错误似乎是android studio中的一些奇怪行为,我已经使缓存失效并重新启动了项目,但问题仍然存在,
我应该如何解决这个问题

您的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'

如果有人读到这篇文章也有同样的问题,我最近也遇到过这种情况,这是因为错误地编写了两次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文件都没有类似这样的错误(因为它不会显示为错误)。

我在执行

问题出在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>
<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>

**
@颜色/原色
@颜色/原色暗
@颜色/颜色重音**
只需删除上面的4个项目行,它就会工作。
可能是因为您使用的是Compat库,并且主题没有定义。

您不需要更改依赖项中的任何内容。如果您要组合多个模块,可能它们有冲突,您必须添加前缀“android:”。在这种情况下,我认为您只需更新文件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>
<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>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音

它与我的源代码一起工作。

尝试使用android studio菜单中的“清理”然后“重建”命令。您的Minsdk版本是21。您可以使用
主题、材质、灯光、暗色操作条
中的
对我来说非常有魅力。谢谢@P FusterHi,@HimanshuRawat事实上你应该在你的项目中进行更改,而不是在问题中:D