1.adb push XXX.apk 目錄是將apk發(fā)送到手機(jī)指定的目錄
????adb push test.apk /sdcard/test/test.apk
2.adb install 電腦中apk的路徑是安裝電腦中的apk到手機(jī)
????adb install /Users/test/test.apk
3.強(qiáng)制安裝
????有時(shí)候會(huì)出現(xiàn)Read-only的錯(cuò)誤塘辅,我們可以使用強(qiáng)制安裝命令來(lái)安裝apk
????adb install -r /Users/test/test.apk
adb的安裝過(guò)程分為傳輸與安裝兩步陪竿。
在出錯(cuò)后灭忠,adb會(huì)報(bào)告錯(cuò)誤信息跷乐,但是信息可能只是一個(gè)代號(hào)肥败,需要自己定位分析出錯(cuò)的原因。??
幾種常見(jiàn)的錯(cuò)誤及解決方法:?
1愕提、INSTALL_FAILED_INVALID_APK:無(wú)效的安裝包,安裝包已損壞
????????????請(qǐng)檢查安裝包是否完整馒稍。如果是xpk包,可以通過(guò)手動(dòng)安裝xpk來(lái)檢測(cè)一下浅侨。如果是apk包纽谒,請(qǐng)重 ? 新下載。
2如输、INSTALL_FAILED_OLDER_SDK:系統(tǒng)版本過(guò)低
????????????當(dāng)前程序不支持您的手機(jī)鼓黔。
3央勒、INSTALL_FAILED_INSUFFICIENT_STORAGE:沒(méi)有足夠的存儲(chǔ)空間
4、INSTALL_FAILED_INVALID_INSTALL_LOCATION:無(wú)效的安裝位置
5澳化、INSTALL_CANCELED_BY_USER:系統(tǒng)禁止安裝未知來(lái)源的應(yīng)用
????????????這個(gè)要在Android系統(tǒng)設(shè)置里修改崔步,勾選安全選項(xiàng)里的未知來(lái)源,允許安裝缎谷。
6井濒、INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES:安裝包簽名不一致
????????????這樣的問(wèn)題主要是簽名沖突造成的,比如你使用了ADB的debug權(quán)限簽名慎陵,但后來(lái)使用標(biāo)準(zhǔn)sign簽名后再安裝同一個(gè)文件會(huì)出現(xiàn)這樣的錯(cuò)誤提示眼虱,解決的方法除了只有先老老實(shí)實(shí)從手機(jī)上卸載原有版本再進(jìn)行安裝,而adb install -r參數(shù)也無(wú)法解決這個(gè)問(wèn)題席纽。
7捏悬、INSTALL_FAILED_INVALID_URI:
????????????應(yīng)用為中文名, adb install 中文.apk時(shí)出現(xiàn)此問(wèn)題。修改為英文名就OK了润梯。
錯(cuò)誤基本是在 cmd 命令行安裝時(shí)遇到的过牙。
INSTALL_FAILED_ALREADY_EXISTS ? ? ? ? ? ? ? ? 程序已經(jīng)存在
INSTALL_FAILED_INVALID_APK ? ? ? ? ? ? ? ? ? ? 無(wú)效的APK
INSTALL_FAILED_INVALID_URI ? ? ? ? ? ? ? ? ? ? 無(wú)效的鏈接
INSTALL_FAILED_INSUFFICIENT_STORAGE ? ? ? ? ?沒(méi)有足夠的存儲(chǔ)空間
INSTALL_FAILED_DUPLICATE_PACKAGE ? ? ? ? ? ? 已存在同名程序
INSTALL_FAILED_NO_SHARED_USER ? ? ? ? ? ? ? ?要求的共享用戶不存在
INSTALL_FAILED_UPDATE_INCOMPATIBLE ? ? ? ? ? 版本不能共存
INSTALL_FAILED_SHARED_USER_INCOMPATIBLE ? ? 需求的共享用戶簽名錯(cuò)誤
INSTALL_FAILED_MISSING_SHARED_LIBRARY ? ? ? 需求的共享庫(kù)已丟失
INSTALL_FAILED_REPLACE_COULDNT_DELETE ? ? ?需求的共享庫(kù)無(wú)效
INSTALL_FAILED_DEXOPT ? ? ? ? ? ? ? ? ? ? ? ? ?dex優(yōu)化驗(yàn)證失敗
INSTALL_FAILED_OLDER_SDK ? ? ? ? ? ? ? ? ? ? ?系統(tǒng)版本過(guò)舊
INSTALL_FAILED_CONFLICTING_PROVIDER ? ? ? ? ?存在同名的內(nèi)容提供者
INSTALL_FAILED_NEWER_SDK ? ? ? ? ? ? ? ? ? ? ?系統(tǒng)版本過(guò)新
INSTALL_FAILED_TEST_ONLY ? ? ? ? ? ? ? ? ? ? ?調(diào)用者不被允許測(cè)試的測(cè)試程序
INSTALL_FAILED_CPU_ABI_INCOMPATIBLE ? ? ? ? 包含的本機(jī)代碼不兼容
CPU_ABIINSTALL_FAILED_MISSING_FEATURE ? ? ? 使用了一個(gè)無(wú)效的特性
INSTALL_FAILED_CONTAINER_ERROR ? ? ? ? ? ? ?SD卡訪問(wèn)失敗
INSTALL_FAILED_INVALID_INSTALL_LOCATION ? ? 無(wú)效的安裝路徑
INSTALL_FAILED_MEDIA_UNAVAILABLE ? ? ? ? ? ?SD卡不存在
INSTALL_FAILED_INTERNAL_ERROR ? ? ? ? ? ? ? ?系統(tǒng)問(wèn)題導(dǎo)致安裝失敗
DEFAULT ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?未知錯(cuò)誤
INSTALL_FAILED_VERSION_DOWNGRADE ?當(dāng)前程序的版本低于已安裝的程序CPU_ABIINSTALL_FAILED_MISSING_FEATURE ??使用了一個(gè)無(wú)效的特性
安裝APK的錯(cuò)誤碼android源碼
安裝APK的錯(cuò)誤碼,定義在android源碼中的這個(gè)文件中:
frameworks\base\core\java\android\content\pm\PackageManager.java
/**
* if the package is already installed.
* 程序已經(jīng)存在
*/
public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
/**
* if the package archive file is invalid.
* 無(wú)效的APK
*/
public static final int INSTALL_FAILED_INVALID_APK = -2;
/**
* if the URI passed in is invalid.
* 無(wú)效的鏈接
*/
public static final int INSTALL_FAILED_INVALID_URI = -3;
/**
* if the package manager service found that the device?
* didn't have enough storage space to install the app.
* 沒(méi)有足夠的存儲(chǔ)空間
*/
public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
/**
* if a package is already installed with the same name.
* 已存在同名程序
*/
public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
/**
* if the requested shared user does not exist.
* 共享用戶不存在
*/
public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
/**
* if a previously installed package of the same name has a different signature
* than the new package (and the old package's data was not removed).
* 更新不兼容
*/
public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
/**
* if the new package is requested a shared user which is already installed?
* on the device and does not have matching signature.
* 共享用戶不兼容
*/
public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
/**
* if the new package uses a shared library that is not available.
* 共享庫(kù)已丟失
*/
public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
/**
* if the new package uses a shared library that is not available.
* 替換時(shí)無(wú)法刪除
*/
public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
/**
* if the new package failed while optimizing and validating its dex files,
* either because there was not enough storage or the validation failed.
* 空間不足或驗(yàn)證失敗
*/
public static final int INSTALL_FAILED_DEXOPT = -11;
/**
* if the new package failed because the current SDK version is older than
* that required by the package.
* 系統(tǒng)版本過(guò)舊
*/
public static final int INSTALL_FAILED_OLDER_SDK = -12;
/**
* if the new package failed because it contains a content provider with the
* same authority as a provider already installed in the system.
* 存在同名的內(nèi)容提供者
*/
public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
/**
* if the new package failed because the current SDK version is newer than
* that required by the package.
* 系統(tǒng)版本過(guò)新
*/
public static final int INSTALL_FAILED_NEWER_SDK = -14;
/**
* if the new package failed because it has specified that it is a test-only
* package and the caller has not supplied the {@link #INSTALL_ALLOW_TEST}
* flag.
* 調(diào)用者不被允許測(cè)試的測(cè)試程序
*/
public static final int INSTALL_FAILED_TEST_ONLY = -15;
/**
* if the package being installed contains native code, but none that is
* compatible with the the device's CPU_ABI.
* 包含的本機(jī)代碼不兼容CPU_ABI
*/
public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
/**
* if the new package uses a feature that is not available.
* 使用了一個(gè)無(wú)效的特性
*/
public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
// ------ Errors related to sdcard
/**
* if a secure container mount point couldn't be accessed on external media.
* SD卡訪問(wèn)失敗
*/
public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;
/**
* if the new package couldn't be installed in the specified install location.
* 無(wú)效的安裝路徑
*/
public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;
/**
* if the new package couldn't be installed in the specified install
* location because the media is not available.
* SD卡不可用
*/
public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;
/**
* if the new package couldn't be installed because the verification timed out.
* 驗(yàn)證超時(shí)
*/
public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT = -21;
/**
* if the new package couldn't be installed because the verification did not succeed.
* 驗(yàn)證失敗
*/
public static final int INSTALL_FAILED_VERIFICATION_FAILURE = -22;
/**
* if the package changed from what the calling program expected.
* 預(yù)期的應(yīng)用被改變
*/
public static final int INSTALL_FAILED_PACKAGE_CHANGED = -23;
/**
* if the parser was given a path that is not a file, or does not end?
* with the expected '.apk' extension.
* 解析失敗纺铭,不是APK
*/
public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
/**
* if the parser was unable to retrieve the AndroidManifest.xml file.
* 解析失敗寇钉,無(wú)法提取Manifest
*/
public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
/**
* if the parser encountered an unexpected exception.
* 解析失敗,無(wú)法預(yù)期的異常
*/
public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
/**
* if the parser did not find any certificates in the .apk.
* 解析失敗舶赔,找不到證書(shū)
*/
public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
/**
* if the parser found inconsistent certificates on the files in the .apk.
* 解析失敗扫倡,證書(shū)不一致
*/
public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
/**
* if the parser encountered a CertificateEncodingException in one of the
* files in the .apk.
* 解析失敗,證書(shū)編碼異常
*/
public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
/**
* if the parser encountered a bad or missing package name in the manifest.
* 解析失敗竟纳,manifest中的包名錯(cuò)誤或丟失
*/
public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
/**
* if the parser encountered a bad shared user id name in the manifest.
* 解析失敗撵溃,manifest中的共享用戶錯(cuò)誤
*/
public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
/**
* if the parser encountered some structural problem in the manifest.
* 解析失敗,manifest中出現(xiàn)結(jié)構(gòu)性錯(cuò)誤
*/
public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
/**
* if the parser did not find any actionable tags (instrumentation or application)
* in the manifest.
* 解析失敗锥累,manifest中沒(méi)有actionable tags
*/
public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
/**
* if the system failed to install the package because of system issues.
* 系統(tǒng)問(wèn)題導(dǎo)致安裝失敗
*/
public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;