compile.sh 5.92 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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4 5
# Read the Android Wiki http://wiki.videolan.org/AndroidCompile
# Setup all that stuff correctly.
6
# 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
7

8 9
while [ $# -gt 0 ]; do
    case $1 in
Thomas Guillem's avatar
Thomas Guillem committed
10
        help|--help|-h)
11 12 13 14 15
            echo "Use -a to set the ARCH:"
            echo "  ARM:     armeabi-v7a, armeabi, armeabi-v5, armeabi-nofpu"
            echo "  ARM64:   arm64-v8a"
            echo "  X86:     x86, x86_64"
            echo "  MIPS:    mips, mips64."
16
            echo "Use --release to build in release mode"
17 18
            echo "Use -s to set your keystore file and -p for the password"
            echo "Use -t to get an AndroidTv build"
Thomas Guillem's avatar
Thomas Guillem committed
19
            echo "Use -c to get a ChromeOS build"
20
            exit 0
21 22 23 24 25
            ;;
        a|-a)
            ANDROID_ABI=$2
            shift
            ;;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
26 27 28
        -t)
            ANDROID_TV=1
            ;;
Thomas Guillem's avatar
Thomas Guillem committed
29 30 31
        -c)
            CHROME_OS=1
            ;;
32 33 34 35 36 37 38 39 40 41 42 43 44 45
        -r|release|--release)
            RELEASE=1
            ;;
        -s|--signature)
            KEYSTORE_FILE=$2
            shift
            ;;
        -p|--password)
            PASSWORD_KEYSTORE=$2
            shift
            ;;
        run)
            RUN=1
            ;;
46
    esac
47
    shift
48 49
done

50 51 52 53 54 55
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
   echo "You must define ANDROID_NDK, ANDROID_SDK before starting."
   echo "They must point to your NDK and SDK directories.\n"
   exit 1
fi

56 57 58
if [ -z "$ANDROID_ABI" ]; then
   echo "*** No ANDROID_ABI defined architecture: using ARMv7"
   ANDROID_ABI="armeabi-v7a"
59 60
fi

61 62 63 64 65 66 67 68
#############
# FUNCTIONS #
#############

checkfail()
{
    if [ ! $? -eq 0 ];then
        echo "$1"
69
        exit 1
70 71
    fi
}
72

73 74 75
##########
# GRADLE #
##########
Rémi Duraffort's avatar
Rémi Duraffort committed
76

77
if [ ! -d "gradle/wrapper" ]; then
78
    echo "Downloading gradle"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
79
    GRADLE_VERSION=2.6
80
    GRADLE_URL=http://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
81
    wget ${GRADLE_URL} 2>/dev/null || curl -O ${GRADLE_URL}
82
    checkfail "gradle: download failed"
83

84
    unzip -o gradle-${GRADLE_VERSION}-all.zip
85
    checkfail "gradle: unzip failed"
86

87
    cd gradle-${GRADLE_VERSION}
88

89 90
    ./bin/gradle wrapper
    checkfail "gradle: wrapper failed"
Rémi Duraffort's avatar
Rémi Duraffort committed
91

92 93 94 95 96 97
    ./gradlew -version
    checkfail "gradle: wrapper failed"
    cd ..
    mkdir -p gradle
    mv gradle-${GRADLE_VERSION}/gradle/wrapper/ gradle
    mv gradle-${GRADLE_VERSION}/gradlew .
98
    chmod a+x gradlew
99 100
    rm -rf gradle-${GRADLE_VERSION}-all.zip gradle-${GRADLE_VERSION}
fi
101

102 103 104
####################
# Configure gradle #
####################
Rémi Duraffort's avatar
Rémi Duraffort committed
105

106 107 108 109 110 111 112 113 114 115 116 117
if [ -z "$KEYSTORE_FILE" ]; then
    KEYSTORE_FILE="$HOME/.android/debug.keystore"
    STOREALIAS="androiddebugkey"
else
    if [ -z "$PASSWORD_KEYSTORE" ]; then
        echo "No password"
        exit 1
    fi
    rm -f gradle.properties
    STOREALIAS="vlc"
