Search code examples
androidgradleandroid-productflavors

Android multi flavor library referenced from non flavor application - AAPT: No resource found


I have library which contains string resource:

<string name="lib_name">MyLibrary</string>

Reference to library in application build.gradle:

dependencies{
  compile project(':mylibrary')
...
}

In application module I have displayed this text resource:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/lib_name" />

There is no problem without using flavors. Now I want to add new flavor to library with different text.

build.gradle of library:

android {
...
  productFlavors {
    myFlavor {}
  }
}

Then I create new resource file for new flavor \mylibrary\src\myFlavor\res\values\strings.xml:

<string name="lib_name">MyLibrary My Flavor</string>

But now I have build error, resource is not available anymore:

AAPT: No resource found that matches the given name (at 'text' with value '@string/lib_name').

I need this application has only default flavor. Resource in 'myFlavor' will be consumed in different application, which will also have 'myFlavor' flavor specified.

What I need to change in application to solve this error?

Thank you for any help.

Edit: I uploaded my sample project here.


Solution

  • Firstly, change flavor configuration to your dependency:

    compile project(path: ':mylibrary', configuration: 'myFlavorRelease')
    

    Secondly, replace your wrong AndroidManifest.xml in *mylibrary\src\myFlavor* by correct in *mylibrary\src\main*.