1. 程式人生 > >aapt解析的坑,記錄一下防止再次掉入

aapt解析的坑,記錄一下防止再次掉入

在將app釋出到各大市場上之前我們需要自己在本地用aapt解析一遍上傳的apk檔案,當然你也可以選擇等各大市場將你的apk打回來之後再去檢查原因,好了,進入正題,解析apk時提示“ERROR getting 'android:icon' attribute: attribute is not a stringvalue”或者“ERROR getting 'android:label' attribute: attribute is not a stringvalue”,android清單檔案中label有兩種引用方式一種是硬編碼一種是資源引用,無論是報上面哪種錯誤在我看來都是label的錯,當清單檔案有多個android:label的時候請使用:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="xxxxx">
 <application
        android:name=".xxxx"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="應用名硬編碼"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="android:label"
>

要注意檢查的是清單檔案中的所有資源引用類似於@string的android:label都需要轉化成硬編碼,至於icon在清單檔案中只能以資源引用的方式存在,無需理會,下面提供一下本地aapt解析apk的方法:1.找到自己本地sdk下build-tools的資料夾,開啟命令列,進入build-tools資料夾目錄,執行aapt dump badging .apk2.檢視是否有報錯資訊,若看得太吃力可以使用aapt dump badging .apk >1.txt將資料列印到文字中觀看好了,就這麼點內容了