Android resource linking failed. attribute iconGravity (aka com.bignerdranch.android.geoquiz:iconGravity) not found

Hello everyone,
I’m trying to add an icon to my GeoQuiz app like it described in Chapter 2, “Adding an Icon”. But when I’m trying to run my app it fails with error:

Android resource linking failed
com.bignerdranch.android.geoquiz.app-mergeDebugResources-48:/layout/activity_main.xml:43: error: attribute iconGravity (aka com.bignerdranch.android.geoquiz:iconGravity) not found.
error: failed linking file resources.

In activiy_main.xml everything like in the book.

I guess that something is wrong in my dependencies:

dependencies {

    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

    implementation 'androidx.core:core-ktx:1.10.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
    implementation 'androidx.activity:activity-compose:1.7.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}

Could you please help me to solve the problem?

1 Like

It seems that the issue is that I am trying to add attribute iconGravity on Button which doesn’t support it . iconGravity is supported by com.google.android.material.button.MaterialButton so if I want to use iconGravity , I have to use MaterialButton, right?

You do not need to use MaterialButton directly in order to get the functionality of it in your app. I think your problem might be that you do not have the old Material design library in your dependencies. I think you used a different project template than the book when creating your app. Follow the directions here: Material Design

And see if that works.

Thanks! I removed all unnecessary dependencies. Also removed compose true from buildFeatures and it worked

I was using Ladybug 2.1 and the 5th edition of the book. I had this very same iconGravity issue exactly the same as the OP posted. I tried all the possible fix I could found but none fixed.

The exact error I got was
Android resource linking failed
com.bignerdranch.android.geoquiz.app-mergeDebugResources-43:/layout/activity_main.xml:49: error: attribute iconGravity (aka com.bignerdranch.android.geoquiz:iconGravity) not found.
error: failed linking file resources.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:app:processDebugResources’.

A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
Android resource linking failed
com.bignerdranch.android.geoquiz.app-mergeDebugResources-43:/layout/activity_main.xml:49: error: attribute iconGravity (aka com.bignerdranch.android.geoquiz:iconGravity) not found.
error: failed linking file resources.