aapt.exe错误添加android v7支持库时,非零退出值完成

时间:2015-11-23 04:54:18

标签: android android-studio gradle build.gradle

我正在尝试将lib com.android.support:preference-v7:23.1.0导入到我的项目中。 但是,当我添加

compile ("com.android.support:preference-v7:23.1.0"){
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }

到我的gradle构建文件。我收到错误:

Execution failed for task ':proxitag:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.E
xecException: Process 'command 'C:\Users\nlthinh\AppData\Local\Android\sdk\build
-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1.

我尝试清理并构建项目,以及将compileSdkVersion更新为21和buildToolsVersion 22.0.1。

这是我的完整gradle构建文件:

import org.ajoberstar.grgit.*

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

repositories {
    mavenCentral();
    maven {
        url "http://repo.gradle.org/gradle/repo"
    }

    maven {
        url "https://repo.commonsware.com.s3.amazonaws.com"
    }
    def androidHome = System.getenv("ANDROID_HOME")
    maven {
        url "$androidHome/extras/android/m2repository/"
    }



}

apply plugin: 'android'
apply plugin: 'eclipse'

configurations {
    compile
}

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile project (":preferencefragment")
    compile 'com.jjoe64:graphview:3.1.3'
    compile "com.android.support:support-v4:19.1.+"
    compile ("com.android.support:preference-v7:23.1.0"){
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    //exclude appcompat-v7 as it conflicted with the actionbarsherlock

    compile fileTree(dir: 'libs', include: ['*.jar'], exclude: ['support-v4*.jar'])
}

android {
    lintOptions {
        abortOnError false
    }
    enforceUniquePackageName false
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }

}

task copyJarDependencies(type: Copy) {
    description = 'Used for Eclipse. Copies all dependencies to the deps directory. If there are any AAR files it will extract the classes.jar and rename it the same as the AAR file but with a .jar on the end.'
    def libDir = new File(project.projectDir, '/deps')
    println libDir
    println 'Extracting dependencies from compile configuration'
    configurations.compile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
    println 'Extracting dependencies from releaseCompile configuration'
    configurations.releaseCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
    println 'Extracting dependencies from debugCompile configuration'
    configurations.debugCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }

}

void moveAndRenameAar(File file){
    println 'Added aar ' + file
    def baseFilename = file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}

    // directory excluding the classes.jar
    copy{
        from zipTree(file)
        exclude 'classes.jar'
        into 'deps/'+baseFilename
    }

    // Copies the classes.jar into the deps directory of the expoded AAR.
    // In Eclipse you can then import this exploded ar as an Android project
    // and then reference not only the classes but also the android resources :D
    copy{
        from zipTree(file)
        include 'classes.jar'
        into 'deps/' + baseFilename +'/libs'
        rename { String fileName ->
            fileName.replace('classes.jar', baseFilename + '.jar')
        }
    }
}

task copyNativeLibs(type: Copy) {
    from(new File(getProjectDir(), 'libs')) { include '**/*.so' }
    into new File(buildDir, 'libs')
}

tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }

clean.dependsOn 'cleanCopyNativeLibs'

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniFolders = new HashSet<File>()
    pkgTask.jniFolders.add(new File(buildDir, 'libs'))
}

编辑!:更新堆栈跟踪日志

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':proxita
g:processDebugResources'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
e(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
ter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
e(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur
e(AbstractTask.java:310)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
tTaskPlanExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
ltTaskGraphExecuter.java:88)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
ExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:62)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
uter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
ter.java:68)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
ecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:62)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:55)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:149)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:106)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:90)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(Exe
cuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildA
ctionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:28)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:50)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:27)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:169)
        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(JavaRunti
meValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.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(ExceptionRep
ortingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.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(ProcessBoots
trap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.ja
va:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: org.gradle.internal.UncheckedException: com.android.ide.common.proces
s.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'C:\Users\nlthinh\AppData\Local\Android\sdk\build-tools\22.0.1\aapt.exe'' finish
ed with non-zero exit value 1
        at org.gradle.internal.UncheckedException.throwAsUncheckedException(Unch
eckedException.java:45)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:78)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)

        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
        ... 49 more
Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.i
nternal.ExecException: Process 'command 'C:\Users\nlthinh\AppData\Local\Android\
sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1
        at com.android.build.gradle.internal.process.GradleProcessResult.assertN
ormalExitValue(GradleProcessResult.java:42)
        at com.android.builder.core.AndroidBuilder.processResources(AndroidBuild
er.java:854)
        at com.android.builder.core.AndroidBuilder$processResources$1.call(Unkno
wn Source)
        at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskActi
on(ProcessAndroidResources.groovy:159)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(In
crementalTask.java:79)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        ... 55 more
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Users
\nlthinh\AppData\Local\Android\sdk\build-tools\22.0.1\aapt.exe'' finished with n
on-zero exit value 1
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNo
rmalExitValue(DefaultExecHandle.java:365)
        at com.android.build.gradle.internal.process.GradleProcessResult.assertN
ormalExitValue(GradleProcessResult.java:40)
        ... 60 more

更新 使用 assembleDebug --info 参数

运行gradle时的错误输出
Successfully started process 'command 'C:\Users\nlthinh\AppData\Local\Android\sd
k\build-tools\21.1.2\aapt.exe''
Unknown source file : ERROR: In <declare-styleable> Preference, unable to find a
ttribute layout

:proxitag:processDebugResources FAILED
:proxitag:processDebugResources (Thread[main,5,main]) completed. Took 0.349 secs

1 个答案:

答案 0 :(得分:0)

首先 com.android.support:preference-v7需要appcompat

您可以在pom文件中查看它。

<dependency>
  <groupId>com.android.support</groupId>
  <artifactId>appcompat-v7</artifactId>
  <version>23.1.1</version>
  <type>aar</type>
  <scope>compile</scope>
</dependency>

您无法一起使用appcompat和sherlock 。删除abs库。

然后,因为你正在使用v23,如果com.android.support:preference-v7你必须:

  • compileSdk更改为23

  • buildTools更改为23

  • 将支持库更新为23,不使用不同版本的支持库

Somenthing like:

 compileSdkVersion 23
 buildToolsVersion "23.0.1"

 compile "com.android.support:support-v4:23.1.1"
 compile ("com.android.support:preference-v7:23.1.1"){
    exclude group: 'com.android.support', module: 'appcompat-v7'
 }