Sushil Kadu
Sushil Kadu

Reputation: 21

Gradle : Error retrieving parent for item: No resource found that matches the given name '@style/SomeTheme'

I've a library project which has java source and resources.

In my application I'm referring the resources from library project. Everything is working fine, but as soon as I add product flavours in library project I get following error.

Error:(1) Error retrieving parent for item: No resource found that matches the given name '@style/SomeTheme'.

Please see the flavours I added.

productFlavors {
    production {
    }

    staging {
    }
}

If I remove these flavours, things are working fine.

What other things should I do to make sure resources are available to application project when new flavours are added to library project ?

I do not want to add defaultPublishConfig "dev1Production" entry to library project.

What else can I do to fix this problem ?


build.gradle of library project

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

//    defaultPublishConfig "dev1Debug"
//    publishNonDefault true

    productFlavors {
        production {
        }

        staging {
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
}

style.xml from library project

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="SomeAppTheme" parent="@style/SomeTheme">

        <!-- Customize your theme here. -->
        <item name="android:windowDisablePreview">true</item>
    </style>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="SomeThemeBaseJW" parent="@style/Theme.AppCompat.Light">

        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="SomeTheme" parent="@style/SomeThemeBaseJW" />

    <style name="Theme.Translucent.NoTitleBar" parent="@android:style/Theme.Translucent.NoTitleBar">

        <!-- Customize your theme here. -->
        <item name="android:windowNoTitle">true</item>
    </style>

</resources>

AndroidManifest for library project

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mhood.testlibrary" >

    <application
        android:allowBackup="true"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Upvotes: 2

Views: 922

Answers (1)

Jared Burrows
Jared Burrows

Reputation: 55527

Try this configuration:

It is best to have structure by listing the "parent" theme first. Then list all of your application themes(the ones that inherit the parent).

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- List base theme first -->
    <style name="SomeThemeBase" parent="@style/Theme.AppCompat.Light">
        <!-- Customize your theme here -->
    </style>

    <!-- App theme inherits Parent base theme -->
    <style name="SomeAppTheme" parent="@style/SomeThemeBase">

        <!-- Customize your theme here -->
        <item name="android:windowDisablePreview">true</item>
    </style>

    <!-- App theme inherits Parent base theme -->
    <style name="SomeTheme" parent="@style/SomeThemeBase" />

    <!-- App theme inherits Parent base theme -->
    <style name="Theme.Translucent.NoTitleBar" parent="@android:style/Theme.Translucent.NoTitleBar">
        <!-- Customize your theme here -->
        <item name="android:windowNoTitle">true</item>
    </style>

</resources>

Upvotes: 0

Related Questions