compile.sh 4.49 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 10
while [ $# -gt 0 ]; do
    case $1 in
        help|--help)
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 19
            echo "Use -s to set your keystore file and -p for the password"
            echo "Use -t to get an AndroidTv build"
            exit 0
20 21 22 23 24
            ;;
        a|-a)
            ANDROID_ABI=$2
            shift
            ;;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
25 26 27
        -t)
            ANDROID_TV=1
            ;;
28 29 30 31 32 33 34 35 36 37 38 39 40 41
        -r|release|--release)
            RELEASE=1
            ;;
        -s|--signature)
            KEYSTORE_FILE=$2
            shift
            ;;
        -p|--password)
            PASSWORD_KEYSTORE=$2
            shift
            ;;
        run)
            RUN=1
            ;;
42
    esac
43
    shift
44 45
done

46 47 48 49 50 51
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

52 53 54
if [ -z "$ANDROID_ABI" ]; then
   echo "*** No ANDROID_ABI defined architecture: using ARMv7"
   ANDROID_ABI="armeabi-v7a"
55 56
fi

57 58 59 60 61 62 63 64
#############
# FUNCTIONS #
#############

checkfail()
{
    if [ ! $? -eq 0 ];then
        echo "$1"
65
        exit 1
66 67
    fi
}
68

69 70 71
##########
# GRADLE #
##########
Rémi Duraffort's avatar
Rémi Duraffort committed
72

73 74 75 76 77
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"
78

79 80
    unzip gradle-${GRADLE_VERSION}-all.zip
    checkfail "gradle: unzip failed"
81

82
    cd gradle-${GRADLE_VERSION}
83

84 85
    ./bin/gradle wrapper
    checkfail "gradle: wrapper failed"
Rémi Duraffort's avatar
Rémi Duraffort committed
86

87 88 89 90 91 92 93 94
    ./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
95

96 97 98
####################
# Configure gradle #
####################
Rémi Duraffort's avatar
Rémi Duraffort committed
99

100 101 102 103 104 105 106 107 108 109 110 111
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

112 113 114
if [ ! -f gradle.properties ]; then
    echo keyStoreFile=$KEYSTORE_FILE > gradle.properties
    echo storealias=$STOREALIAS >> gradle.properties
115 116 117
    if [ -z PASSWORD_KEYSTORE ]; then
        echo storepwd=android >> gradle.properties
    fi
118 119 120 121
fi
if [ ! -f local.properties ]; then
    echo sdk.dir=$ANDROID_SDK > local.properties
    echo ndk.dir=$ANDROID_NDK >> local.properties
122
fi
Rafaël Carré's avatar
Rafaël Carré committed
123

124 125 126
####################
# Fetch VLC source #
####################
127

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
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
146

147 148 149
############
# Make VLC #
############
150

151 152 153 154 155
echo "Configuring"
OPTS="-a ${ANDROID_ABI}"
if [ "$RELEASE" = 1 ]; then
    OPTS+=" release"
fi
156

157
./compile-libvlc.sh $OPTS
158

159 160 161
##################
# Compile the UI #
##################
162

163
if [ "$RELEASE" = 1 ]; then
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
164 165 166 167 168
    if [ "$ANDROID_TV" = 1 ]; then
        TARGET="assembleTvRelease"
    else
        TARGET="assembleVanillaRelease"
    fi
169
else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
170 171 172 173 174
    if [ "$ANDROID_TV" = 1 ]; then
        TARGET="assembleTvDebug"
    else
        TARGET="assembleVanillaDebug"
    fi
175
fi
176

177
PASSWORD_KEYSTORE="$PASSWORD_KEYSTORE" ./gradlew $TARGET
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
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
    if [ "$RELEASE" = 1 ]; then
        adb install -r vlc-android/build/outputs/apk/vlc-android-vanilla-release.apk
Thomas Guillem's avatar
Thomas Guillem committed
187
        adb shell am start -n org.videolan.vlc/org.videolan.vlc.gui.MainActivity
188 189
    else
        adb install -r vlc-android/build/outputs/apk/vlc-android-vanilla-debug.apk
Thomas Guillem's avatar
Thomas Guillem committed
190
        adb shell am start -n org.videolan.vlc.debug/org.videolan.vlc.gui.MainActivity
191 192
    fi
fi