[Android] build: make compile-liblvc.sh stand alone

Thomas Guillem git at videolan.org
Tue May 14 16:47:27 CEST 2019


vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon May 13 14:34:32 2019 +0200| [22a7b53e7992e4325b2ee1f43860d6d805779fc2] | committer: Thomas Guillem

build: make compile-liblvc.sh stand alone

This script alone can now be used to build a libvlc .so library (without the
JNI part). This will be used for CI.

> https://code.videolan.org/videolan/vlc-android/commit/22a7b53e7992e4325b2ee1f43860d6d805779fc2
---

 compile-libvlc.sh       | 48 +++++++++++++++++++++++++++++++-------
 compile-medialibrary.sh |  2 +-
 compile.sh              | 61 +++++++++++++++++++++++++++++++++----------------
 libvlc/build.gradle     |  2 +-
 libvlc/jni/Android.mk   | 27 ++--------------------
 5 files changed, 85 insertions(+), 55 deletions(-)

diff --git a/compile-libvlc.sh b/compile-libvlc.sh
index dcdbc881c..7b9e5a890 100755
--- a/compile-libvlc.sh
+++ b/compile-libvlc.sh
@@ -162,6 +162,8 @@ fi
 SRC_DIR=$PWD
 VLC_SRC_DIR="$SRC_DIR/vlc"
 VLC_BUILD_DIR=`realpath $VLC_SRC_DIR/build-android-${TARGET_TUPLE}`
