compile.sh 6.77 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 29 30 31 32
            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."
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
            ;;
63
        *)
64 65
            diagnostic "$0: Invalid option '$1'."
            diagnostic "$0: Try --help for more information."
66 67
            exit 1
            ;;
68
    esac
69
    shift
70 71
done

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

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

83 84 85
##########
# GRADLE #
##########
Rémi Duraffort's avatar
Rémi Duraffort committed
86

87
if [ ! -d "gradle/wrapper" ]; then
88
    diagnostic "Downloading gradle"
Geoffrey Métais's avatar
Geoffrey Métais committed
89
    GRADLE_VERSION=2.10
90
    GRADLE_URL=https://download.videolan.org/pub/contrib/gradle-${GRADLE_VERSION}-all.zip
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
91
    wget ${GRADLE_URL} 2>/dev/null || curl -O ${GRADLE_URL}
92
    checkfail "gradle: download failed"
93

94
    unzip -o gradle-${GRADLE_VERSION}-all.zip
95
    checkfail "gradle: unzip failed"
96

97
    cd gradle-${GRADLE_VERSION}
98

99 100
    ./bin/gradle wrapper
    checkfail "gradle: wrapper failed"
Rémi Duraffort's avatar
Rémi Duraffort committed
101

102 103 104 105 106 107
    ./gradlew -version
    checkfail "gradle: wrapper failed"
    cd ..
    mkdir -p gradle
    mv gradle-${GRADLE_VERSION}/gradle/wrapper/ gradle
    mv gradle-${GRADLE_VERSION}/gradlew .
108
    chmod a+x gradlew
109 110
    rm -rf gradle-${GRADLE_VERSION}-all.zip gradle-${GRADLE_VERSION}
fi
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
###############
# SDK Manager #
###############

if [ ! -f "gradle/plugins/sdk-manager-plugin.jar" ]; then
    cd gradle/
    if [ -d "sdk-manager-plugin" ]; then
        rm -rf sdk-manager-plugin
    fi
    git clone https://github.com/JakeWharton/sdk-manager-plugin.git
    cd sdk-manager-plugin
    git reset --hard 1d29782dd6ffa18880c8cbada748fb3dea45e7be
    ./gradlew assemble
    cd ..
    if [ ! -d "plugins" ]; then
        mkdir plugins
    fi
    mv sdk-manager-plugin/build/libs/sdk-manager-plugin-1.5.0-SNAPSHOT.jar plugins/sdk-manager-plugin.jar
    rm -rf sdk-manager-plugin
    cd ..
fi

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

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

150 151 152
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
153
    if [ -z "$PASSWORD_KEYSTORE" ]; then
154 155
        echo storepwd=android >> gradle.properties
    fi
156 157 158 159
fi
if [ ! -f local.properties ]; then
    echo sdk.dir=$ANDROID_SDK > local.properties
    echo ndk.dir=$ANDROID_NDK >> local.properties
160
fi
Rafaël Carré's avatar
Rafaël Carré committed
161

162 163 164
####################
# Fetch VLC source #
####################
165

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

185 186 187
############
# Make VLC #
############
188

189
diagnostic "Configuring"
190 191
OPTS="-a ${ANDROID_ABI}"
if [ "$RELEASE" = 1 ]; then
Geoffrey Métais's avatar
Geoffrey Métais committed
192
    OPTS="$OPTS release"
193
fi
Thomas Guillem's avatar
Thomas Guillem committed
194 195 196
if [ "$CHROME_OS" = 1 ]; then
    OPTS="$OPTS -c"
fi
197

198
./compile-libvlc.sh $OPTS
199

200 201 202
##################
# Compile the UI #
##################
203 204
PLATFORM="Vanilla"
BUILDTYPE="Debug"
205
if [ "$RELEASE" = 1 ]; then
206 207
    BUILDTYPE="Release"
fi
208
if [ "$CHROME_OS" = 1 ]; then
Thomas Guillem's avatar
Thomas Guillem committed
209
    PLATFORM="Chrome"
210
fi
211

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
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"
228 229
else
    GRADLE_ABI="ARMv7"
230 231
fi

232 233 234 235 236
if [ "$BUILD_LIBVLC" = 1 ];then
    ./gradlew -p libvlc assemble${BUILDTYPE}
    RUN=0
    CHROME_OS=0
else
237 238 239 240 241 242
    if [ "$RUN" = 1 ]; then
        ACTION="install"
    else
        ACTION="assemble"
    fi
    TARGET="${ACTION}${PLATFORM}${GRADLE_ABI}${BUILDTYPE}"
243 244
    PASSWORD_KEYSTORE="$PASSWORD_KEYSTORE" ./gradlew $TARGET
fi
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
245

246 247 248 249 250 251 252
#######
# RUN #
#######
if [ "$RUN" = 1 ]; then
    export PATH=${ANDROID_SDK}/platform-tools/:$PATH
    adb wait-for-device
    if [ "$RELEASE" = 1 ]; then
253
        adb shell am start -n org.videolan.vlc/org.videolan.vlc.StartActivity
254
    else
255
        adb shell am start -n org.videolan.vlc.debug/org.videolan.vlc.StartActivity
256 257
    fi
fi
258 259 260 261 262

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