无法真正通过命令行成功安装 apk [英] Could not really install apk successfully via command line

查看:69
本文介绍了无法真正通过命令行成功安装 apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pixel 3XL 无法通过 adb 安装应用程序,但可以使用 AS run 安装应用程序我使用命令行安装apk,它说它成功了.但是我在启动器中看不到图标.另外,当我尝试列出已安装的 apk 时,它不在列表中.

Pixel 3XL could not install app via adb but could using AS run to install the app I use the command line to install the apk and it said it is successfuly. But I could not see the icon in the launcher. Plus, when I try to list the installed apk, it is not in the list.

WM-C02WM0T3HTD8:~ zgong$ adb shell cmd package list packages | grep `common_string_in_package_name_with_installed_app_package`
package:A
package:B
package:C
package:D
WM-C02WM0T3HTD8:~ zgong$ adb install XXXX.apk
Performing Streamed Install
Success
WM-C02WM0T3HTD8:~ zgong$ adb shell cmd package list packages | grep `common_string_in_package_name_with_installed_app_package`
package:A
package:B
package:C
package:D

未安装新软件包.

WM-C02WM0T3HTD8:~ zgong$ adb shell cmd package list packages | grep `unique string_in_package_name`

未安装新软件包.

出现这个问题太奇怪了.

It is so weird that this issue happens.

我可以使用 adb 为其他 Android 设备安装 apk.我使用的是 Android 4.0.1.

I could use adb to install the apk for other Android device. I am using Android 4.0.1.

有人知道怎么解决吗?

更新 1:

commen 说 adb install 是 adb shell pm install 的包装器.我运行 adb shell pm 以获取选项手册.似乎没有可以帮助调试的选项.

The commen says that adb install is the wrapper of adb shell pm install. I run the adb shell pm to get the manual of options. It seems that there are no options which could help to debug.

WM-C02WM0T3HTD8:android_vdca zgong$ adb shell pm
Package manager (package) commands:
  help
    Print this help text.



  install [-rtfdgw] [-i PACKAGE] [--user USER_ID|all|current]
       [-p INHERIT_PACKAGE] [--install-location 0/1/2]
       [--install-reason 0/1/2/3/4] [--originating-uri URI]
       [--referrer URI] [--abi ABI_NAME] [--force-sdk]
       [--preload] [--instant] [--full] [--dont-kill]
       [--enable-rollback]
       [--force-uuid internal|UUID] [--pkg PACKAGE] [-S BYTES]
       [--apex] [--wait TIMEOUT]
       [PATH [SPLIT...]|-]
    Install an application.  Must provide the apk data to install, either as
    file path(s) or '-' to read from stdin.  Options are:
      -R: disallow replacement of existing application
      -t: allow test packages
      -i: specify package name of installer owning the app
      -f: install application on internal flash
      -d: allow version code downgrade (debuggable packages only)
      -p: partial application install (new split on top of existing pkg)
      -g: grant all runtime permissions
      -S: size in bytes of package, required for stdin
      --user: install under the given user.
      --dont-kill: installing a new feature split, don't kill running app
      --restrict-permissions: don't whitelist restricted permissions at install
      --originating-uri: set URI where app was downloaded from
      --referrer: set URI that instigated the install of the app
      --pkg: specify expected package name of app being installed
      --abi: override the default ABI of the platform
      --instant: cause the app to be installed as an ephemeral install app
      --full: cause the app to be installed as a non-ephemeral full app
      --install-location: force the install location:
          0=auto, 1=internal only, 2=prefer external
      --install-reason: indicates why the app is being installed:
          0=unknown, 1=admin policy, 2=device restore,
          3=device setup, 4=user request
      --force-uuid: force install on to disk volume with given UUID
      --apex: install an .apex file, not an .apk
      --wait: when performing staged install, wait TIMEOUT milliseconds
          for pre-reboot verification to complete. If TIMEOUT is not
          specified it will wait for 60000 milliseconds. 

更新 2:

复制apk到设备:

WM-C02WM0T3HTD8:android_vdca zgong$ adb push ~/Downloads/NonSIMCC-151-app-release-signed.apk /storage/emulated/0/Download/
/Users/zgong/Downloads/NonSIMCC-151-app-release-signed.apk: 1 file pushed. 12.7 MB/s (34493209 bytes in 2.597s)

通过 adb shell 使用 pm install

use pm install via adb shell

255|crosshatch:/storage/emulated/0/Download $ pm install NonSIMCC-151-app-release-signed.apk
avc:  denied  { read } for  scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
System server has no access to read file context u:object_r:fuse:s0 (from path /storage/emulated/0/Download/NonSIMCC-151-app-release-signed.apk, context u:r:system_server:s0)
Error: Unable to open file: NonSIMCC-151-app-release-signed.apk
Consider using a file under /data/local/tmp/
Error: Can't open file: NonSIMCC-151-app-release-signed.apk

