使用productFlavors时无法继承自定义主题

时间:2016-06-19 03:37:26

标签: android user-interface gradle

这是我的full code,这里是my screenshot 在旧代码中:

在MyLibrary / styles.xml

// Here, do something useful with the audio data that's 
// now in the audioBytes array...

应用程序/ styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="RoTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    </style>
</resources>

它有效,但改变时

在MyLibrary /的build.gradle

<resources>
    <style name="AppTheme" parent="RoTheme">
    </style>
</resources>

defaultConfig {
    minSdkVersion 23
    targetSdkVersion 23

并点击android studio&#34; gradle sync&#34;,它会提升

productFlavors {
   dev {
       minSdkVersion 23
       targetSdkVersion 23
   }
}

如何解决?

3 个答案:

答案 0 :(得分:0)

替换

<style name="RoTheme"
       parent="android:style/Theme.AppCompat.Light.DarkActionBar">

{{1}}

android:style表示它是Android的内置样式

答案 1 :(得分:0)

  

产品风格支持与defaultConfig相同的属性,因为defaultConfig实际上属于ProductFlavor类,但创建产品风格类似于创建构建类型。

请参阅build-variants了解详情, 所以保持defaultConfig不变并添加productFlavors但不要替换它,你应该这样做:

android {
    ...
    defaultConfig {...}
    buildTypes {...}
    productFlavors {
        demo {
            applicationId "..."
            versionName "..."
        }
        full {
            applicationId "..."
            versionName "..."
        }
    }
}

答案 2 :(得分:0)

就我而言,错误只发生在

compile project(path: ":mylibrary")

如果我使用以下代码将起作用:

dependencies {
    compile 'ro.mylibrary:mylibrary-dev-release:1.0@aar'
}

repositories {
    flatDir {
        dirs "$System.env.HOME/Dropbox/try/adr/product-flavor-make-custom-theme-inheritance-failed/mylibrary/build/outputs/aar"
    }
}

所以如果我在我的库中使用productFlavors,那么这个bug只会出现在虚拟项目中,这不是什么大问题。