android Settings項目安裝

接着前面的settings項目的建立,繼續講一下setting怎麼安裝到真機上
--1.先按普通run android application的方式運行settings,
[2011-05-19 11:31:24 - Settings] Uploading Settings.apk onto device '0123456789ABCDEF'
[2011-05-19 11:31:26 - Settings] Installing Settings.apk...
[2011-05-19 11:31:29 - Settings] Re-installation failed due to different application signatures.
[2011-05-19 11:31:29 - Settings] You must perform a full uninstall of the application. WARNING: This will remove the application data!
[2011-05-19 11:31:29 - Settings] Please execute 'adb uninstall com.android.settings' in a shell.
[2011-05-19 11:31:29 - Settings] Launch canceled!
--2.安裝出錯,需要先卸載setting,使用adb uninstall com.android.settings,發現也失敗,我這裏提供一種可用的卸載方法:
adb shell "cd /system/app;rm Settings.apk;"
adb uninstall com.android.settings
--3.卸載ok了再次安裝
[2011-05-19 12:02:36 - Settings] Installation error: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
[2011-05-19 12:02:36 - Settings] Please check logcat output for more details.
[2011-05-19 12:02:36 - Settings] Launch canceled!
打開logcat:
01-02 09:49:09.882: ERROR/PackageManager(2002): Package com.android.settings has no signatures that match those in shared user android.uid.system; ignoring!
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
        package="com.android.settings"
        android:sharedUserId="android.uid.system"
        android:versionCode="1"
在AndroidManifest中有一個屬性android:sharedUserId,上網google一下什麼意思,它使用來指定apk的權限的,因爲setings需要訪問系統級的一些資源,所以需要添加android.uid.system的權限,但是系統權限不是任意apk可以隨意獲取的,需要系統簽名,platform.x509.pem和platform.pk8可以讓你獲得系統權限
--4.獲取platform.x509.pem和platform.pk8文件,爲你的apk進行簽名,下面是我寫的爲settings進行簽名的批處理語句
java -jar signapk.jar platform.x509.pem platform.pk8 ../Settings/bin/Settings.apk output/Settings.apk
--5.簽名後重新安裝,你會發現你的setting不在安裝在/system/app下,而是在/data/app,跟普通的應用一樣,只不過它擁有系統權限,使用的使用與原來的setting沒有任何區別

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章