我有一个拥有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 for library project
<?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>