shadowsocks / shadowsocks-android

A shadowsocks client for Android
Other
35.14k stars 11.59k forks source link

Build from docker image (ubuntu:xenial), but got invalid apk file. #1461

Closed kimw closed 6 years ago

kimw commented 6 years ago

I was trying to build shadowsocks-android from docker image. The building process is successful, but apk file is invalid.

Build steps are,

  1. Command in host

    docker run --rm -it ubuntu:xenial bash
  2. Commands in docker image

    # envs
    export ANDROID_COMPILE_SDK="25"
    export ANDROID_SDK_TOOLS="25.2.5"
    export ANDROID_BUILD_TOOLS="27.0.0"
    export ANDROID_NDK=r15b
    export NDK_CCACHE=ccache
    export GOROOT_BOOTSTRAP=/usr/lib/go
    export ANDROID_HOME=/android/android-sdk-linux
    export ANDROID_NDK_HOME=/android/android-ndk-${ANDROID_NDK}
    export ARCH=$(uname -m)
    export SBTPATH=${HOME}/.sbt
    export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_NDK_HOME}
    export WORKDIR=/workdir
    
    # make dirs
    mkdir -p ${ANDROID_HOME}
    mkdir -p ${WORKDIR}
    mkdir -p ${SBTPATH}
    
    apt-get update && apt-get install --yes --no-install-recommends \
        python-minimal python-pip build-essential ccache git wget unzip file \
        golang-go openjdk-8-jdk
    
    # install android sdk tools
    wget -q https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
    unzip -q tools_r${ANDROID_SDK_TOOLS}-linux.zip -d ${ANDROID_HOME}
    echo y | ${ANDROID_HOME}/tools/android -s update sdk -u -a -t \
        android-${ANDROID_COMPILE_SDK},tools,platform-tools,build-tools-${ANDROID_BUILD_TOOLS},extra-android-m2repository,extra-google-m2repository
    
    # install android ndk
    wget -q https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK}-linux-${ARCH}.zip
    unzip -q android-ndk-${ANDROID_NDK}-linux-${ARCH}.zip -d /android
    ndk-build --version
    
    # install sbt-extras
    if [ ! -f "${SBTPATH}/sbt" ]; then
        mkdir -p ${SBTPATH}
        pushd ${SBTPATH}
        wget -q https://raw.githubusercontent.com/paulp/sbt-extras/master/sbt
        chmod a+x sbt
        popd
    fi
    
    # system informations
    uname -a
    free -m
    df -h
    wget --version
    gcc --version
    make --version
    ccache --version
    java -Xmx32m -version
    javac -J-Xmx32m -version
    
    # go build    
    cd ${WORKDIR}
    git clone https://github.com/shadowsocks/shadowsocks-android.git
    cd shadowsocks-android
    git submodule update --init --recursive
    ${SBTPATH}/sbt clean go-build android:package
    
    # clean locks
    find ${HOME}/.sbt -name "*.lock" | xargs rm
    find ${HOME}/.ivy2 -name "*.lock" | xargs rm

The compiling is successful and I got 2 files stored in /workdir/shadowsocks-android/mobile/target/android/output, which are shadowsocks-debug.apk & shadowsocks-debug-unaligned.apk. Any of these 2 files can not installed in Adnroid 7.0.0 (Samsung S6 Edge).

I unzipped the apk files and find that the structure are different from official release file (https://github.com/shadowsocks/shadowsocks-android/releases/download/v4.2.5/shadowsocks-nightly-4.2.5.apk), shown as pictures attached.

What can I do to build a valid apk file?


ATTACHMENTS

kimw commented 6 years ago

system information

$ uname -a
Linux 69fd5a3a817e 4.13.12-041312-generic #201711080535 SMP Wed Nov 8 10:40:26 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7887        1876        3636         529        2375        5128
Swap:          1023           0        1023

$ df -h
Filesystem               Size  Used Avail Use% Mounted on
overlay                   15G  4.7G  9.4G  34% /
tmpfs                     64M     0   64M   0% /dev
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/Air--vg-var   15G  4.7G  9.4G  34% /etc/hosts
shm                       64M     0   64M   0% /dev/shm
tmpfs                    3.9G     0  3.9G   0% /sys/firmware

$ wget --version
GNU Wget 1.17.1 built on linux-gnu.

+digest -gpgme +https +ipv6 +iri +large-file -metalink +nls +ntlm 
+opie -psl +ssl/openssl 

Wgetrc: 
    /etc/wgetrc (system)
Locale: 
    /usr/share/locale 
Compile: 
    gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/etc/wgetrc" 
    -DLOCALEDIR="/usr/share/locale" -I. -I../../src -I../lib 
    -I../../lib -Wdate-time -D_FORTIFY_SOURCE=2 -I/usr/include 
    -DHAVE_LIBSSL -DNDEBUG -g -O2 -fPIE -fstack-protector-strong 
    -Wformat -Werror=format-security -DNO_SSLv2 -D_FILE_OFFSET_BITS=64 
    -g -Wall 
Link: 
    gcc -DHAVE_LIBSSL -DNDEBUG -g -O2 -fPIE -fstack-protector-strong 
    -Wformat -Werror=format-security -DNO_SSLv2 -D_FILE_OFFSET_BITS=64 
    -g -Wall -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro 
    -Wl,-z,now -L/usr/lib -lpcre -luuid -lssl -lcrypto -lz -lidn 
    ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a 

Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
Please send bug reports and questions to <bug-wget@gnu.org>.

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ ccache --version
ccache version 3.2.4

Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2015 Joel Rosdahl

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.

$ java -Xmx32m -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

$ javac -J-Xmx32m -version
javac 1.8.0_151
wongsyrone commented 6 years ago

https://github.com/scala-android/sbt-android#usage

Mygod commented 6 years ago

Define invalid.

madeye commented 6 years ago

It's because you're building a debug APK, which would include additional debug files in that APK.

kimw commented 6 years ago

@Mygod

INVALID means - When I try to install shadowsocks-release-unsigned.apk into my device, it reports The package appears to be corrupt. See attachment.

Device: Samsung S6 Edge Android: 7.0

PS, the installation of both shadowsocks-debug.apk and shadowsocks-debug-unaligned.apk are OK.

screenshot_20171121-073255

kimw commented 6 years ago

@madeye

I'm not sure it's caused by different building target. Because I found debug build & release build are in the same file structure. See pic attached.

All 3 apk files are built today morning.

screenshot from 2017-11-21 11 26 56

kimw commented 6 years ago

@wongsyrone Thanks for your reply. The doc is very useful. It helps me to read the code easy more.

madeye commented 6 years ago

You cannot install shadowsocks-release-unsigned.apk to any device. It's expected.

Please follow https://developer.android.com/studio/publish/app-signing.html to sign the APK with your key.

kimw commented 6 years ago

@madeye Thank you.