GS3 4.2.1利用adb安裝apk失敗問題
阿新 • • 發佈:2019-02-01
GS3更新到4.2.1後,安裝自編應用均出現錯誤INSTALL_FAILED_INTERNAL_ERROR:
解決辦法:
1.Setting -> Security -> Verify Apps去掉選擇框的選擇。
2.Setting -> Security -> Unknown sources去掉選擇框的選擇。
當安裝原始碼編譯的apk後再次安裝Eclipse編譯出的apk出現以下錯誤:
E:\send_file>adb install -r \Development.apk 1255 KB/s (71986 bytes in 0.056s) pkg: /data/local/tmp/Development.apk Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
解決辦法:
先解除安裝apk,再次安裝新的apk。
原始碼分析:
frameworks/base/services/java/com/android/server/pm/PackageManagerService.java
public PackageManagerService(Context context, Installer installer, boolean factoryTest, boolean onlyCore) { ... // Find base frameworks (resource packages without code). mFrameworkInstallObserver = new AppDirObserver( mFrameworkDir.getPath(), OBSERVER_EVENTS, true); mFrameworkInstallObserver.startWatching(); scanDirLI(mFrameworkDir, PackageParser.PARSE_IS_SYSTEM | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode | SCAN_NO_DEX, 0); // Collect all system packages. mSystemAppDir = new File(Environment.getRootDirectory(), "app"); mSystemInstallObserver = new AppDirObserver( mSystemAppDir.getPath(), OBSERVER_EVENTS, true); mSystemInstallObserver.startWatching(); scanDirLI(mSystemAppDir, PackageParser.PARSE_IS_SYSTEM | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0); // Collect all vendor packages. mVendorAppDir = new File("/vendor/app"); mVendorInstallObserver = new AppDirObserver( mVendorAppDir.getPath(), OBSERVER_EVENTS, true); mVendorInstallObserver.startWatching(); scanDirLI(mVendorAppDir, PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0); ... if (!mOnlyCore) { EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START, SystemClock.uptimeMillis()); mAppInstallObserver = new AppDirObserver( mAppInstallDir.getPath(), OBSERVER_EVENTS, false); mAppInstallObserver.startWatching(); scanDirLI(mAppInstallDir, 0, scanMode, 0); mDrmAppInstallObserver = new AppDirObserver( mDrmAppPrivateInstallDir.getPath(), OBSERVER_EVENTS, false); mDrmAppInstallObserver.startWatching(); scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK, scanMode, 0);
以上程式碼可看出系統會監視五個目錄:/system/app /data/app ...
一旦目錄中檔案出現變動,onEvent將會被呼叫:
private final class AppDirObserver extends FileObserver { ... public void onEvent(int event, String path) {... synchronized (mInstallLock) { if ((event&ADD_EVENTS) != 0) { if (p == null) { p = scanPackageLI(fullPath, (mIsRom ? PackageParser.PARSE_IS_SYSTEM | PackageParser.PARSE_IS_SYSTEM_DIR: 0) | PackageParser.PARSE_CHATTY | PackageParser.PARSE_MUST_BE_APK, SCAN_MONITOR | SCAN_NO_PATHS | SCAN_UPDATE_TIME, System.currentTimeMillis(), UserHandle.ALL); if (p != null) { /* * TODO this seems dangerous as the package may have * changed since we last acquired the mPackages * lock. */ // writer synchronized (mPackages) { updatePermissionsLPw(p.packageName, p, p.permissions.size() > 0 ? UPDATE_PERMISSIONS_ALL : 0); } addedPackage = p.applicationInfo.packageName; addedAppId = UserHandle.getAppId(p.applicationInfo.uid); } } } // reader synchronized (mPackages) { mSettings.writeLPr(); } } ... if (addedPackage != null) { Bundle extras = new Bundle(1); extras.putInt(Intent.EXTRA_UID, addedAppId); sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage, extras, null, null, addedUsers); }