描述:
Android6.0以上支持内置Native库,不需要解压部署到文件系统中。后续可以利用该机制节省空间。
具体原理是本地库在APK中的位置是对齐到文件系统块的,并且没有压缩,可以直接映射APK中某个文件数据到内存页面。
在集成到应用以及通过网络分发,插件APK是被压缩的,所以不影响应用体积和网络流量。
Source code
[libcore] DexPathList
备注1:
通过 Androd.mk 编译的结果
Android SDK 21 (5.0) 不是 zipalign 的
Android SDK 23 (6.0) 已经是 zipalign 的
# zipalign -c -v 4 WallpaperPlayerService.apk
Verifying alignment of WallpaperPlayerService.apk (4)...
4096 lib/armeabi-v7a/libbreakpad_jni.so (OK)
131072 lib/armeabi-v7a/libidmap_jni.so (OK)
278528 lib/armeabi-v7a/liblogcat_jni.so (OK)
316960 res/drawable-xhdpi-v4/ic_launcher.png (OK)
326228 res/drawable-xhdpi-v4/leak_canary_icon.png (OK)
329332 res/drawable-xhdpi-v4/leak_canary_notification.png (OK)
330724 res/drawable-xhdpi-v4/music_start_focused.png (OK)
340988 resources.arsc (OK)
355917 AndroidManifest.xml (OK - compressed)
358979 assets/prop/wplayer.ini (OK - compressed)
359408 assets/prop/wptest.ini (OK - compressed)
359711 classes.dex (OK - compressed)
1256415 res/color/player_txt_cor.xml (OK - compressed)
1256762 res/drawable/leak_canary_toast_background.xml (OK - compressed)
1257071 res/drawable/player_item.xml (OK - compressed)
1257370 res/drawable/player_item_focus_bak.xml (OK - compressed)
1257748 res/layout-v17/leak_canary_ref_row.xml (OK - compressed)
1258324 res/layout/leak_canary_display_leak.xml (OK - compressed)
1258852 res/layout/leak_canary_heap_dump_toast.xml (OK - compressed)
1259349 res/layout/leak_canary_leak_row.xml (OK - compressed)
1259840 res/layout/leak_canary_ref_row.xml (OK - compressed)
1260375 res/layout/leak_canary_ref_top_row.xml (OK - compressed)
1260761 res/layout/monitor_list_item.xml (OK - compressed)
1261303 res/layout/monitor_list_item_title.xml (OK - compressed)
1261716 res/layout/player_videoview.xml (OK - compressed)
1262052 res/layout/test_login.xml (OK - compressed)
1262651 res/layout/test_menu_item.xml (OK - compressed)
1263104 res/layout/test_menu_list.xml (OK - compressed)
1263431 res/layout/test_wallpaper.xml (OK - compressed)
1263908 res/layout/wallpaper_player.xml (OK - compressed)
1264258 res/xml/pptvwallpaper.xml (OK - compressed)
1264585 META-INF/MANIFEST.MF (OK - compressed)
1265828 META-INF/CERT.SF (OK - compressed)
1267095 META-INF/CERT.RSA (OK - compressed)
备注2:
在 938 (N55)上加载成功,见附件 provider.maps
没有找到 just so,有很多 PptvMedia.apk 的文件映射
e1eb1000-e2246000 r-xp 002e8000 103:04 757 /data/data/com.pptv.wallpaperplayer/cache/plugins/PptvMedia.apk
e2246000-e2258000 r--p 0067c000 103:04 757 /data/data/com.pptv.wallpaperplayer/cache/plugins/PptvMedia.apk
e2258000-e2259000 rw-p 0068e000 103:04 757 /data/data/com.pptv.wallpaperplayer/cache/plugins/PptvMedia.apk
备注3:
但是从系统角度来看,并没有让 WallpaperPlayerService 使用 apk 里面的 so
e01c3000-e01e0000 r-xp 00000000 103:04 3042 /data/app/com.pptv.wallpaperplayer-1/lib/arm/libbreakpad_jni.so
e01e0000-e01e2000 r--p 0001c000 103:04 3042 /data/app/com.pptv.wallpaperplayer-1/lib/arm/libbreakpad_jni.so
e01e2000-e01e3000 rw-p 0001e000 103:04 3042 /data/app/com.pptv.wallpaperplayer-1/lib/arm/libbreakpad_jni.so
加上 android:extractNativeLibs="false" 也没有用