Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style attribute attr/colorSecondary not found

Tags:

android

styles

I can't build my project. It shows me attr/colorSecondary not found error.

These are my styles and manifest files:

Android studio version: 3.0 canary 9

compileSdkVersion 25

buildToolsVersion '25.0.3'

minSdkVersion 17

Style

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

Colors

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

Manifest

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

Dependency

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

Error Message

C:\Users\Raja.gradle\caches\transforms-1\files-1.1\appcompat-v7-25.3.1.aar\9d599a32a67c8fb41b4e2d36c5f93152\res\values\values.xml

Error:(353, 5) style attribute 'attr/colorSecondary (aka com.equitasbank.merchant:attr/colorSecondary)' not found

Error:D:\Android Projects\Purz Merchant\Equitas Merchant Android\app\build\intermediates\incremental\mergeLiveDebugResources\merged.dir\values\values.xml:609 style attribute 'attr/colorSecondary (aka com.equitasbank.merchant:attr/colorSecondary)' not found

Error:java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.AaptException: AAPT2 link failed:

Error:com.android.builder.internal.aapt.AaptException: AAPT2 link failed:

Error:Execution failed for task ':app:processLiveDebugResources'. Failed to execute aapt

Console Error

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)
like image 442
Raja Avatar asked Aug 11 '17 12:08

Raja


3 Answers

You need to explicitly define the 'attr' type in the item in AS 3.0

eg.

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

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

Also, don't forget to define the attribute in your attrs.xml. eg.

<declare-styleable name="Theme">
    <attr name="colorPrimary" format="color|reference" />
</declare-styleable>
like image 137
Jeremy Avatar answered Oct 15 '22 07:10

Jeremy


The error you're getting is telling that the problem is that Theme named Theme.AppCompat.Light.NoActionBar doesn't contain attribute secondaryColor. So what you're basically trying to do is assign value to non-existent attribute.

Depending on your needs, you can choose from existing attributes (easiest way to get them is by pressing CTR + SPACE inside empty quotes in item name = "") , or just add regular color and use it directly in the layout or Java code.

like image 5
Gotiasits Avatar answered Oct 15 '22 06:10

Gotiasits


Had the similar problem after I added a car lib.

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

That missing attribute was available in

implementation 'androidx.preference:preference:1.1.1'

Just check which lib the missing attribute is available in and add that as dep.

like image 1
cgr Avatar answered Oct 15 '22 06:10

cgr