fi

118 119 120
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
121
    if [ -z "$PASSWORD_KEYSTORE" ]; then
122 123
        echo storepwd=android >> gradle.properties
    fi
124 125 126 127
fi
if [ ! -f local.properties ]; then
    echo sdk.dir=$ANDROID_SDK > local.properties
    echo ndk.dir=$ANDROID_NDK >> local.properties
128
fi
Rafaël Carré's avatar
Rafaël Carré committed
129

130 131 132
####################
# Fetch VLC source #
####################
133

134
TESTED_HASH=7740747
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
if [ ! -d "vlc" ]; then
    echo "VLC source not found, cloning"
    git clone git://git.videolan.org/vlc.git vlc
    checkfail "vlc source: git clone failed"
else
    echo "VLC source found"
    cd vlc
    if ! git cat-file -e ${TESTED_HASH}; then
        cat << EOF
***
*** Error: Your vlc checkout does not contain the latest tested commit: ${TESTED_HASH}
***
EOF
        exit 1
    fi
    cd ..
fi
152

153 154 155
############
# Make VLC #
############
156

157 158 159
echo "Configuring"
OPTS="-a ${ANDROID_ABI}"
if [ "$RELEASE" = 1 ]; then
Geoffrey Métais's avatar
Geoffrey Métais committed
160
    OPTS="$OPTS release"
161
fi
Thomas Guillem's avatar
Thomas Guillem committed
162 163 164
if [ "$CHROME_OS" = 1 ]; then
    OPTS="$OPTS -c"
fi
165

166
./compile-libvlc.sh $OPTS
167

168 169 170
##################
# Compile the UI #
##################
171 172
PLATFORM="Vanilla"
BUILDTYPE="Debug"
173
if [ "$RELEASE" = 1 ]; then
174 175 176 177
    BUILDTYPE="Release"
fi
if [ "$ANDROID_TV" = 1 ]; then
    PLATFORM="Tv"
Thomas Guillem's avatar
Thomas Guillem committed
178 179
elif [ "$CHROME_OS" = 1 ]; then
    PLATFORM="Chrome"
180
fi
181

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
if [ "$ANDROID_ABI" = "armeabi-v5" ]; then
    GRADLE_ABI="ARMv5"
elif [ "$ANDROID_ABI" = "armeabi" ]; then
    GRADLE_ABI="ARMv6fpu"
elif [ "$ANDROID_ABI" = "armeabi-nofpu" ]; then
    GRADLE_ABI="ARMv6nofpu"
elif [ "$ANDROID_ABI" = "arm64-v8a" ]; then
    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"
198 199
else
    GRADLE_ABI="ARMv7"
200 201 202 203
fi

TARGET="assemble${PLATFORM}${GRADLE_ABI}${BUILDTYPE}"

204
PASSWORD_KEYSTORE="$PASSWORD_KEYSTORE" ./gradlew $TARGET
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
205

206 207 208 209 210 211 212 213
#######
# RUN #
#######
if [ "$RUN" = 1 ]; then
    export PATH=${ANDROID_SDK}/platform-tools/:$PATH
    adb wait-for-device
    if [ "$RELEASE" = 1 ]; then
        adb install -r vlc-android/build/outputs/apk/vlc-android-vanilla-release.apk
Thomas Guillem's avatar
Thomas Guillem committed
214
        adb shell am start -n org.videolan.vlc/org.videolan.vlc.gui.MainActivity
215 216
    else
        adb install -r vlc-android/build/outputs/apk/vlc-android-vanilla-debug.apk
Thomas Guillem's avatar
Thomas Guillem committed
217
        adb shell am start -n org.videolan.vlc.debug/org.videolan.vlc.gui.MainActivity
218 219
    fi
fi
220 221 222 223 224 225 226 227 228 229 230 231

#########################
# Chrome OS repackaging #
#########################
# You need to run the armv7 version first, then relaunch this script for x86
if [ "$CHROME_OS" = 1 ]; then
    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