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

北慕城南 提交于 2019-12-10 09:46:33

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/34658325/android-multi-flavor-library-referenced-from-non-flavor-application-aapt-no-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!