未找到样式属性attr / colorSecondary

时间:2017-08-11 12:17:13

标签: android styles

我无法构建我的项目。它显示我attr / colorSecondary未找到错误。

看看我的风格和清单,请告诉我什么是错的。

  

Android工作室版:3.0金丝雀9

     

compileSdkVersion 25

     

buildToolsVersion '25 .0.3'

     

minSdkVersion 17

风格

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorSecondary">@color/secondaryColor</item>
</style>

颜色

 <color name="primaryColor">#fcc425</color>
 <color name="secondaryColor">#e5af17</color>

清单

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

依赖

compile 'com.android.support:appcompat-v7:25.3.1'

错误消息

  

C:\用户\ Raja.gradle \缓存\变换-1 \文件-1.1 \程序兼容性-v7-25.3.1.aar \ 9d599a32a67c8fb41b4e2d36c5f93152 \ RES \值\ values.xml

     

错误:(353,5)样式属性'attr / colorSecondary(又名   com.equitasbank.merchant:attr / colorSecondary)'not found

     

错误:D:\ Android Projects \ Purz Merchant \ Equitas Merchant   的Android \应用\构建\中间体\增量\ mergeLiveDebugResources \ merged.dir \值\ values.xml:609   style属性'attr / colorSecondary(又名   com.equitasbank.merchant:attr / colorSecondary)'not found

     

错误:java.util.concurrent.ExecutionException:   com.android.builder.internal.aapt.AaptException:AAPT2链接失败:

     

错误:com.android.builder.internal.aapt.AaptException:AAPT2链接   失败:

     

错误:任务':app:processLiveDebugResources'的执行失败。   无法执行aapt

控制台错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processLiveDebugResources'.
> Failed to execute aapt

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processLiveDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.tooling.BuildException: Failed to execute aapt
    at com.android.build.gradle.tasks.ProcessAndroidResources.invokeAaptForSplit(ProcessAndroidResources.java:583)
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:281)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)

请帮助。在此先感谢:)

3 个答案:

答案 0 :(得分:12)

您需要在AS 3.0中的项目中明确定义'attr'类型

例如

<item type="attr" name="colorPrimary">@color/primaryColor</item>

文档:https://web.archive.org/web/20180518223123/https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration

另外,不要忘记在attrs.xml中定义属性。 例如

<declare-styleable name="Theme">
    <attr name="colorPrimary" format="color|reference" />
</declare-styleable>

答案 1 :(得分:3)

您收到的错误告诉您问题是名为Theme.AppCompat.Light.NoActionBar的主题不包含属性secondaryColor。所以你基本上要做的就是为不存在的属性赋值。

根据您的需要,您可以选择现有属性(通过在item name = ""中按空白引号内的CTR + SPACE来获取它们的最简单方法),或者只是添加常规颜色并直接在布局中使用它或Java代码。

答案 2 :(得分:1)

添加汽车库后出现类似的问题。

AAPT: error: style attribute 'attr/listChoiceIndicatorSingleAnimated (aka ****debug:attr/listChoiceIndicatorSingleAnimated)' not found.

缺少的属性在

中可用
implementation 'androidx.preference:preference:1.1.1'

只需检查缺少的属性在哪个库中可用,然后将其添加为dep。