Search code examples
androidandroid-gradle-pluginandroid-resourcesandroid-themeandroid-library

Failing to use resource from Android library ("Error retrieving parent for item: No resource found that matches...")


I have an Android library module that defines a theme:

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@drawable/v4_window_background</item>
</style>

<style name="MP.Theme" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/V4_Green</item>
    <item name="drawerArrowStyle">@style/MP.Widget.DrawerArrowStyle</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/V4_Green_Pressed</item>
    <item name="android:textColorSecondary">@color/V4_White</item>
    <item name="actionMenuTextColor">@color/V4_White</item>
    <item name="android:textColorPrimaryInverse">@color/V4_White</item>
    <item name="android:buttonStyle">@style/MP.Base.Widget.Button</item>
    <item name="actionBarPopupTheme">@style/CustomToolbarTheme</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowActionModeOverlay">true</item>
    <item name="android:actionModeStyle">@style/MP.Widget.ActionMode</item>
    <item name="actionModeStyle">@style/MP.Widget.ActionMode</item>
    <item name="colorControlNormal">@color/V4_White</item>
    <item name="colorControlActivated">@color/V4_White</item>

    <!--<item name="android:fitsSystemWindows">true</item>-->

    <!-- colorAccent is used as the default value for
 colorControlActivated which is used to tint widgets. -->
    <item name="colorAccent">@color/V4_Green</item>
    <item name="toolbarNavigationButtonStyle">@style/toolbarStyle</item>
    <item name="android:actionOverflowButtonStyle">@style/overflowButtonStyle</item>
    <item name="actionOverflowButtonStyle">@style/overflowButtonStyle</item>
</style>

The AAR module gets build successfully, and the app module successfully uses the library as a dependency.

In the main app, I'm trying to reference the theme as a parent:

 <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="App_MP.Theme" parent="MP.Theme">

    </style>

</resources>

However I get Error:(217) Error retrieving parent for item: No resource found that matches the given name 'MP.Theme'.

I've also tried using "@style/MP.Theme".

Not sure how to proceed from here - how to correctly reference a resource inside my library?

UPDATE

Project gradle file:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://dl.bintray.com/optimizely/optimizely'
        }
    }
}

Library gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.library'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
    }

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

    productFlavors {
        a {
                  }
        b {

        }
    }

    sourceSets {
        a.java.srcDirs = [‘a’, ‘b’, ‘c’]
        b.java.srcDirs = [‘a’, ‘b’, ‘c’]
    }
}

dependencies {
    compile 'com.android.support:support-v4:23.3.0'
    compile ('com.android.support:cardview-v7:23.3.0'){
        transitive = true
        exclude module:'support-v4'
        exclude module:'support-annotations'

    }
    compile ('com.android.support:appcompat-v7:23.3.0'){
        transitive = true
        exclude module:'support-v4'
        exclude module:'support-annotations'

    }
    compile ('com.android.support:recyclerview-v7:23.3.0'){
        transitive = true
        exclude module:'support-v4'
        exclude module:'support-annotations'
    }

    compile ('com.google.android.gms:play-services-basement:+'){
        exclude module:'support-v4'
        exclude module:'support-annotations'
    }
    compile ('com.google.android.gms:play-services-base:+'){
        transitive = true
        exclude group:'com.google.android.gms', module:'play-services-basement'
    }
    compile ('com.google.android.gms:play-services-gcm:+'){
        transitive = true
        exclude group:'com.google.android.gms', module:'play-services-base'
        exclude group:'com.google.android.gms', module:'play-services-basement'
    }
    compile ('com.google.android.gms:play-services-analytics:+'){
        transitive = true
        exclude group:'com.google.android.gms', module:'play-services-base'
        exclude group:'com.google.android.gms', module:'play-services-basement'
    }
    compile 'org.mozilla:rhino:1.7.7'
    compile 'com.google.code.gson:gson:+'


    compile 'io.fabric.sdk.android:fabric:+'
    compile ('com.crashlytics.sdk.android:crashlytics:+'){
        transitive = true
        exclude module: 'fabric'
    }







    compile ('io.branch.sdk.android:library:2.4.7'){
        exclude module:'support-v4'
        exclude module:'support-annotations'
    }

    compile ('com.android.support:percent:23.3.0'){
        exclude module:'support-v4'
        exclude module:'support-annotations'
    }
    compile 'com.squareup.okhttp3:okhttp:+'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mixpanel.android:mixpanel-android:4.+'
    compile ('com.amplitude:android-sdk:2.13.0'){
        exclude module:'okhttp'
    }
    compile('com.optimizely:optimizely:+@aar') {
        transitive = true
        exclude module: 'gson'
        exclude module:'support-v4'
        exclude module: 'okhttp'
    }
    //compile 'com.facebook.android:facebook-android-sdk:4.+'
    provided 'com.jayway.android.robotium:robotium-solo:5.5.4'
    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.4'
    androidTestCompile 'org.assertj:assertj-core:1.6.1'
    //compile 'com.google.firebase:firebase-database:9.8.0'
    compile 'com.parse:parse-android:1.13.1'
    androidTestCompile('com.squareup.assertj:assertj-android:1.0.+') {
        exclude module: 'support-annotations'
    }
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
    testCompile 'junit:junit:4.12'
//    provided 'org.robolectric:robolectric:3.1.4'
//    testCompile 'org.robolectric:robolectric:3.1.4'
//    androidTestCompile('com.android.support.test:runner:0.4') {
//        exclude module: 'support-annotations'
//    }
    androidTestCompile('com.android.support.test:rules:0.4') {
        exclude module: 'support-annotations'
    }
    androidTestCompile('com.squareup.assertj:assertj-android-support-v4:1.1.1') {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
    }

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-library:1.3'

}

