天天看点

解决aapt "finished with non-zero exit value 1"问题

问题描述:

问题情境1:

使用Android Studio导入Eclipse工程后,常遇到如下的报错:

com.android.ide.common.process.ProcessException: 
org.gradle.process.internal.ExecException: 
Process 'command 'C:\Users\Vishnu Ruhela\AppData\Local\Android\sdk\build-tools
\21.1.2\aapt.exe'' finished with non- zero exit value 1
           

这种莫名其妙的问题真心毁了我的三观,好在经过不断努力和尝试还是解决了。

问题情境2:

最近发现拷贝其他工程的attrs.xml并引用这些属性也出现“finished with non- zero exit value 1”报错,并伴随”Attribute xx has already been defined”:

解决aapt "finished with non-zero exit value 1"问题

查阅资料后也以某种方式解决了。

解决方法:

问题一:

一、修改应用launcher icon的引用方式

即从drawable改为mipmap:

右键res->New->Android resourse directory->选择mipmap,第一步;

右键mipmap->New->Image Asset,完成剩下的操作。

二、修改manifest

1、修改android:icon的”@drawable/ic_launcher”为”@mipmap/ic_launcher”

2、在application中添加tools:replace=”android:icon”,参见如下代码:

<application
        android:allowBackup="true"
        tools:replace="android:icon"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
           

如果tools标红,manifest标签中增加xmlns:tools=”http://schemas.android.com/tools”即可。

问题的具体原因无从做更深入分析,但是这样操作既符合新应用规范,又解决了我的棘手问题。

问题二:

一、修改属性名

修改之前:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Circle">
        <attr name="bwidth" format="dimension" />
        <attr name="bcolor" format="color" />
    </declare-styleable>

</resources>
           

修改之后:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Circle">
        <attr name="bwidth1" format="dimension" />
        <attr name="bcolor1" format="color" />
    </declare-styleable>

</resources>
           

二、修改java中的引用

修改之前:

c.getColor(R.styleable.Circle_bcolor, DEFAULT_BORDER_COLOR);
           

修改之后

c.getColor(R.styleable.Circle_bcolor1, DEFAULT_BORDER_COLOR);
           

然后clean并重新编译就可以了。

width="330" height="86" src="http://music.163.com/outchain/player?type=2&id=199172&auto=1&height=66">

继续阅读