主题在两个库中声明样式时出现gradle错误

Luk*_*s H 9 android android-appcompat gradle android-studio android-gradle-plugin

我尝试使用以下build.gradle文件编译一个android项目:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    maven {
        url 'https://github.com/Goddchen/mvn-repo/raw/master/'
    }
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 18
    }
}

dependencies {
        compile 'com.android.support:appcompat-v7:18.0.+'
        compile 'com.android.support:support-v4:18.0.+'

        compile 'com.google.android.gms:play-services:3.2.+'

        compile 'com.facebook.android:facebook:3.5.+'
        compile 'com.android:volley:1.0'
        compile 'org.jraf:android-switch-backport:1.0'

}
Run Code Online (Sandbox Code Playgroud)

但是这失败了以下错误:

:TestProject:processDebugResources
/home/lukas/apps/Splots_test/apps/TestProject/build/res/all/debug/values/values.xml:1622: error: Error: No resource found that matches the given name: attr 'switchStyle'.
:TestProject:processDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':TestProject:processDebugResources'.
> Could not call IncrementalTask.taskAction() on task ':TestProject:processDebugResources'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED
Run Code Online (Sandbox Code Playgroud)

在查看生成的values.xml之后,我发现它缺少android-switch-backport的declare-styleable"Theme"部分.

此部分在Appcompat和AndroidSwitchBackport中定义,但最终文件中只包含其中一个:

lukas@lukas-Workstation:~/apps/Splots_test/apps$ grep -r 'declare-styleable name="Theme"' .
./TestProject/build/exploded-bundles/ComAndroidSupportAppcompatV71800.aar/res/values/values.xml:    <declare-styleable name="Theme">
./TestProject/build/exploded-bundles/OrgJrafAndroidSwitchBackport10.aar/res/values/values.xml:    <declare-styleable name="Theme">
Run Code Online (Sandbox Code Playgroud)

有没有办法告诉gradle它应该合并两个库的属性?

jon*_*h_w 5

我也遇到了这个问题.我认为你需要更改android-switch-backport库中的attrs.xml文件.

尝试改变这个

<declare-styleable name="Theme">
        <attr name="switchStyle" format="reference" />
        <attr name="switchPreferenceStyle" format="reference" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)

对此:

<declare-styleable name="AppTheme">
        <attr name="switchStyle" format="reference" />
        <attr name="switchPreferenceStyle" format="reference" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)


BoD*_*BoD 1

你知道,我是 Switch Backport 库的开发者,从 1.3.1 版本开始这个问题就不再存在了。

(确保升级时包含正确的存储库,因为它不再是 Maven 中心)。