1

I have an app which locate in /system/priv-app/MyTestApp. The android source code environment is Android P (API 28).

At first, the MyTestApp.apk was build with gradle build tools 3.6.1. Then I upgrade it to 4.1.0 and build a new MyTestApp.apk and prebuilt it in the rom. So the crash happens.

E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/priv-app/MyTestApp/MyTestApp.apk!/lib/armeabi-v7a/libmytest.so" not found
E AndroidRuntime:       at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
E AndroidRuntime:       at java.lang.System.loadLibrary(System.java:1669)

I pull the file /system/priv-app/MyTestApp/MyTestApp.apk, extract the file and found that the libmytest.so exists. It definitely caused by gradle build tools upgrade. But I can't find the reason. Could anyone give some help?

bitristan
  • 631
  • 8
  • 16

4 Answers4

0

After looking to the source code, I found that in bionic/linker/linker.cpp

if (entry.method != kCompressStored || (entry.offset % PAGE_SIZE) != 0) {
  close(fd);
  return -1;
}

entry.offset % PAGE_SIZE != 0 this condition fails.

So I guess there's something wrong with zipalign of AGP 4.1+.

Still looking into it.

bitristan
  • 631
  • 8
  • 16
0

Android build system will uncompress dex files embedded in apk for privileged apps as long as the property DONT_UNCOMPRESS_PRIV_APPS_DEXS not defined. The uncompress definition is as below

# Uncompress dex files embedded in an apk.
#
define uncompress-dexs
$(hide) if (zipinfo $@ '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then \
  tmpdir=$@.tmpdir; \
  rm -rf $$tmpdir && mkdir $$tmpdir; \
  unzip -q $@ '*.dex' -d $$tmpdir && \
  zip -qd $@ '*.dex' && \
  ( cd $$tmpdir && find . -type f | sort | zip -qD -X -0 ../$(notdir $@) -@ ) && \
  rm -rf $$tmpdir; \
  fi
endef

When apk build with AGP 4.0, after uncompress-dexs, it can be success verified by zipalign tool.

zipalign -v -c -p 4 MyTestApp.apk

But when build with AGP 4.1+ (also include 7.0-alpha), it can't be verified by zipalign tool.

But I haven't find the reason yet. Just guess that there is something new change about apk archive in AGP 4.1+.

bitristan
  • 631
  • 8
  • 16
0
android.useNewApkCreator=false

Add this line in gradle.properties can solve this issue.

But since AGP 3.6+, the default value of this property is true. So it should not be the difference between AGP 4.0 and AGP 4.1.

I'm so confused. There maybe some else conditions to make effect.

bitristan
  • 631
  • 8
  • 16
0

refer to lastest code, the uncompress-dexs method is like below

https://android.googlesource.com/platform/build/+/master/core/definitions.mk#2385

# Uncompress dex files embedded in an apk.
#
define uncompress-dexs
  if (zipinfo $@ '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then \
    $(ZIP2ZIP) -i $@ -o $@.tmp -0 "classes*.dex" && \
    mv -f $@.tmp $@ ; \
  fi
endef
bitristan
  • 631
  • 8
  • 16