错误:资源android:attr / preserveIconSpacing是私有的

时间:2018-04-16 02:39:35

标签: java android android-studio gradle android-gradle

您好我正在尝试将我的Android应用项目从Eclipse迁移到Android Studio。这是为Android KitKat而构建的。我忘记了我使用的Eclipse版本是什么。我正在使用Android Studio 3.0.1。我按照https://developer.android.com/studio/intro/migrate.html的说明进行操作。尝试迁移时出现此错误。请帮忙。这对我来说很重要

Error Message Image

这是Gradle控制台上的错误消息

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]

Configuration on demand is an incubating feature.
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:checkDebugManifest
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:createDebugCompatibleScreenManifests
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug
:app:processDebugResources
AGPBI: {"kind":"error","text":"error: resource android:attr/preserveIconSpacing is private.","sources":[{"file":"C:\\Users\\Shazwan\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-19.1.0.aar\\df4f4f2e7a9c43dda4827c11e87fed2a\\res\\values\\values.xml","position":{"startLine":507,"startColumn":4,"startOffset":24529,"endColumn":61,"endOffset":24586}}],"original":"","tool":"AAPT"}
D:\Work\AndroidD\OpacKAWAT\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:133: error: resource android:attr/preserveIconSpacing is private.
error: failed linking references.

Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:796)
    at com.android.build.gradle.tasks.ProcessAndroidResources.invokeAaptForSplit(ProcessAndroidResources.java:551)
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:285)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.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:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:794)
    ... 48 more
Caused by: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:462)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at com.android.builder.internal.aapt.v2.QueueableAapt2.lambda$makeValidatedPackage$1(QueueableAapt2.java:179)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    ... 1 more
Caused by: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    at com.android.builder.png.AaptProcess$NotifierProcessOutput.handleOutput(AaptProcess.java:463)
    at com.android.builder.png.AaptProcess$NotifierProcessOutput.err(AaptProcess.java:415)
    at com.android.builder.png.AaptProcess$ProcessOutputFacade.err(AaptProcess.java:332)
    at com.android.utils.GrabProcessOutput$1.run(GrabProcessOutput.java:104)

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt

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

* Get more help at https://help.gradle.org

BUILD FAILED in 37s

12 actionable tasks: 12 executed

3 个答案:

答案 0 :(得分:4)

我的经验是这样的:从targetSdkVersion 21降级到19(因为我公司中约有20部电话使用android 4.4),我遇到了标题为resource android:attr/preserveIconSpacing is private的错误。

我设法以这种方式克服了这个错误:

在错误消息中,它是使用设置写入目录的,在我的情况下是:.gradle\caches\transforms-1\files-1.1\appcompat-v7-19.0.0.aar\4cd3ccb7957b0114d8e3c7a67ecc96ad\res\values\。我从该目录打开attr.xml文件,对消息中声明的整行进行了注释,即:

<attr name="android:preserveIconSpacing" />

现在,丑陋的错误消失了。我不认为这可以解决问题,因为它听起来像是一个缓存目录并且可以被覆盖,但事实并非如此,

以前,我还尝试过修改android目录中的attr.xml文件,我认为这是解决方案,即 android-sdk \ extras \ android \ support \ v7 \ appcompat \ res \ values \ attr.xml 。但是该文件无法修改,已被写保护。我关闭了所有Android Studio,没有启动Java或任何其他类似的应用程序,但是没有运气。

以前,我还尝试从目录 android-sdk \ extras \ android \ support \ v7 \ appcompat \ res \ values \ 中复制“ attr.xml”,修改了prepareIconSpacing设置,然后进行了复制它在我的res / values目录中。没有运气。

更新2018年11月5日。在另一个安装中,它不是包含字符串“”的“ attr.xml”文件。因此,我搜索了错误中指定的整个“ res”目录,并在“ values.xml”文件中找到/找到了该目录。我在那里评论。而且有效。

我希望这对某人有帮助。

答案 1 :(得分:3)

从eclipse升级到android studio时遇到了同样的问题。我通过升级build.gradle解决了这个问题。

首先,我升级了

 buildToolsVersion 

然后改变了

  compileSdkVersion 'your api level'
  minSdkVersion 'your api level'
  targetSdkVersion 'your api level'

也升级了

dependencies {
implementation 'com.android.support:appcompat-v7:'your api level''
}

这解决了我的问题

答案 2 :(得分:1)

出于某种原因,我想使用KitKat(API级别19)来编译我的项目,而使用最新的canary(Android Studio 3.3 Canary 5)却无法正常工作(我不记得错误消息,但是我已经浪费了很多时间)由于这个原因有些时间,并认为它可能会对遇到相同问题的人有所帮助。

我做了以下事情:

  1. 在Android Studio 2.3稳定版中打开项目,
  2. 打开项目的 build.gradle 文件(不是应用模块的文件!),并将插件版本设置为2.2.3:

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
    
  3. 将项目的 build.gradle 中的google()替换为(如果文件中没有google()):

    maven {
        url 'https://maven.google.com'
    }
    
  4. 打开 gradle-wrapper.properties 并将gradle版本设置为2.14.1(在选择相互兼容的插件和gradle版本时,this page很有用):< / p>

    distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip