compile.sh 3.88 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
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
9
   echo "You must define ANDROID_NDK, ANDROID_SDK before starting."
10
   echo "They must point to your NDK and SDK directories.\n"
Rafaël Carré's avatar
Rafaël Carré committed
11 12
   exit 1
fi
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
while [ $# -gt 0 ]; do
    case $1 in
        help|--help)
            echo "Use -a to set the ARCH"
            echo "Use --release to build in release mode"
            echo "Use -s to set your keystore file"
            exit 1
            ;;
        a|-a)
            ANDROID_ABI=$2
            shift
            ;;
        -r|release|--release)
            RELEASE=1
            ;;
        -s|--signature)
            KEYSTORE_FILE=$2
            shift
            ;;
        -p|--password)
            PASSWORD_KEYSTORE=$2
            shift
            ;;
        run)
            RUN=1
            ;;
40
    esac
41
    shift
42 43
done

44 45 46
if [ -z "$ANDROID_ABI" ]; then
   echo "*** No ANDROID_ABI defined architecture: using ARMv7"
   ANDROID_ABI="armeabi-v7a"
47 48
fi

49 50 51 52
if [ -z "$KEYSTORE_FILE" ]; then
    KEYSTORE_FILE="$HOME/.android/debug.keystore"
    PASSWORD_KEYSTORE="android"
    STOREALIAS="androiddebugkey"
Edward Wang's avatar
Edward Wang committed
53
else
54 55 56 57 58 59
    if [ -z "$PASSWORD_KEYSTORE" ]; then
        echo "No password"
        exit 1
    fi
    rm -f gradle.properties
    STOREALIAS="vlc"
Edward Wang's avatar
Edward Wang committed
60
fi
61

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

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

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

78 79 80 81 82
if [ ! -d "gradle/wrapper" ]; then
    GRADLE_VERSION=2.2.1
    GRADLE_URL=http://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
    wget ${GRADLE_URL}
    checkfail "gradle: download failed"
83

84 85
    unzip gradle-${GRADLE_VERSION}-all.zip
    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 98 99
    ./gradlew -version
    checkfail "gradle: wrapper failed"
    cd ..
    mkdir -p gradle
    mv gradle-${GRADLE_VERSION}/gradle/wrapper/ gradle
    mv gradle-${GRADLE_VERSION}/gradlew .
    rm -rf gradle-${GRADLE_VERSION}-all.zip gradle-${GRADLE_VERSION}
fi
100

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

105 106 107 108 109 110 111 112
if [ ! -f gradle.properties ]; then
    echo keyStoreFile=$KEYSTORE_FILE > gradle.properties
    echo storealias=$STOREALIAS >> gradle.properties
    echo storepwd=$PASSWORD_KEYSTORE >> gradle.properties
fi
if [ ! -f local.properties ]; then
    echo sdk.dir=$ANDROID_SDK > local.properties
    echo ndk.dir=$ANDROID_NDK >> local.properties
113
fi
Rafaël Carré's avatar
Rafaël Carré committed
114

115 116 117
####################
# Fetch VLC source #
####################
118

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
TESTED_HASH=18e445a
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
137

138 139 140
############
# Make VLC #
############
141

142 143 144 145 146
echo "Configuring"
OPTS="-a ${ANDROID_ABI}"
if [ "$RELEASE" = 1 ]; then
    OPTS+=" release"
fi
147

148
./compile-libvlc.sh $OPTS
149

150 151 152
##################
# Compile the UI #
##################
153

154 155 156 157 158
if [ "$RELEASE" = 1 ]; then
    ./gradlew assembleVanillaRelease
else
    ./gradlew assembleVanillaDebug
fi
159

160 161 162 163 164 165 166 167 168 169 170 171 172 173
#######
# RUN #
#######
if [ "$RUN" = 1 ]; then
    export PATH=${ANDROID_SDK}/platform-tools/:$PATH
    adb wait-for-device
    adb uninstall org.videolan.vlc
    if [ "$RELEASE" = 1 ]; then
        adb install -r vlc-android/build/outputs/apk/vlc-android-vanilla-release.apk
    else
        adb install -r vlc-android/build/outputs/apk/vlc-android-vanilla-debug.apk
    fi
    adb shell am start -n org.videolan.vlc/org.videolan.vlc.gui.MainActivity
fi