所以我在Android Studio(0.6.1)中有一个Android项目。有2个模块 A 和 B 。 A 是我的主要模块,它依赖于 B ,其中包含各种资源(drawables,字符串,样式),因此可以像库一样运行(尽管它不是库) -项目)。我将 B 添加为git-subtree,将其包含在我的settings.gradle中,构建工作正常。
现在出现问题:我想在 A 中引用 B 中的资源。对于drawable,我已经发现here我可以在 A 中创建虚拟资源,这些资源将被 B 覆盖。但不幸的是不适用于 B 中定义的样式。我在 A 中的styles.xml中创建的虚拟对象不会被覆盖。
我的目标是在 B 中定义多个样式,如:
<style name="ButtonStyle1" parent="android:Widget.Button">
<item name="android:layout_width">wrap_content</item>
<item name="android:minWidth">200dp</item>
<item name="android:background">@drawable/buttonorange</item>
<item name="android:textColor">@android:color/black</item>
</style>
<style name="ButtonStyle2" parent="android:Widget.Button">
<item name="android:layout_width">wrap_content</item>
<item name="android:minWidth">200dp</item>
<item name="android:background">@drawable/buttonorange</item>
<item name="android:textColor">@android:color/black</item>
</style>
然后回到 A 我希望有机会选择应用ButtonStyle1或ButtonStyle,如:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:buttonStyle">@style/ButtonStyle1</item>
</style>
或
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:buttonStyle">@style/ButtonStyle2</item>
</style>
但是当我这样做时,我总能得到
Error:(5, 42) No resource found that matches the given name (at 'android:buttonStyle' with value '@style/ButtonStyle1').
总而言之,我猜我的gradle配置本身是正确的,因为覆盖drawables已经很好了。 所以我做错了什么 - 如何在A中引用B中定义的样式?
settings.gradle
include ':app', ':uiframework:uiframework'
build.gradle from A
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
applicationId 'com.example.uiframeworkexample'
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':uiframework:uiframework')
}
答案 0 :(得分:0)
确保在build.gradle文件中为B(库)项目应用正确的插件
apply plugin: 'com.android.library'