Exception occurred while executing 'install':
java.lang.IllegalArgumentException: Error: Can't open file: NonSIMCC-151-app-release-signed.apk
    at com.android.server.pm.PackageManagerShellCommand.setParamsSize(PackageManagerShellCommand.java:519)
    at com.android.server.pm.PackageManagerShellCommand.doRunInstall(PackageManagerShellCommand.java:1282)
    at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:1248)
    at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:184)
    at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
    at android.os.ShellCommand.exec(ShellCommand.java:44)
    at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:21605)
    at android.os.Binder.shellCommand(Binder.java:929)
    at android.os.Binder.onTransact(Binder.java:813)
    at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4603)
    at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:4306)
    at android.os.Binder.execTransactInternal(Binder.java:1159)
    at android.os.Binder.execTransact(Binder.java:1123)

更新 3

crosshatch:/ $ cp /storage/emulated/0/Download/NonSIMCC-151-app-release-signed.apk /data/local/tmp/apk1.apk
\crosshatch:/ $ ls -la /data/local/tmp
total 51656
drwxrwx--x 4 shell shell     3488 2020-11-19 10:13 .
drwxr-x--x 4 root  root      3488 2019-11-19 14:53 ..
drwxrwxrwx 4 shell shell     3488 2020-11-10 13:55 .studio
-rw-rw---- 1 shell shell 34493209 2020-11-19 10:13 apk1.apk
-rw-rw-rw- 1 shell shell  4322329 1970-01-01 08:00 apk1592483766800.apk
-rw-rw-rw- 1 shell shell  4808820 1970-01-01 08:00 apk1597806836158.apk
-rw-rw-rw- 1 shell shell  4808820 1970-01-01 08:00 apk1597807282659.apk
-rw-rw-rw- 1 shell shell  4375675 1970-01-01 08:00 apk1599201485983.apk
drwxrwxrwx 5 shell shell     3488 2020-11-02 00:17 perfd
-rw-rw-rw- 1 shell shell        8 1970-01-01 08:00 vysor.pwd
crosshatch:/ $ pm install /data/local/tmp/ap
apk1.apk              apk1592483766800.apk  apk1597806836158.apk  apk1597807282659.apk  apk1599201485983.apk
crosshatch:/ $ pm install /data/local/tmp/apk1.apk
Success
crosshatch:/ $ exit

验证是否真实安装

WM-C02WM0T3HTD8:android_vdca zgong$ /Users/zgong/Library/Android/sdk/build-tools/29.0.3/aapt2 dump packagename ~/Downloads/NonSIMCC-151-app-release-signed.apk
com.nonsimcc.vmcp
WM-C02WM0T3HTD8:android_vdca zgong$ adb shell cmd package list packages | grep vmcp

还是无法真正安装.

更新 4

我尝试重启我的 Pixel 3XL 设备.还是运气不好.

I have tried to reboot my Pixel 3XL device. Still bad luck.

更新 5

刚刚测试并得到奇怪的结果:

Just tested and the get the weird result:

Android Studio,点击运行,即可安装并启动应用.

Android Studio, click Run, and the app could be installed and launched.

WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo
package:com.visa.mobileEnablement.loginFeatureDemo

在 Android Studio 的运行部分

In Run section in Android Studio

11/19 11:51:07: Launching 'demoApp' on Google Pixel 3 XL.
Install successfully finished in 1 s 290 ms.
$ adb shell am start -n "com.visa.mobileEnablement.loginFeatureDemo/com.visa.mobileEnablement.loginFeatureDemo.DemoActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 27798 on device 'google-pixel_3_xl-8BBY0WYAG'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.

使用从 Run 构建的相同 apk,并使用 adb install

Using the same apk built from Run, and use adb install

WM-C02WM0T3HTD8:mep_login_android zgong$ adb install -t demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
Performing Streamed Install
Success
WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo

adb install 和 Android Studio 安装过程有什么区别?

What is the difference between adb install and Android Studio installation process?

更新 6:

已经尝试撤销USB调试授权还是运气不好.

Already tried to Revoke USB debugging authorizations Still bad luck.

WM-C02WM0T3HTD8:mep_login_android zgong$ adb install -t demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apkPerforming Streamed Install
Success
WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo

还尝试关闭开发人员选项并重新打开它.设置 USB 首选项 - USE USB FOR,选择 PTP 或无数据传输.还是运气不好

Also tried to close the Developer options and reopened it. Set the USB Preferences - USE USB FOR, choose PTP or No data transfer. Still bad luck

WM-C02WM0T3HTD8:mep_login_android zgong$ adb install -t demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apkPerforming Streamed Install
Success
WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo

更新 7:

我注意到有一个操作系统更新需要我进行.

I noticed that there is an OS update for me to do.

更新 7

adb 安装"由于不匹配的 abi,​​在安装到模拟器时不起作用

"adb install" does not work when installing to the emulator due to unmatching abi

我创建了一个 AVD

Name: Pixel_3_XL_API_Q

CPU/ABI: Google APIs Intel Atom (x86)

Path: /Users/zgong/.android/avd/Pixel_3_XL_API_Q.avd

Target: google_apis [Google APIs] (API level Q)

Skin: pixel_3_xl

fastboot.chosenSnapshotFile: 

runtime.network.speed: full

