Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 870
Vladimír Domes Avatar asked Jan 01 '26 02:01

Vladimír Domes


1 Answers

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*.

like image 93
user5814189 Avatar answered Jan 02 '26 18:01

user5814189



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!