App module gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'pl.itako:icon-version:1.1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'icon-version'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.2'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
               applicationId “a.b.c”

    }


    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the show even when errors are found:
        abortOnError false
    }

    dexOptions {
        preDexLibraries = true
        javaMaxHeapSize "4g"
        jumboMode = true
    }

    packagingOptions {
        exclude 'APK LICENSE.txt'
        exclude 'LICENSE.txt'
    }


    iconVersionConfig {
        fontSize = 18
        verticalLinePadding = 4 // vertical gap between each line of text
    }

    signingConfigs {
        debug {
            storeFile file("../Dev-Tools/certificates/debug.keystore")
        }

        staging {
            try {
                keyAlias ‘abc’
                keyPassword KEY_PASSWORD
                storeFile file(PATH_TO_CERTIFICATE)
                storePassword KEYSTORE_PASSWORD
            }
            catch (ex) {
                throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.", ex)
            }
        }


        release {
            try {
                keyAlias ‘abc’
                keyPassword KEY_PASSWORD
                storeFile file(PATH_TO_CERTIFICATE)
                storePassword KEYSTORE_PASSWORD
            }
            catch (ex) {
                throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.", ex)
            }
        }
    }


    productFlavors {
        a {
            applicationId = “a”

        }
        b {
            applicationId = “b”

        }
        c {
            applicationId = “c”

        }

    }

    sourceSets {
        a.java.srcDirs = ['src/a/java', 'src/b/java', 'src/c/java']
        b.java.srcDirs = ['src/a/java', 'src/b/java', 'src/c/java']
        c.java.srcDirs = ['src/a/java', 'src/b/java', 'src/c/java']    }


    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            ext.enableCrashlytics = false
            debuggable = true
        }
        staging {
            signingConfig signingConfigs.staging
            ext.enableCrashlytics = false
            debuggable = true
        }
        iaptest {
            signingConfig signingConfigs.release
            ext.enableCrashlytics = false
            debuggable = true
            project.testIAP = true
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable = false
        }
    }
}



dependencies {
    compile project(‘:lib’)

    compile ('com.android.support:appcompat-v7:23.3.0')




}

The gradle files I added were modified to remove the product's name.

UPDATE 2

Removing the build flavors from the library seems to resolve this. But I need the build flavors. Can't find the problem yet, since my resources are in src/main/res.


Solution

  • Just resolved it by myself after finding out about publishing multiple variants.

    In short: 1. Add

    android { ... // Tells Gradle to build all variants of the library. Note that this // may increase build times because Gradle must build multiple AARs, // instead of only one. publishNonDefault true }

    to the library.

    2.Add

    android {...}
    ...
    
    // Creates Gradle dependency configurations to use in the dependencies block.
    
    configurations {
      // Initializes placeholder configurations that the Android plugin can use when targeting
      // the corresponding variant of the app.
      aDebugCompile {}
      bReleaseCompile {}
      ...
    }
    
    dependencies {
      // If the library configures multiple build variants using product flavors,
      // you must target one of the library's variants using its full configuration name.
      aDebugCompile project(path: ':my-library-module', configuration: 'aDebug')
      bReleaseCompile project(path: ':my-library-module', configuration: 'bRelease')
      ...
    }
    

    To the app build file.