Android gradle : Error No resource found that matc

2019-07-22 05:33发布

问题:

I tried to migrate my android project from Maven to Gradle then i have this error:

Gradle: No resource found that matches the given name: attr 'mdActiveIndicator'.

Thanks for your help to find a solution.

This is My Project structure:

MediaProject
   build.gradle (%1)
   settings.gradle  (%2)
   HoloCircleSeekBar
       build.gradle (%3)
       src/main/res/values
           attrs.xml  (%4)
   MediaAppli
       telecommande
           build.gradle (%5)
           src/main/res/values
          styles.xml (%6)

content of build.gradle in MediaProject (%1)

allprojects {
    repositories {
        mavenCentral()
    }
}

content of settings.gradle in MediaProject (%2)

include ':HoloCircleSeekBar',':MediaAppli:telecommande'

content of build.gradle in HoloCircleSeekBar (%3)

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4'
        }
    }

apply plugin: 'android-library'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

content of attrs.xml in telecommande (%4)

<resources>
    <attr name="menuDrawerStyle" format="reference" />
    <declare-styleable name="MenuDrawer">
        <attr name="mdMenuSize" format="dimension" />
        <attr name="mdActiveIndicator" format="reference" />
    </declare-styleable>
</resources>

content of build.gradle in telecommande (%5)

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "http://repo1.maven.org/maven2"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(':HoloCircleSeekBar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

content of styles.xml in telecommande (%6)

  <style name="MenuDrawerStyle.Right" parent="MenuDrawer.Widget">
        <item name="mdActiveIndicator">@drawable/menu_arrow_right</item>
        <item name="mdMenuSize">150dp</item>
    </style>

回答1:

If you are using custom attributes for a gradle library then don't forget to mark it as such. The gradle build file of the library needs:

apply plugin: 'android-library'

instead of

apply plugin: 'android'

Not really sure why I couldn't use the attributes, but it works now.



回答2:

My problem was my project and it's library have two declare-styleable with same name, my project's declare-styleable overrided library's declare-styleable.

That's why error

gradle : Error No resource found that matches the given name: attr

is given. (the attr of library's declare-styleable has been overrided)



回答3:

My problem is solved,

i had a dependancy on maven APKlib and not an aar lib.