Search code examples
linuxdockerandroid-ndkunzip

unzip returns non-zero code 2 on Android NDK zip (tested multiple versions)


I'm running the simple docker commands (ubuntu:bionic) to download Android NDK and unzip it:

ENV ANDROID_NDK_VERSION r21d
ENV ANDROID_NDK_URL http://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
RUN curl -L "${ANDROID_NDK_URL}" -o android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
RUN unzip android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip -d ${SDK_HOME}

But I always get (even if I prune everything and start again):

  creating: /opt/android-ndk-r21d/wrap.sh/
  inflating: /opt/android-ndk-r21d/wrap.sh/asan.sh  
The command '/bin/sh -c unzip android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip -d ${SDK_HOME}' returned a non-zero code: 2

/opt/android-ndk-r21d/wrap.sh/asan.sh is the last thing to be unzipped. On r20, it's inflating: /opt/android-ndk-r20/ndk-stack, then I get the same error.

Running unzip with -v as suggested below gives an weird output:

   16704  Defl:X     3281  80% 2019-05-22 12:47 80a0acc7  android-ndk-r20/sources/android/native_app_glue/android_native_app_glue.c
     577  Defl:X      371  36% 2019-05-22 12:47 e63c146e  android-ndk-r20/sources/android/native_app_glue/NOTICE
     439  Defl:X      282  36% 2019-05-22 12:47 8fc9fc18  android-ndk-r20/sources/android/native_app_glue/Android.mk
       0  Stored        0   0% 2019-05-22 12:47 00000000  android-ndk-r20/sources/android/renderscript/
     577  Defl:X      371  36% 2019-05-22 12:47 e63c146e  android-ndk-r20/sources/android/renderscript/NOTICE
     813  Defl:X      234  71% 2019-05-22 12:47 bfbf4628  android-ndk-r20/sources/android/renderscript/Android.mk
    2172  Defl:X     1117  49% 2019-05-22 12:47 43b8cf66  android-ndk-r20/CHANGELOG.md
      92  Defl:X       86   7% 2019-05-22 12:50 250f0ae3  android-ndk-r20/ndk-stack
--------          -------  ---                            -------
3049400190         854740668  72%                            18484 files

which executes instantly (no delay for unzipping) and then the image continues to build, but when it finishes there's nothing on the unzipped destination.

I tried downloading sdk r21c, r21b thinking that maybe it was a problem with the zip archive, but it wasn't. Container is ubuntu:bionic.


Solution

  • curl was downloading corrupt files the majority of the time. Compred using sha1 from android website and from the downloaded file.

    By moving to wget it worked...