+VLC_OUT_PATH="$SRC_DIR/build/ndk"
+VLC_OUT_LDLIBS="-L$VLC_OUT_PATH/libs/${ANDROID_ABI} -lvlc"
 
 avlc_checkfail()
 {
@@ -578,6 +580,8 @@ echo ok
 # libVLC modules #
 ##################
 
+mkdir -p $VLC_OUT_PATH
+
 REDEFINED_VLC_MODULES_DIR=${VLC_BUILD_DIR}/install/lib/vlc/plugins
 rm -rf ${REDEFINED_VLC_MODULES_DIR}
 mkdir -p ${REDEFINED_VLC_MODULES_DIR}
@@ -630,7 +634,7 @@ EOF
     BUILTINS="$BUILTINS vlc_entry__$name,\n";
 done;
 BUILTINS="$BUILTINS NULL\n};\n"; \
-printf "/* Autogenerated from the list of modules */\n#include <unistd.h>\n$DEFINITION\n$BUILTINS\n" > libvlc/jni/libvlcjni-modules.c
+printf "/* Autogenerated from the list of modules */\n#include <unistd.h>\n$DEFINITION\n$BUILTINS\n" > $VLC_OUT_PATH/libvlcjni-modules.c
 
 DEFINITION=""
 BUILTINS="const void *libvlc_functions[] = {\n";
@@ -640,19 +644,44 @@ do
     BUILTINS="$BUILTINS $func,\n";
 done
 BUILTINS="$BUILTINS NULL\n};\n"; \
-printf "/* Autogenerated from the list of modules */\n#include <unistd.h>\n$DEFINITION\n$BUILTINS\n" > libvlc/jni/libvlcjni-symbols.c
+printf "/* Autogenerated from the list of modules */\n#include <unistd.h>\n$DEFINITION\n$BUILTINS\n" > $VLC_OUT_PATH/libvlcjni-symbols.c
 
 rm ${REDEFINED_VLC_MODULES_DIR}/syms
 
-############################################
-# NDK-Build for libvlc.so and libvlcjni.so #
-############################################
+###########################
+# NDK-Build for libvlc.so #
+###########################
 
 VLC_MODULES=$(avlc_find_modules ${REDEFINED_VLC_MODULES_DIR})
 VLC_CONTRIB_LDFLAGS=`for i in $(/bin/ls $VLC_CONTRIB/lib/pkgconfig/*.pc); do PKG_CONFIG_PATH="$VLC_CONTRIB/lib/pkgconfig/" pkg-config --libs $i; done |xargs`
 echo -e "ndk-build vlc"
 
-$ANDROID_NDK/ndk-build$OSCMD -C libvlc \
+touch $VLC_OUT_PATH/dummy.cpp
+
+# This is ugly but it's better to use the linker from ndk-build that will use
+# the proper linkflags depending on ABI/API
+rm -rf $VLC_OUT_PATH/Android.mk
+cat << 'EOF' > $VLC_OUT_PATH/Android.mk
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_MODULE    := libvlc
+LOCAL_SRC_FILES := libvlcjni-modules.c libvlcjni-symbols.c dummy.cpp
+LOCAL_LDFLAGS := -L$(VLC_CONTRIB)/lib
+LOCAL_LDLIBS := \
+	$(VLC_MODULES) \
+	$(VLC_BUILD_DIR)/lib/.libs/libvlc.a \
+	$(VLC_BUILD_DIR)/src/.libs/libvlccore.a \
+	$(VLC_BUILD_DIR)/compat/.libs/libcompat.a \
+	$(VLC_CONTRIB_LDFLAGS) \
+	-ldl -lz -lm -llog \
+	-la52 -ljpeg \
+	-llua \
+	$(VLC_LDFLAGS)
+LOCAL_CXXFLAGS := -std=c++11
+include $(BUILD_SHARED_LIBRARY)
+EOF
+
+$ANDROID_NDK/ndk-build$OSCMD -C build \
     APP_STL="c++_shared" \
     APP_CPPFLAGS="-frtti -fexceptions" \
     VLC_SRC_DIR="$VLC_SRC_DIR" \
@@ -661,13 +690,16 @@ $ANDROID_NDK/ndk-build$OSCMD -C libvlc \
     VLC_CONTRIB_LDFLAGS="$VLC_CONTRIB_LDFLAGS" \
     VLC_MODULES="$VLC_MODULES" \
     VLC_LDFLAGS="$VLC_LDFLAGS" \
-    APP_BUILD_SCRIPT=jni/Android.mk \
+    APP_BUILD_SCRIPT=ndk/Android.mk \
     APP_PLATFORM=android-${ANDROID_API} \
     APP_ABI=${ANDROID_ABI} \
-    NDK_PROJECT_PATH=jni \
+    NDK_PROJECT_PATH=ndk \
     NDK_TOOLCHAIN_VERSION=clang \
     NDK_DEBUG=${NDK_DEBUG}
 
+# Remove gdbserver to avoid conflict with libvlcjni.so debug options
+rm -f $VLC_OUT_PATH/libs/${ANDROID_ABI}/gdb*
+
 avlc_checkfail "ndk-build libvlc failed"
 } # avlc_build()
 
diff --git a/compile-medialibrary.sh b/compile-medialibrary.sh
index 97b760dfd..b6cf8630f 100755
--- a/compile-medialibrary.sh
+++ b/compile-medialibrary.sh
@@ -157,7 +157,7 @@ avlc_checkfail "medialibrary: make failed"
 
 cd ${SRC_DIR}
 
-MEDIALIBRARY_LDLIBS="-L$SRC_DIR/libvlc/jni/libs/$ANDROID_ABI -lvlc \
+MEDIALIBRARY_LDLIBS="$VLC_OUT_LDLIBS \
 -L${MEDIALIBRARY_BUILD_DIR}/build-android-$ANDROID_ABI/.libs -lmedialibrary \
 -L$SRC_DIR/vlc/contrib/contrib-android-$TARGET_TUPLE/jpeg/.libs -ljpeg \
 -L$MEDIALIBRARY_MODULE_DIR/$SQLITE_RELEASE/build-$ANDROID_ABI/.libs -lsqlite3 \
diff --git a/compile.sh b/compile.sh
index 1a0c0ca82..9b529aac7 100755
--- a/compile.sh
+++ b/compile.sh
@@ -97,8 +97,10 @@ if [ -z "$ANDROID_ABI" ]; then
 fi
 
 if [ "$ANDROID_ABI" = "armeabi-v7a" -o "$ANDROID_ABI" = "arm" ]; then
+    ANDROID_ABI="armeabi-v7a"
     GRADLE_ABI="ARMv7"
 elif [ "$ANDROID_ABI" = "arm64-v8a" -o "$ANDROID_ABI" = "arm64" ]; then
+    ANDROID_ABI="arm64-v8a"
     GRADLE_ABI="ARMv8"
 elif [ "$ANDROID_ABI" = "x86" ]; then
     GRADLE_ABI="x86"
@@ -262,52 +264,70 @@ cd ..
 ############
 # Make VLC #
 ############
-
 diagnostic "Configuring"
 compile() {
-    OPTS="-a $1"
-    if [ "$RELEASE" = 1 ]; then
-        OPTS="$OPTS release"
-    fi
+    # Build LibVLC if asked for it, or needed by medialibrary
+    copy_tmp="$1"
 
     OUT_DBG_DIR=.dbg/${ANDROID_ABI}
     mkdir -p $OUT_DBG_DIR
 
-    # Build LibVLC if asked for it, or needed by medialibrary
     if [ "$BUILD_MEDIALIB" != 1 -o ! -d "libvlc/jni/libs/$1" ]; then
         AVLC_SOURCED=1 . ./compile-libvlc.sh
         avlc_build
 
+        $ANDROID_NDK/ndk-build$OSCMD -C libvlc \
+            VLC_SRC_DIR="$VLC_SRC_DIR" \
+            VLC_BUILD_DIR="$VLC_BUILD_DIR" \
+            VLC_OUT_LDLIBS="$VLC_OUT_LDLIBS" \
+            APP_BUILD_SCRIPT=jni/Android.mk \
+            APP_PLATFORM=android-${ANDROID_API} \
+            APP_ABI=${ANDROID_ABI} \
+            NDK_PROJECT_PATH=jni \
+            NDK_TOOLCHAIN_VERSION=clang \
+            NDK_DEBUG=${NDK_DEBUG}
+
+        if [ "$copy_tmp" = "--copy-tmp=libvlc" ];then
+            cp -r $VLC_OUT_PATH/libs/${ANDROID_ABI} libvlc/jni/libs/${ANDROID_ABI} build/tmp
+        fi
+
         cp -a $VLC_OUT_PATH/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}
         cp -a ./libvlc/jni/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}
     fi
 
     if [ "$NO_ML" != 1 ]; then
-        ./compile-medialibrary.sh $OPTS
+        ANDROID_ABI=$ANDROID_ABI RELEASE=$RELEASE ./compile-medialibrary.sh
+        if [ "$copy_tmp" = "--copy-tmp=medialibrary" ];then
+            cp -r medialibrary/jni/libs/${ANDROID_ABI} build/tmp
+        fi
 
         cp -a medialibrary/jni/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}
     fi
 }
+
 if [ "$ANDROID_ABI" = "all" ]; then
-    if [ -d tmp ]; then
-        rm -rf tmp
+    if [ -d build/tmp ]; then
+        rm -rf build/tmp
     fi
-    mkdir tmp
+    mkdir -p build/tmp
     LIB_DIR="libvlc"
     if [ "$NO_ML" != 1 ]; then
         LIB_DIR="medialibrary"
     fi
