天天看點

解決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">

繼續閱讀