在AndroidManifest.xml中添加android:extractNativeLibs后安装应用程序时出错

时间:2016-11-11 06:24:42

标签: android android-studio android-ndk android-manifest android-6.0-marshmallow

我用NDK开发了Android应用程序。我更新了Android Studio cur.ver。 2.2.2 运行该应用程序。应用程序已安装在设备中。但现在它没有在Marshmallow设备上更新,否则工作正常。在运行控制台中获取以下错误。在AndroidManifest.xml中android:extractNativeLibs="false"时。如果android:extractNativeLibs="true"则应用程序正在设备中更新。

  

$ adb shell pm install -r“/ data / local / tmp /”
  PKG:/数据/本地的/ tmp /   失败[INSTALL_FAILED_INVALID_APK]

为什么会这样?有人能解释一下吗?

1 个答案:

答案 0 :(得分:2)

经过一番调查后,我发现问题在于APK不是页面对齐的,这是由zipalign执行的额外步骤,但需要一个特定的标记。请注意,此标志可从 Build Tools版本23.0.0 开始提供。标志为-p(页面对齐存储的共享对象文件)。

$ build-tools/23.0.0/zipalign
Zip alignment utility
Copyright (C) 2009 The Android Open Source Project

Usage: zipalign [-f] [-p] [-v] [-z] <align> infile.zip outfile.zip
       zipalign -c [-v] <align> infile.zip

  <align>: alignment in bytes, e.g. '4' provides 32-bit alignment
  -c: check alignment only (does not modify file)
  -f: overwrite existing outfile.zip
  -p: page align stored shared object files
  -v: verbose output
  -z: recompress using Zopfli

所以,正确的命令是:

zipalign -p -v 4 inapk.apk outapk.apk

线索在以下logcat跟踪中:

12-21 12:31:01.706 933-999/? I/ActivityManager: Start proc 21138:com.android.defcontainer/u0a36 for service com.android.defcontainer/.DefaultContainerService
12-21 12:31:01.773 21138-21150/? E/NativeLibraryHelper: Failed to load assets verifier: 0
12-21 12:31:01.783 21138-21149/? D/DefContainer: Copying /data/local/tmp/wasabi-wallet-app-agoraProduction-release_1.27.0_#78_signed_zipaligned.apk to base.apk
12-21 12:31:01.954 933-999/? E/NativeLibraryHelper: Failed to load assets verifier: 0
12-21 12:31:01.955 933-999/? D/NativeLibraryHelper: Library 'libpanorenderer.so' is not page-aligned - will not be able to open it directly from apk.
12-21 12:31:01.955 933-999/? W/NativeHelper: Failure copying native libraries [errorCode=-2]
12-21 12:31:01.955 933-999/? I/art: Starting a blocking GC Explicit
12-21 12:31:02.042 933-999/? I/art: Explicit concurrent mark sweep GC freed 92355(7MB) AllocSpace objects, 13(308KB) LOS objects, 33% free, 27MB/41MB, paused 1.044ms total 87.077ms
12-21 12:31:02.052 21128-21128/? I/art: System.exit called, status: 1
12-21 12:31:02.052 21128-21128/? I/AndroidRuntime: VM exiting with result code 1.

有关其他信息,请参阅:#SmallerAPK, Part 8: Native libraries, open from APK(请注意,即使有命令zipalign -p 4,如果您碰巧鞭打它,也很容易将它与旧的zipalign -v 4混淆。此外,zipalign的原始文档(针对当前版本的构建工具进行了更新)zipalign