Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error installing application after adding android:extractNativeLibs in AndroidManifest.xml

I developed Android application with NDK. I updated Android Studio cur.ver. 2.2.2 Run the application. Application is already installed in device. But now it was not updating in Marshmallow device, else working fine. Getting following error in Run console. When android:extractNativeLibs="false" in AndroidManifest.xml. If android:extractNativeLibs="true" then Application is updating in device.

$ adb shell pm install -r "/data/local/tmp/"
pkg:/data/local/tmp/ Failure [INSTALL_FAILED_INVALID_APK]

Why this happening? Can anyone explain me?

like image 768
Ankita Shah Avatar asked Nov 11 '16 06:11

Ankita Shah


People also ask

What is Android extractNativeLibs true?

When extractNativeLibs is set to true (default) or not added to the manifest, your native libraries can be stored compressed in the APK. They are extracted by the PackageManager during installation, and a copy is put to /data/app/.

What is Android supportsRtl?

android:supportsRtl. Declares whether your application is willing to support right-to-left (RTL) layouts. If set to true and targetSdkVersion is set to 17 or higher, various RTL APIs will be activated and used by the system so your app can display RTL layouts.

What is usesCleartextTraffic?

Similar to the App Transport Security (ATS) feature in iOS (see also best practice 6.5 Implement App Transport Security), Android 6.0 and later makes it easier to prevent an app from using cleartext network traffic (e.g., HTTP and FTP without TLS) by adding the android:usesCleartextTraffic attribute to the Android ...

What is application manifest in Android?

The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.


1 Answers

After some investigation, I found out that the problem was that the APK was not page-aligned, which is an additional step performed by zipalign, but needs an specific flag. It is important to notice that this flag is available starting from Build Tools version 23.0.0. Flag is -p (page align stored shared object files).

$ 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

So, the right command is:

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

The clue was in the following logcat trace:

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.

For additional information see: #SmallerAPK, Part 8: Native libraries, open from APK (notice that even there is the command zipalign -p 4 it's quite easy to confuse it with the old common zipalign -v 4, if you happen to whip through it. Also, original documentation for zipalign (updated for current versions of Build Tools) zipalign.

like image 193
Xavier Rubio Jansana Avatar answered Nov 14 '22 21:11

Xavier Rubio Jansana