hw.accelerometer: yes

hw.device.name: pixel_3_xl

hw.lcd.width: 1440

image.androidVersion.codename: Q

hw.initialOrientation: Portrait

image.androidVersion.api: 28

tag.id: google_apis

hw.mainKeys: no

hw.camera.front: emulated

avd.ini.displayname: Pixel 3 XL API Q

hw.gpu.mode: auto

hw.ramSize: 8192

PlayStore.enabled: false

fastboot.forceColdBoot: no

hw.cpu.ncore: 4

hw.keyboard: yes

hw.sensors.proximity: yes

hw.dPad: no

hw.lcd.height: 2960

vm.heapSize: 4096

skin.dynamic: yes

hw.device.manufacturer: Google

hw.gps: yes

hw.audioInput: yes

image.sysdir.1: system-images/android-Q/google_apis/x86/

showDeviceFrame: yes

hw.camera.back: virtualscene

AvdId: Pixel_3_XL_API_Q

hw.lcd.density: 560

hw.arc: false

hw.device.hash2: MD5:9bbaa408d4a8691920c4057ef7844f35

fastboot.forceChosenSnapshotBoot: no

fastboot.forceFastBoot: yes

hw.trackBall: no

hw.battery: yes

hw.sdCard: no

tag.display: Google APIs

runtime.network.latency: none

disk.dataPartition.size: 40G

hw.sensors.orientation: yes

avd.ini.encoding: UTF-8

hw.gpu.enabled: yes

我尝试安装从 Android Studio 构建的相同 apk.

I tried to install the same apk built from Android Studio.

WM-C02WM0T3HTD8:mep_login_android zgong$ adb -e install -t -r demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
Performing Streamed Install
adb: failed to install demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]

更新 8:adb安装"安装到另一台设备时工作

Update 8: "adb install" work when installing to another device

所以我使用相同的版本将其安装在另一台 Pixel 3 设备上.可以正确安装.

So I use the same build to install it on another Pixel 3 device. It can be installed correctly.

WM-C02WM0T3HTD8:mep_login_android zgong$ adb -d install -t demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
Performing Streamed Install
Success

这样,我们排除了构建的嫌疑人.

In this way, we exclude the suspect of the build.

更新 9:

在之前无法使用的 Pixel 3XL 上:

On Pixel 3XL on which it does not work before:

WM-C02WM0T3HTD8:mep_login_android zgong$ /Users/zgong/Library/Android/sdk/build-tools/29.0.3/aapt2 dump packagename demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
com.visa.mobileEnablement.loginFeatureDemo


WM-C02WM0T3HTD8:mep_login_android zgong$ adb -d uninstall com.visa.mobileEnablement.loginFeatureDemo
Success
WM-C02WM0T3HTD8:mep_login_android zgong$ adb install demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
error: more than one device/emulator
Performing Push Install
adb: error: failed to get feature set: more than one device/emulator
WM-C02WM0T3HTD8:mep_login_android zgong$ adb -d install demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
Performing Streamed Install
adb: failed to install demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
WM-C02WM0T3HTD8:mep_login_android zgong$ adb -d install -t demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
Performing Streamed Install
Success
WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep visaerror: more than one device/emulator
WM-C02WM0T3HTD8:mep_login_android zgong$ adb -d shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo
package:com.visa.mobileEnablement.loginFeatureDemo

现在我可以在 Launcher 中看到图标并可以启动应用程序.太神奇了.

And now I could see the icon in Launcher and could launch the app. So amazing.

推荐答案

在卸载apk(adb uninstall)再执行adb install时修复

It is fixed when uninstalling the apk (adb uninstall) and then execute the adb install again

WM-C02WM0T3HTD8:Downloads zgong$ adb -d install ~/Downloads/NonSIMCC-151-app-release-signed.apk
Performing Streamed Install
Success
WM-C02WM0T3HTD8:Downloads zgong$ /Users/zgong/Library/Android/sdk/build-tools/29.0.3/aapt2 dump packagename ~/Downloads/NonSIMCC-151-app-release-signed.apk
com.nonsimcc.vmcp
WM-C02WM0T3HTD8:Downloads zgong$ adb -d shell cmd package list packages | grep com.nonsimcc.vmcp
WM-C02WM0T3HTD8:Downloads zgong$ adb uninstall com.nonsimcc.vmcp
error: more than one device/emulator
- waiting for device -
error: more than one device/emulator
WM-C02WM0T3HTD8:Downloads zgong$ adb -d uninstall com.nonsimcc.vmcp
Success
WM-C02WM0T3HTD8:Downloads zgong$ adb -d shell cmd package list packages | grep com.nonsimcc.vmcp
WM-C02WM0T3HTD8:Downloads zgong$ adb -d install ~/Downloads/NonSIMCC-151-app-release-signed.apk
Performing Streamed Install
Success
WM-C02WM0T3HTD8:Downloads zgong$ adb -d shell cmd package list packages | grep com.nonsimcc.vmcp
package:com.nonsimcc.vmcp

这篇关于无法真正通过命令行成功安装 apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