1. 程式人生 > >adb 指令uninstall解除安裝android app 處理方法

adb 指令uninstall解除安裝android app 處理方法

正常思路,想當然,兩句指令搞定應該沒啥毛病。

adb unstall ImageGrabber.apk
adb install ImageGrabber.apk

問題來了,報錯Unknown package: ImageGrabber.apk

Exception occurred while dumping:
java.lang.IllegalArgumentException: Unknown package: ImageGrabber.apk
        at com.android.server.pm.Settings.isOrphaned(Settings.java:4134)
        at com.android.server.pm.PackageManagerService.isOrphaned(PackageManagerService.java:18256)
        at com.android.server.pm.PackageManagerService.deletePackage(PackageManagerService.java:15673)
        at com.android.server.pm.PackageInstallerService.uninstall(PackageInstallerService.java:888)
        at com.android.server.pm.PackageManagerShellCommand.runUninstall(PackageManagerShellCommand.java:792)
        at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:118)
        at android.os.ShellCommand.exec(ShellCommand.java:94)
        at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:18516)
        at android.os.Binder.shellCommand(Binder.java:468)
        at android.os.Binder.onTransact(Binder.java:367)
        at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2387)
        at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3147)
        at android.os.Binder.execTransact(Binder.java:565)

手機端根本不認識這個apk,解決辦法:

將 ImageGrabber.apk整個檔案解壓,其中包含:AndroidManifest.xml,開啟之後是亂碼,彆著急,需要反編譯工具AXMLPrinter2.jar 給他翻譯一下,將這兩個檔案放在同一個目錄下,如D:\ImageGrabber

先命令列將目錄設定為D:\ImageGrabber    然後再執行java -jar AXMLPrinter2.jar AndroidManifest.xml > AndroidManifest.txt,前提是PC端裝好了Java環境,特別是要注意設定好PC端的環境變數。

C:\Users\Antony WU>d:

D:\>cd ImageGrabber

D:\ImageGrabber>java -jar AXMLPrinter2.jar AndroidManifest.xml > AndroidManifest.txt

執行完成後,用notepad++開啟AndroidManifest.txt,其中第6行就是所要的答案了package="com.qualcomm.vr.callibrationtool"

<?xml version="1.0" encoding="utf-8"?>
<manifest
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:versionCode="1"
	android:versionName="1.0"
	package="com.qualcomm.vr.callibrationtool"
	platformBuildVersionCode="25"
	platformBuildVersionName="7.1.1"
	>
	<uses-sdk
		android:minSdkVersion="15"
		android:targetSdkVersion="22"
		>
	</uses-sdk>
	<uses-permission
		android:name="android.permission.CAMERA"
		>
	</uses-permission>
	<uses-permission
		android:name="android.permission.WRITE_EXTERNAL_STORAGE"
		>
	</uses-permission>
	<meta-data
		android:name="android.support.VERSION"
		android:value="25.3.0"
		>
	</meta-data>
	<application
		android:theme="@7F0800A3"
		android:label="@7F060021"
		android:icon="@7F030000"
		android:debuggable="true"
		android:allowBackup="true"
		android:supportsRtl="true"
		android:roundIcon="@7F030001"
		>
		<activity
			android:name="com.qualcomm.vr.callibrationtool.CameraActivity"
			>
			<intent-filter
				>
				<action
					android:name="android.intent.action.MAIN"
					>
				</action>
				<category
					android:name="android.intent.category.LAUNCHER"
					>
				</category>
			</intent-filter>
		</activity>
	</application>
</manifest>

接下來就好搞了,做一個批處理檔案,連線USB線或者設定手機端和PC端的wifi在同一區域網,點選後自動執行安裝apk檔案了,免去了手動安裝的痛苦。

.\platform-tools\adb uninstall com.qualcomm.vr.callibrationtool

.\platform-tools\adb install  ImageGrabber.apk

pause

再高階一點就用c# winform做一個介面,可以把多個adb指令功能整合到一個介面裡,實現PC端一鍵控制手機端adb各類指令。