compile.sh 6.47 KB
Newer Older
Rémi Duraffort's avatar
Rémi Duraffort committed
1
#! /bin/sh
2
set -e
Rémi Duraffort's avatar
Rémi Duraffort committed
3

4 5 6 7
#############
# FUNCTIONS #
#############

8 9 10 11 12
diagnostic()
{
    echo "$@" 1>&2;
}

13 14 15 16 17 18 19 20
checkfail()
{
    if [ ! $? -eq 0 ];then
        diagnostic "$1"
        exit 1
    fi
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
21 22
# Read the Android Wiki http://wiki.videolan.org/AndroidCompile
# Setup all that stuff correctly.
23
# Get the latest Android SDK Platform or modify numbers in configure.sh and libvlc/default.properties.
Rafaël Carré's avatar
Rafaël Carré committed
24

25 26
while [ $# -gt 0 ]; do
    case $1 in
Thomas Guillem's avatar
Thomas Guillem committed
27
        help|--help|-h)
28
            echo "Use -a to set the ARCH:"
29 30
            echo "  ARM:     (armeabi-v7a|arm)"
            echo "  ARM64:   (arm64-v8a|arm64)"
31 32
            echo "  X86:     x86, x86_64"
            echo "  MIPS:    mips, mips64."
33
            echo "Use --release to build in release mode"
34
            echo "Use -s to set your keystore file and -p for the password"
Thomas Guillem's avatar
Thomas Guillem committed
35
            echo "Use -c to get a ChromeOS build"
36
            echo "Use -l to build only LibVLC"
37
            exit 0
38 39 40 41 42
            ;;
        a|-a)
            ANDROID_ABI=$2
            shift
            ;;
Thomas Guillem's avatar
Thomas Guillem committed
43 44 45
        -c)
            CHROME_OS=1
            ;;
46 47 48 49 50 51 52 53 54 55 56
        -r|release|--release)
            RELEASE=1
            ;;
        -s|--signature)
            KEYSTORE_FILE=$2
            shift
            ;;
        -p|--password)
            PASSWORD_KEYSTORE=$2
            shift
            ;;
57 58 59
        -l)
            BUILD_LIBVLC=1
            ;;
60 61 62
        run)
            RUN=1
            ;;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
63 64 65
        --asan)
            ASAN=1
            ;;
66
        *)
67 68
            diagnostic "$0: Invalid option '$1'."
            diagnostic "$0: Try --help for more information."
69 70
            exit 1
            ;;
71
    esac
72
    shift
73 74
done

75
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
76 77
   diagnostic "You must define ANDROID_NDK, ANDROID_SDK before starting."
   diagnostic "They must point to your NDK and SDK directories."
78 79 80
   exit 1
fi

81
if [ -z "$ANDROID_ABI" ]; then
82
   diagnostic "*** No ANDROID_ABI defined architecture: using ARMv7"
83
   ANDROID_ABI="armeabi-v7a"
84 85
fi

86
if [ "$ANDROID_ABI" = "armeabi-v7a" -o "$ANDROID_ABI" = "arm" ]; then
87
    GRADLE_ABI="ARMv7"
88
elif [ "$ANDROID_ABI" = "arm64-v8a" -o "$ANDROID_ABI" = "arm64" ]; then
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    GRADLE_ABI="ARMv8"
elif [ "$ANDROID_ABI" = "x86" ]; then
    GRADLE_ABI="x86"
elif [ "$ANDROID_ABI" = "x86_64" ]; then
    GRADLE_ABI="x86_64"
elif [ "$ANDROID_ABI" = "mips" ]; then
    GRADLE_ABI="MIPS"
elif [ "$ANDROID_ABI" = "mips64" ]; then
    GRADLE_ABI="MIPS64"
else
    diagnostic "Invalid arch specified: '$ANDROID_ABI'."
    diagnostic "Try --help for more information"
    exit 1
fi

104 105 106
##########
# GRADLE #
##########
Rémi Duraffort's avatar
Rémi Duraffort committed
107

108
if [ ! -d "gradle/wrapper" ]; then
109
    diagnostic "Downloading gradle"
110
    GRADLE_VERSION=3.2.1
111
    GRADLE_URL=https://download.videolan.org/pub/contrib/gradle/gradle-${GRADLE_VERSION}-all.zip
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
112
    wget ${GRADLE_URL} 2>/dev/null || curl -O ${GRADLE_URL}
113
    checkfail "gradle: download failed"
114

115
    unzip -o gradle-${GRADLE_VERSION}-all.zip
116
    checkfail "gradle: unzip failed"
117

118
    cd gradle-${GRADLE_VERSION}
119

120 121
    ./bin/gradle wrapper
    checkfail "gradle: wrapper failed"
Rémi Duraffort's avatar
Rémi Duraffort committed
122

123 124 125 126 127 128
    ./gradlew -version
    checkfail "gradle: wrapper failed"
    cd ..
    mkdir -p gradle
    mv gradle-${GRADLE_VERSION}/gradle/wrapper/ gradle
    mv gradle-${GRADLE_VERSION}/gradlew .
129
    chmod a+x gradlew
130
    rm -rf gradle-${GRADLE_VERSION}-all.zip
131
fi
132

133 134 135
####################
# Configure gradle #
####################
Rémi Duraffort's avatar
Rémi Duraffort committed
136

