compile.sh 4.12 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
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
            ;;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
26 27 28
        -t)
            ANDROID_TV=1
            ;;
29 30 31 32 33 34 35 36 37 38 39 40 41 42
        -r|release|--release)
            RELEASE=1
            ;;
        -s|--signature)
            KEYSTORE_FILE=$2
            shift
            ;;
        -p|--password)
            PASSWORD_KEYSTORE=$2
            shift
            ;;
        run)
            RUN=1
            ;;
43
    esac
44
    shift
45 46
done

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

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

65 66 67 68 69 70 71 72
#############
# FUNCTIONS #
#############

checkfail()
{
    if [ ! $? -eq 0 ];then
        echo "$1"
73
        exit 1
74 75
    fi
}
76

77 78 79
##########
# GRADLE #
##########
Rémi Duraffort's avatar
Rémi Duraffort committed
80

81 82 83 84 85
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"
86

87 88
    unzip gradle-${GRADLE_VERSION}-all.zip
    checkfail "gradle: unzip failed"
89

90
    cd gradle-${GRADLE_VERSION}
91

92 93
    ./bin/gradle wrapper
    checkfail "gradle: wrapper failed"
Rémi Duraffort's avatar
Rémi Duraffort committed
94

95 96 97 98 99 100 101 102
    ./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
103

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

108 109 110 111 112 113 114 115
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
116
fi
Rafaël Carré's avatar
Rafaël Carré committed
117

118 119 120
####################
# Fetch VLC source #
####################
121

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
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
140

141 142 143
############
# Make VLC #
############
144

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

151
./compile-libvlc.sh $OPTS
152

153 154 155
##################
# Compile the UI #
##################
156

157
if [ "$RELEASE" = 1 ]; then
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
158 159 160 161 162
    if [ "$ANDROID_TV" = 1 ]; then
        TARGET="assembleTvRelease"
    else
        TARGET="assembleVanillaRelease"
    fi
163
else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
164 165 166 167 168
    if [ "$ANDROID_TV" = 1 ]; then
        TARGET="assembleTvDebug"
    else
        TARGET="assembleVanillaDebug"
    fi
169
fi
170

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
171 172
./gradlew $TARGET

173 174 175 176 177 178 179 180 181 182 183 184 185 186
#######
# 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