淘先锋技术网

首页 1 2 3 4 5 6 7

问题介绍

前两天从eclipse切换到Android Studio开发,出包给客户,结果客户反馈部分机型无法安装。一开始以为是加壳的问题,后来反复沟通测试后发现不是,机型主要是 努比亚Z11、红米note3、红米4pro之类的,都是Android6.0,共性就是Android6.0啦。手头没有Android6.0的机器,自己下载了一个6.0的模拟器来调试,install run都是没问题的,那问题在哪儿呢?



定位过程

在网上胡搜了一通也没找到什么快速搞定的答案,主要是不知道为啥,没有提示,我就看了一下logcat的日志,如下:

03-17 04:16:11.490 1564-1590/? I/ActivityManager: START u0 {dat=file:///sdcard/Download/com.xxxxxxx.xxxxxxxx.apk cmp=com.android.packageinstaller/.InstallAppProgress (has extras)} from uid 10012 on display 0
03-17 04:16:11.531 1364-1723/? D/AudioFlinger: mixer(0xf1e00000) throttle end: throttle time(11)
03-17 04:16:11.534 2996-3008/? D/DefContainer: Copying /sdcard/Download/com.xxxxxxx.xxxxxxxx.apk to base.apk
03-17 04:16:11.665 1564-1689/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.MOUNT_UNMOUNT_FILESYSTEMS in package: com.xxxxxxx.xxxxxxxx at: Binary XML file line #31
03-17 04:16:11.666 1564-1689/? W/PackageParser: Unknown element under <manifest>: meta-data at /data/app/vmdl901128964.tmp/base.apk Binary XML file line #34
03-17 04:16:11.666 1564-1689/? W/PackageParser: Unknown element under <manifest>: meta-data at /data/app/vmdl901128964.tmp/base.apk Binary XML file line #38
03-17 04:16:11.670 1564-1689/? W/PackageManager: Failed collect during installPackageLI
                                                 android.content.pm.PackageParser$PackageParserException: Package /data/app/vmdl901128964.tmp/base.apk has no certificates at entry AndroidManifest.xml
                                                     at android.content.pm.PackageParser.collectCertificates(PackageParser.java:1104)
                                                     at android.content.pm.PackageParser.collectCertificates(PackageParser.java:1057)
                                                     at com.android.server.pm.PackageManagerService.installPackageLI(PackageManagerService.java:12196)
                                                     at com.android.server.pm.PackageManagerService.-wrap25(PackageManagerService.java)
                                                     at com.android.server.pm.PackageManagerService$9.run(PackageManagerService.java:10156)
                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                     at android.os.Looper.loop(Looper.java:148)
                                                     at android.os.HandlerThread.run(HandlerThread.java:61)
                                                     at com.android.server.ServiceThread.run(ServiceThread.java:46)

Package /data/app/vmdl901128964.tmp/base.apk has no certificates at entry AndroidManifest.xml

看起来应该是证书签名之类的问题,但是我用的是Android Studio的Generate Signed APK来出包的,照理说应该没啥问题才是,不得其解,就根据日志去搜索了一番,果然坑早就有人踩过啦,哈哈,有人在stackoverflow提过这个问题,真是签名导致的,原链接贴在下面

https://stackoverflow.com/questions/44386464/android-app-installation-failed-package-com-my-app-has-no-certificates-at-entry

原文提及到Try to signed your APK with version 1. Version 2 signed APK only compatible from 7.0 so it will not working on below 7.0 devices or try to generate v1 and v2 version APK.

给出了API上的链接:

https://source.android.com/security/apksigning/v2

APK 签名方案 v2 是在 Android 7.0 (Nougat) 中引入的。为了使 APK 可在 Android 6.0 (Marshmallow) 及更低版本的设备上安装,应先使用 JAR 签名功能对 APK 进行签名,然后再使用 v2 方案对其进行签名。


解决方法



其实就是要在Generate Signed APK的时候勾中V1的签名方式。如上,问题解决。


其他问题

但是我在解决的过程中间还遇到一个坑,我看到“应先使用 JAR 签名功能对 APK 进行签名”这句话,就自己拿build里面的未签名的包来自己签名安装,惊人的发现,还是安装不了!logcat给出了如下日志:

03-17 04:34:08.381 1564-1593/? I/ActivityManager: START u0 {dat=file:///sdcard/Download/-com.xxxxxxx.xxxxxxxx.apk cmp=com.android.packageinstaller/.InstallAppProgress (has extras)} from uid 10012 on display 0
03-17 04:34:08.420 2996-3008/? D/DefContainer: Copying /sdcard/Download/-com.xxxxxxx.xxxxxxxx.apk to base.apk
03-17 04:34:08.448 1364-1723/? D/AudioFlinger: mixer(0xf1e00000) throttle end: throttle time(11)
03-17 04:34:08.511 2859-2872/? W/EGL_emulation: eglSurfaceAttrib not implemented
03-17 04:34:08.511 2859-2872/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe047ff80, error=EGL_SUCCESS
03-17 04:34:08.587 1564-1689/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.MOUNT_UNMOUNT_FILESYSTEMS in package: com.xxxxxxx.xxxxxxxx at: Binary XML file line #31
03-17 04:34:08.587 1564-1689/? W/PackageParser: Unknown element under <manifest>: meta-data at /data/app/vmdl529540994.tmp/base.apk Binary XML file line #34
03-17 04:34:08.587 1564-1689/? W/PackageParser: Unknown element under <manifest>: meta-data at /data/app/vmdl529540994.tmp/base.apk Binary XML file line #38
03-17 04:34:08.591 1564-1689/? W/PackageManager: installPackageLI
03-17 04:34:08.598 1564-1689/? I/art: Starting a blocking GC Explicit
03-17 04:34:08.621 1564-1689/? I/art: Explicit concurrent mark sweep GC freed 6923(397KB) AllocSpace objects, 2(40KB) LOS objects, 33% free, 6MB/9MB, paused 491us total 22.686ms
03-17 04:34:08.685 1564-1606/? I/ActivityManager: Displayed com.android.packageinstaller/.InstallAppProgress: +299ms
03-17 04:34:08.704 2859-2859/? D/InstallAppProgress: Installation error code: -15
03-17 04:34:08.740 2859-2872/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xe13f4150
03-17 04:34:08.760 2859-2872/? D/OpenGLRenderer: endAllStagingAnimators on 0xe0633d00 (RippleDrawable) with handle 0xeea92b90



Installation error code: -15是什么鬼…

本着不知道就去问的原则,得出了问题是INSTALL_FAILED_TEST_ONLY错误

实际就是不能用install run跑出来的包来签名使用,因为会在生成的安装包中manifest文件里插入使用一个android:testOnly=”true”这样的属性,意味着应用只是为了测试,如果要出包还是使用Build Apks或者Generate Signed APK吧。

贴出@zou_pl的原文链接:

http://blog.csdn.net/zou_pl/article/details/78679394