无法在Android上使用build.gradle覆盖bool资源

时间:2016-07-05 11:47:26

标签: android gradle build.gradle

我尝试使用build.gradle覆盖bool资源。它会覆盖string资源,但它不会覆盖bool资源 我该如何修复并覆盖它?

Stacktrace如下:

Executing task ':app:mergeDebug2Resources' (up-to-date check took 0.102 secs) due to:
  No history is available.
All input files are considered out-of-date for incremental task ':app:mergeDebug2Resources'.
Unable do incremental execution: full task run
[bool/isBeta] /builds/nao20010128nao/Wisecraft/app/src/main/res/values/booleans.xml [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/build/generated/res/resValues/debug2/values/generated.xml: Error: Duplicate resources
:app:mergeDebug2Resources FAILED
:app:mergeDebug2Resources (Thread[main,5,main]) completed. Took 0.355 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebug2Resources'.
> [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/src/main/res/values/booleans.xml   [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/build/generated/res/resValues/debug2/values/generated.xml: Error: Duplicate resources

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDebug2Resources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:154)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:151)
    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:45)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: com.android.build.gradle.tasks.ResourceException: [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/src/main/res/values/booleans.xml    [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/build/generated/res/resValues/debug2/values/generated.xml: Error: Duplicate resources
    at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.java:185)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:88)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:244)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:231)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 57 more
Caused by: [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/src/main/res/values/booleans.xml  [bool/isBeta] /builds/nao20010128nao/Wisecraft/app/build/generated/res/resValues/debug2/values/generated.xml: Error: Duplicate resources
    at com.android.ide.common.res2.DataSet.checkItems(DataSet.java:412)
    at com.android.ide.common.res2.DataSet.loadFromFiles(DataSet.java:251)
    at com.android.ide.common.res2.ResourceSet.loadFromFiles(ResourceSet.java:52)
    at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.java:164)
    ... 65 more


BUILD FAILED

Total time: 2 mins 0.394 secs
Stopped 0 compiler daemon(s).

build.gradle的内容是:(某些内容被截断)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        applicationId 'com.nao20010128nao.Wisecraft'
        minSdkVersion 8
        targetSdkVersion 21
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles '../proguard-rules.pro'
        }
        debug {
            applicationIdSuffix = '.alpha'  
            versionNameSuffix = 'd'
        }
        pre {
            versionNameSuffix = ' Pre'
            resValue "string", "app_name", "Wisecraft BETA"
            resValue "bool", "isBeta", "true"
        }
        debug2 {
            applicationIdSuffix = '.alpha'  
            versionNameSuffix = ' Pre'
            resValue "string", "app_name", "Wisecraft BETA"
            resValue "bool", "isBeta", "true"
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:multidex:+'
    compile 'com.android.support:preference-v7:23.4.0'
}

1 个答案:

答案 0 :(得分:0)

在您的Gradle 编译支持:multidex 1.0.1并添加dexOptions 和packagingOptions

apply plugin: 'com.android.application'

 android {
compileSdkVersion 23
buildToolsVersion '23.0.3'

defaultConfig {
    applicationId 'com.nao20010128nao.Wisecraft'
    minSdkVersion 8
    targetSdkVersion 21
    multiDexEnabled true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles '../proguard-rules.pro'
    }
    debug {
        applicationIdSuffix = '.alpha'  
        versionNameSuffix = 'd'
    }
    pre {
        versionNameSuffix = ' Pre'
        resValue "string", "app_name", "Wisecraft BETA"
        resValue "bool", "isBeta", "true"
    }
    debug2 {
        applicationIdSuffix = '.alpha'  
        versionNameSuffix = ' Pre'
        resValue "string", "app_name", "Wisecraft BETA"
        resValue "bool", "isBeta", "true"
    }
}
dexOptions {
    //incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g"
}

packagingOptions {
    exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
    exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}

lintOptions {
    abortOnError false
}
}

dependencies {
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:preference-v7:23.4.0'
compile 'com.android.support:multidex:1.0.1'
}

AndroidManifest.xml 中添加以下行 android:name

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication"
    >