问题描述
我有一个包含字符串资源的库:
I have library which contains string resource:
<string name="lib_name">MyLibrary</string>
对应用程序build.gradle中的库的引用:
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:
build.gradle of library:
android {
...
productFlavors {
myFlavor {}
}
}
然后,我为新的风味\ mylibrary \ src \ myFlavor \ res \ values \ strings.xml创建新的资源文件:
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').
我需要此应用程序仅具有默认样式."myFlavor"中的资源将在不同的应用程序中使用,并且还将指定"myFlavor"风格.
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?
谢谢您的帮助.
我在此处上传了示例项目.
推荐答案
首先,将flavor配置更改为您的依赖项:
Firstly, change flavor configuration to your dependency:
compile project(path: ':mylibrary', configuration: 'myFlavorRelease')
第二,通过* mylibrary \ src \ main *中的正确替换* mylibrary \ src \ myFlavor *中的错误AndroidManifest.xml.
Secondly, replace your wrong AndroidManifest.xml in *mylibrary\src\myFlavor* by correct in *mylibrary\src\main*.
这篇关于从非风味应用程序引用的Android多种风味库-AAPT:找不到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!