137 138 139 140 141
if [ -z "$KEYSTORE_FILE" ]; then
    KEYSTORE_FILE="$HOME/.android/debug.keystore"
    STOREALIAS="androiddebugkey"
else
    if [ -z "$PASSWORD_KEYSTORE" ]; then
142
        diagnostic "No password"
143 144 145 146 147 148
        exit 1
    fi
    rm -f gradle.properties
    STOREALIAS="vlc"
fi

149 150 151
if [ ! -f gradle.properties ]; then
    echo keyStoreFile=$KEYSTORE_FILE > gradle.properties
    echo storealias=$STOREALIAS >> gradle.properties
Geoffrey Métais's avatar
Geoffrey Métais committed
152
    if [ -z "$PASSWORD_KEYSTORE" ]; then
153 154
        echo storepwd=android >> gradle.properties
    fi
155 156 157 158
fi
if [ ! -f local.properties ]; then
    echo sdk.dir=$ANDROID_SDK > local.properties
    echo ndk.dir=$ANDROID_NDK >> local.properties
159
fi
Rafaël Carré's avatar
Rafaël Carré committed
160

161 162 163
# Download build tools, Android SDK version & Android AppCompat
for i in "build-tools;25.0.2" "platforms;android-24" "extras;google;m2repository"; do
    echo "Downloading $i"
164
    yes | $ANDROID_SDK/tools/bin/sdkmanager $i
165 166
done

167 168 169
####################
# Fetch VLC source #
####################
170

Thomas Guillem's avatar
Thomas Guillem committed
171
TESTED_HASH=377d831
172
if [ ! -d "vlc" ]; then
173
    diagnostic "VLC source not found, cloning"
174
    git clone http://git.videolan.org/git/vlc.git vlc
175 176
    checkfail "vlc source: git clone failed"
else
177
    diagnostic "VLC source found"
178 179
    cd vlc
    if ! git cat-file -e ${TESTED_HASH}; then
180
        cat 1>&2 << EOF
181 182 183 184 185 186 187 188
***
*** Error: Your vlc checkout does not contain the latest tested commit: ${TESTED_HASH}
***
EOF
        exit 1
    fi
    cd ..
fi
189

190 191 192
############
# Make VLC #
############
193

194
diagnostic "Configuring"
195 196
OPTS="-a ${ANDROID_ABI}"
if [ "$RELEASE" = 1 ]; then
Geoffrey Métais's avatar
Geoffrey Métais committed
197
    OPTS="$OPTS release"
198
fi
Thomas Guillem's avatar
Thomas Guillem committed
199 200 201
if [ "$CHROME_OS" = 1 ]; then
    OPTS="$OPTS -c"
fi
Thomas Guillem's avatar
Thomas Guillem committed
202 203 204
if [ "$ASAN" = 1 ]; then
    OPTS="$OPTS --asan"
fi
205

206
./compile-libvlc.sh $OPTS
207

208 209 210
##################
# Compile the UI #
##################
211 212
PLATFORM="Vanilla"
BUILDTYPE="Debug"
213
if [ "$RELEASE" = 1 ]; then
214 215
    BUILDTYPE="Release"
fi
216
if [ "$CHROME_OS" = 1 ]; then
Thomas Guillem's avatar
Thomas Guillem committed
217
    PLATFORM="Chrome"
218
fi
219 220 221 222 223
if [ "$BUILD_LIBVLC" = 1 ];then
    ./gradlew -p libvlc assemble${BUILDTYPE}
    RUN=0
    CHROME_OS=0
else
224 225 226 227 228 229
    if [ "$RUN" = 1 ]; then
        ACTION="install"
    else
        ACTION="assemble"
    fi
    TARGET="${ACTION}${PLATFORM}${GRADLE_ABI}${BUILDTYPE}"
230 231
    PASSWORD_KEYSTORE="$PASSWORD_KEYSTORE" ./gradlew $TARGET
fi
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
232

233 234 235 236 237 238 239
#######
# RUN #
#######
if [ "$RUN" = 1 ]; then
    export PATH=${ANDROID_SDK}/platform-tools/:$PATH
    adb wait-for-device
    if [ "$RELEASE" = 1 ]; then
240
        adb shell am start -n org.videolan.vlc/org.videolan.vlc.StartActivity
241
    else
242
        adb shell am start -n org.videolan.vlc.debug/org.videolan.vlc.StartActivity
243 244
    fi
fi
245 246 247 248 249

#########################
# Chrome OS repackaging #
#########################
# You need to run the armv7 version first, then relaunch this script for x86
250
if [ "$CHROME_OS" = 1 -a "$ANDROID_ABI" = "x86" ]; then
251 252 253 254 255 256
    unzip -o vlc-android/build/outputs/apk/VLC-Android-CHROME-*-ARMv7.apk lib/armeabi-v7a/libvlcjni.so
    zip -rv vlc-android/build/outputs/apk/VLC-Android-CHROME-*-x86.apk lib/armeabi-v7a/libvlcjni.so
    rm -rf lib/
    apk_to_crx.py --zip vlc-android/build/outputs/apk/VLC-Android-CHROME-*-x86.apk --metadata vlc-android/flavors/chrome/VLC-Android-CHROME.crx.json
    mv vlc-android/build/outputs/apk/VLC-Android-CHROME-*-x86.zip vlc-android/build/outputs/apk/VLC-Android-CHROME-ALL.zip
fi