-    compile armeabi-v7a
-    cp -r $LIB_DIR/jni/libs/armeabi-v7a tmp
-    compile arm64-v8a
-    cp -r $LIB_DIR/jni/libs/arm64-v8a tmp
-    compile x86
-    cp -r $LIB_DIR/jni/libs/x86 tmp
-    compile x86_64
-    mv tmp/* $LIB_DIR/jni/libs
-    rm -rf tmp
+    copy_tmp="--copy-tmp=$LIB_DIR"
+
+    # The compile function is sourcing ./compile-libvlc.sh and is configured
+    # with env variables (ANDROID_ABI), therefore it need to be run from a new
+    # context for each ABI
+
+    (ANDROID_ABI=armeabi-v7a RELEASE=$RELEASE compile $copy_tmp)
+    (ANDROID_ABI=arm64-v8a RELEASE=$RELEASE compile $copy_tmp)
+    (ANDROID_ABI=x86 RELEASE=$RELEASE compile $copy_tmp)
+    (ANDROID_ABI=x86_64 RELEASE=$RELEASE compile $copy_tmp)
+    rm -rf $LIB_DIR/jni/libs/
+    mv build/tmp $LIB_DIR/jni/libs/
 else
-    compile $ANDROID_ABI
+    compile
 fi
 
 ##################
@@ -319,6 +339,7 @@ if [ "$SIGNED_RELEASE" = 1 ]; then
 elif [ "$RELEASE" = 1 ]; then
     BUILDTYPE="Release"
 fi
+
 if [ "$BUILD_LIBVLC" = 1 ];then
     GRADLE_ABI=$GRADLE_ABI ./gradlew -p libvlc assemble${BUILDTYPE}
     RUN=0
diff --git a/libvlc/build.gradle b/libvlc/build.gradle
index fa241a98b..558b30bbf 100644
--- a/libvlc/build.gradle
+++ b/libvlc/build.gradle
@@ -22,7 +22,7 @@ android {
     sourceSets {
         main {
             jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
-            jniLibs.srcDirs = [ 'jni/libs' ] // Where generated .so files are placed.
+            jniLibs.srcDirs = [ 'jni/libs', '../build/ndk/libs' ] // Where generated .so files are placed.
             manifest.srcFile 'AndroidManifest.xml'
             java.srcDirs = ['src']
             resources.srcDirs = ['src']
diff --git a/libvlc/jni/Android.mk b/libvlc/jni/Android.mk
index 5a3e4683f..a56e5a859 100644
--- a/libvlc/jni/Android.mk
+++ b/libvlc/jni/Android.mk
@@ -10,30 +10,7 @@ LOCAL_SRC_FILES += libvlcjni-media.c libvlcjni-medialist.c libvlcjni-mediadiscov
 LOCAL_SRC_FILES += libvlcjni-dialog.c
 LOCAL_SRC_FILES += thumbnailer.c
 LOCAL_SRC_FILES += std_logger.c
-LOCAL_C_INCLUDES := $(VLC_SRC_DIR)/include $(VLC_BUILD_DIR)/include $(MEDIALIBRARY_JNI_DIR)
+LOCAL_C_INCLUDES := $(VLC_SRC_DIR)/include $(VLC_BUILD_DIR)/include
 LOCAL_CFLAGS := -std=c11
-LOCAL_LDLIBS := -llog
-LOCAL_SHARED_LIBRARIES := libvlc
-include $(BUILD_SHARED_LIBRARY)
-
-# libvlc
-include $(CLEAR_VARS)
-LOCAL_MODULE    := libvlc
-LOCAL_SRC_FILES := libvlcjni-modules.c libvlcjni-symbols.c dummy.cpp
-LOCAL_LDFLAGS := -L$(VLC_CONTRIB)/lib
-LOCAL_LDLIBS := \
-	$(VLC_MODULES) \
-	$(VLC_BUILD_DIR)/lib/.libs/libvlc.a \
-	$(VLC_BUILD_DIR)/src/.libs/libvlccore.a \
-	$(VLC_BUILD_DIR)/compat/.libs/libcompat.a \
-	$(VLC_CONTRIB_LDFLAGS) \
-	-ldl -lz -lm -llog \
-	-lliveMedia -lUsageEnvironment -lBasicUsageEnvironment -lgroupsock \
-	-la52 -ljpeg \
-	-lavcodec -lebml \
-	-llua \
-	-lgcrypt -lgpg-error \
-	$(VLC_LDFLAGS) \
-	-llog
-LOCAL_CXXFLAGS := -std=c++11
+LOCAL_LDLIBS := -llog $(VLC_OUT_LDLIBS)
 include $(BUILD_SHARED_LIBRARY)



More information about the Android mailing list