我有一个包含 java 源代码和资源的图书馆项目。
在我的应用程序中,我引用了图书馆项目中的资源。一切工作正常,但是一旦我在库项目中添加产品风格,我就会收到以下错误。
错误:(1) 检索项目的父级时出错:找不到与给定名称“@style/SomeTheme”匹配的资源。
请查看我添加的口味。
productFlavors {
production {
}
staging {
}
}
如果我删除这些味道,一切都会正常。
当新风格添加到库项目时,我还应该做哪些事情来确保资源可用于应用程序项目?
我不想将defaultPublishConfig“dev1Production”条目添加到库项目中。
我还能做什么来解决这个问题?
<小时/>库项目的build.gradle
应用插件:'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
// defaultPublishConfig "dev1Debug"
// publishNonDefault true
productFlavors {
production {
}
staging {
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
来自库项目的 style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="SomeAppTheme" parent="@style/SomeTheme">
<!-- Customize your theme here. -->
<item name="android:windowDisablePreview">true</item>
</style>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="SomeThemeBaseJW" parent="@style/Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="SomeTheme" parent="@style/SomeThemeBaseJW" />
<style name="Theme.Translucent.NoTitleBar" parent="@android:style/Theme.Translucent.NoTitleBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
</style>
</resources>
库项目的AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mhood.testlibrary" >
<application
android:allowBackup="true"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
最佳答案
尝试此配置:
最好首先列出“父”主题来建立结构。然后列出所有应用程序主题(继承父主题的主题)。
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- List base theme first -->
<style name="SomeThemeBase" parent="@style/Theme.AppCompat.Light">
<!-- Customize your theme here -->
</style>
<!-- App theme inherits Parent base theme -->
<style name="SomeAppTheme" parent="@style/SomeThemeBase">
<!-- Customize your theme here -->
<item name="android:windowDisablePreview">true</item>
</style>
<!-- App theme inherits Parent base theme -->
<style name="SomeTheme" parent="@style/SomeThemeBase" />
<!-- App theme inherits Parent base theme -->
<style name="Theme.Translucent.NoTitleBar" parent="@android:style/Theme.Translucent.NoTitleBar">
<!-- Customize your theme here -->
<item name="android:windowNoTitle">true</item>
</style>
</resources>
关于android - Gradle : Error retrieving parent for item: No resource found that matches the given name '@style/SomeTheme' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31412555/