Difference between revisions of "AndroidCompile"

From VideoLAN Wiki
Jump to navigation Jump to search
(Undo revision 62019 by Dekans (talk))
 
(134 intermediate revisions by 14 users not shown)
Line 1: Line 1:
This page is an introduction to compilation of '''VLC for Android''' on Linux.  
+
This page is an introduction to the compilation of '''VLC for Android''' on Linux.  
  
==Eclipse, SDK and NDK installation==
+
==Android Studio, SDK and NDK installation==
  
===Android SDK===
+
=== Requirements  ===
#Create a working directory ''android''.  
+
* You '''MUST''' build on Linux (or OSX if you know what you are doing).
#Go to [http://developer.android.com/sdk/index.html Android SDK page] and download android-sdk_r10-linux_x86.tgz.  
+
* The following packages '''MUST''' must be installed:
#Decompress into ''android'' folder.
+
** the GNU autotools: ''autoconf'', ''libtool'', ''automake'' and ''make'' (a.k.a. ''gmake'')
#Run ''tools/android''. (without X environement you can run : "tools/android update sdk -u -t platform,platform-tool,extra")
+
** ...and their dependencies: ''m4'' and ''gawk'', ''mawk'' or ''nawk'',
#In the tool, install '''"SDK Platform Android 2.3, API 10"''', and follow the instructions.
+
** the GNU C and C++ compilers a.k.a. ''gcc'' and ''g++'',
 +
** some GNU build utilities: ''pkg-config'' and ''patch'',
 +
** the following other build utilities: ''Apache Ant'' (or ''Ant''), ''cmake'', ''protobuf'', ''ragel'',
 +
** the Subversion and Git version control systems
 +
** ''unzip'' and either ''curl'' or ''wget'' for retreiving sources.
 +
* Very recent versions of some of those tools may be required. At the time of writing, notably gettext 0.19.3 or later is required.
 +
* If any of the above is missing, expect the build to fail at some point.
 +
* If targeting an Android-x86 device, ''yasm'' must be installed too.
  
You can have [http://developer.android.com/sdk/installing.html more details], if needed.  
+
Precise lists of tools dependencies is listed [https://git.videolan.org/?p=vlc.git;a=blob;f=extras/tools/bootstrap;h=e60e5ebf93e69e7bb731e80d0fbc6ebd1226dfdb;hb=HEAD#l73 here].
  
===Android NDK===
+
<span style="color: #ff0000">'''64-bit users'''</span>: You must install these 32-bit libs as specified here: [[#Can.27t_run_aapt_or_adb_on_Linux_64-bit]]
# Check that the SDK installation is correct.
 
# Go to [http://developer.android.com/sdk/ndk/index.html Android NDK page].
 
# Download http://dl.google.com/android/ndk/android-ndk-r5b-linux-x86.tar.bz2.
 
# Decompress into ''android'' folder, next to your android-sdk-linux_x86 folder.
 
  
'''Note''': If you use the Android v7 NDK, replace your /vlc-android/build.xml file as follows:
+
==== Example on Ubuntu ====
 +
Install the packages as follow:
 +
sudo apt-get install automake ant autopoint cmake build-essential libtool-bin \
 +
      patch pkg-config protobuf-compiler ragel subversion unzip git \
 +
    openjdk-8-jre openjdk-8-jdk flex python wget
  
<pre>
+
=== SDK & Android Studio ===
<?xml version="1.0" encoding="UTF-8"?>
+
# Go to [http://developer.android.com/sdk/index.html Android SDK/IDE page].
<project name="VLC" default="help">
+
# Android Studio is recommended, but not mandatory!
  
    <!-- The local.properties file is created and updated by the 'android' tool.
+
===Android NDK===
        It contains the path to the SDK. It should *NOT* be checked into
+
# Check that the SDK installation is correct.
        Version Control Systems. -->
+
# Go to the [https://developer.android.com/ndk/downloads/index.html Android NDK page] and download the '''NDK r21''' for Linux.  
    <loadproperties srcFile="local.properties" />
+
# Decompress it to install
  
    <!-- The ant.properties file can be created by you. It is only edited by the
+
== Environment setup  ==
        'android' tool to add properties to it.
+
Set '''$ANDROID_SDK''' to point to your Android SDK directory
        This is the place to change some Ant specific build properties.
 
        Here are some properties you may want to change/update:
 
  
        source.dir
+
export ANDROID_SDK=/path/to/android-sdk
            The name of the source directory. Default is 'src'.
 
        out.dir
 
            The name of the output directory. Default is 'bin'.
 
  
        For other overridable properties, look at the beginning of the rules
+
Set '''$ANDROID_NDK''' to point to your Android NDK directory
        files in the SDK, at tools/ant/build.xml
 
  
        Properties related to the SDK location or the project target should
+
export ANDROID_NDK=/path/to/android-ndk
        be updated using the 'android' tool with the 'update' action.
 
  
        This file is an integral part of the build system for your
+
Add some useful binaries to your '''$PATH'''
        application and should be checked into Version Control Systems.
 
  
        -->
+
export PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools
    <property file="ant.properties" />
 
  
    <!-- The project.properties file is created and updated by the 'android'
+
== Building ==
        tool, as well as ADT.
+
=== Get VLC Source ===
 +
Clone the source from the VLC git!
  
        This contains project specific properties such as project target, and library
+
In your ''android'' source folder, run:
        dependencies. Lower level build properties are stored in ant.properties
 
        (or in .classpath for Eclipse projects).
 
  
        This file is an integral part of the build system for your
+
git clone https://code.videolan.org/videolan/vlc-android.git
        application and should be checked into Version Control Systems. -->
 
    <loadproperties srcFile="project.properties" />
 
  
    <!-- quick check on sdk.dir -->
+
==== Setup Gradle build system ====
    <fail
 
            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
 
            unless="sdk.dir"
 
    />
 
  
 +
Before using Android studio to compile the app, you must run '''compile.sh''' once to set up gradle build system.
  
<!-- extension targets. Uncomment the ones where you want to do custom work
+
It should automatically populate mandatory local.properties and gradle.properties files with:
    in between standard targets -->
 
<!--
 
    <target name="-pre-build">
 
    </target>
 
    <target name="-pre-compile">
 
    </target>
 
  
    /* This is typically used for code obfuscation.
+
''local.properties''
      Compiled code location: ${out.classes.absolute.dir}
 
      If this is not done in place, override ${out.dex.input.absolute.dir} */
 
    <target name="-post-compile">
 
    </target>
 
-->
 
  
    <!-- Import the actual build file.
+
sdk.dir=<SDK path from $ANDROID_SDK>
 +
ndk.dir=<NDK path from $ANDROID_NDK>
  
        To customize existing targets, there are two options:
+
This sets up gradle to build with correct SDK/NDK.
        - Customize only one target:
 
            - copy/paste the target into this file, *before* the
 
              <import> task.
 
            - customize it to your needs.
 
        - Customize the whole content of build.xml
 
            - copy/paste the content of the rules files (minus the top node)
 
              into this file, replacing the <import> task.
 
            - customize to your needs.
 
  
        ***********************
+
Once this first compilation has succeeded, you can build from Android Studio with the '''Run''' command.
        ****** IMPORTANT ******
 
        ***********************
 
        In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
 
        in order to avoid having your file be overridden by tools such as "android update project"
 
    -->
 
    <!-- version-tag: 1 -->
 
    <import file="${sdk.dir}/tools/ant/build.xml" />
 
  
</project>
+
=== Devices ===
</pre>
 
  
===Eclipse===
+
Find the ABI for the target device.
As used by your distribution, install Eclipse with your package manager:
 
  
apt-get install eclipse (debian)
+
* For a normal (2012-2015 consumer phone or tablet) device (e.g. Cortex-A8 or Cortex-A9)
  yum install eclipse (Fedora)
+
  <code>armeabi-v7a</code>
  pacman -S eclipse (Arch)
+
* For a Tegra2 device (no [[wikipedia:ARM_architecture#Advanced_SIMD_.28NEON.29|NEON]])
  emerge -av eclipse-sdk (Gentoo)
+
  <code>armeabi-v7a</code>
  ...
+
* For an ARMv6 device
 +
<code>armeabi</code>
 +
* For an ARMv6 device that does not support FPU
 +
  <code>armeabi-nofpu</code>
 +
* For an ARMv5 device or the Android Emulator
 +
<code>armeabi-v5</code>
 +
* For a x86 device (e.g. Android-x86, Google TV, Logitech TV, Android x86 smartphones, etc)
 +
  <code>x86</code>
 +
* For a MIPS device (i.e. Ainol Novo tablets):
 +
<code>mips</code>
  
And run it, at least once, and then quit eclipse.  
+
This value must be passed to the compile.sh script
  
====ADT====
+
==== Compile ====
The '''ADT''' plugin is required to compile on Android.
 
  
#Go to [http://developer.android.com/sdk/eclipse-adt.html#installing ADT page].
+
'''Read''' compile.sh first, as it contains some very useful and important information. Then run it:
#Start Eclipse, then select Help &gt; Install New Software....
+
buildsystem/compile.sh -a <ABI>
#Add the "ADT Plugin" repository with https://dl-ssl.google.com/android/eclipse/ as '''URL'''  
 
#Validate and select the checkbox next to Developer Tools and click Next, Next, Finish.
 
#Restart Eclipse.
 
#Go to ''Menu'' &gt; ''Window'' &gt; ''Preferences...'' and then ''Android'' from the left pane.  
 
#Point the SDK Location in to your downloaded SDK directory.
 
#Ok, and quit Eclipse.
 
  
See [http://developer.android.com/sdk/eclipse-adt.html#troubleshooting extra information here].  
+
'''Note:''' At this point, you will get an auto-generated debug APK in the vlc-android/build/outputs/apk folder, signed with a debug key.
  
=== Environment setup  ===
+
In order to build a non-debug (release, and '''unsigned''') package:
==== Linux and autotools ====
+
buildsystem/compile.sh release
* You '''MUST''' be on Linux, and a recent one.
 
* You '''MUST''' have installed: ''apache-ant'', ''autoconf'', ''automake'', ''libtool'', ''gawk'' (or ''nawk''), ''gcc'', ''g++'', ''pkg-config'', ''cmake'', ''patch'', ''subversion''. And very up-to-date versions of those tools.
 
* You '''MUST''' install: ''git''.
 
  
==== Environment ====
+
'''Note:''' At this point, you will get an release APK in the same folder.
  
Set $ANDROID_SDK to point to your Android SDK directory
+
==== Build LibVLC ====
  
  export ANDROID_SDK=/path/to/android-sdk
+
To build LibVLC, simply pass the -l option:
 +
  buildsystem/compile.sh -l -a <ABI> -r
  
Set $ANDROID_NDK to point to your Android NDK directory
+
.aar archive will be located in libvlc/build/outputs/aar/
  
export ANDROID_NDK=/path/to/android-ndk
+
==== Gradle tweaks ====
  
Add some useful binaries to your $PATH
+
To improve gradle execution time, try these options by writing this in gradle.properties in vlc android project.
 +
Or directly in your ~/.gradle/gradle.properties
 +
org.gradle.parallel=true
 +
org.gradle.configureondemand=true
 +
# If you have a BUNCH of RAM available
 +
org.gradle.daemon=true
 +
org.gradle.jvmargs=-Xmx2048M
  
export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
+
=== Run ===
 
+
Run it and enjoy!
If you plan to use the emulator or if you have a phone that does not support NEON, you need a build without [[wikipedia:ARM_architecture#Advanced_SIMD_.28NEON.29|NEON]]
 
 
 
export NO_NEON=1
 
 
 
Those exports must be set at all times, notably for the contribs and the configure.
 
 
 
== Building ==
 
=== Get VLC Source ===
 
Use the VLC git repository to get the source!  
 
 
 
In your ''android'' folder, run:
 
 
 
git clone git://git.videolan.org/vlc-ports/android.git
 
 
 
 
 
==== Compile ====
 
'''Read''' compile.sh first, as it contains some very useful important information. Then run it:
 
sh compile.sh
 
 
 
==== Package in Eclipse ====
 
# In Eclipse, create a new Android project from existing source by giving the vlc-android path.
 
# Compile your project using Eclipse.
 
  
=== Run ===
+
=== Troubleshooting ===
Run it and enjoy!
+
==== Compilation error on Dependencies ====
 +
Sometimes, especially when gradle dependencies have been upgraded, the ''compile.sh'' will fail to refetch dependencies. Just close Android Studio and re-run the script to fix this issue.
  
 
== Debugging ==
 
== Debugging ==
Line 183: Line 133:
 
* [http://developer.android.com/guide/developing/debugging/ddms.html DDMS]  
 
* [http://developer.android.com/guide/developing/debugging/ddms.html DDMS]  
 
* [http://developer.android.com/guide/developing/tools/logcat.html Logcat]
 
* [http://developer.android.com/guide/developing/tools/logcat.html Logcat]
 +
 +
===Native debugging===
 +
If you run VLC Android and you get a crash that looks something like this:
 +
<pre>
 +
I/DEBUG  (  958): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
 +
I/DEBUG  (  958): Build fingerprint: 'MOTO/MBTCA/sesame/XT300:2.1-update1/SESLA_U3_01.71.0/110110:user/release-keys'
 +
I/DEBUG  (  958): pid: 1733, tid: 1733 >>> org.videolan.vlc <<<
 +
I/DEBUG  (  958): signal 11 (SIGSEGV), fault addr 4237be3c
 +
I/DEBUG  (  958):  r0 423640a0  r1 7ece77ac  r2 42bccdac  r3 4237be38
 +
I/DEBUG  (  958):  r4 00000000  r5 42bccdac  r6 002ed088  r7 002ed018
 +
I/DEBUG  (  958):  r8 7ece78e8  r9 2bafa844  10 0000000e  fp 7ece794c
 +
I/DEBUG  (  958):  ip 00002ba0  sp 7ece7784  lr 423652e4  pc 4237be3c  cpsr 60000010
 +
I/DEBUG  (  958):          #00  pc 0037be3c  /data/data/org.videolan.vlc/lib/libvlcjni.so
 +
I/DEBUG  (  958):          #01  lr 423652e4  /data/data/org.videolan.vlc/lib/libvlcjni.so
 +
</pre>
 +
 +
You have a '''native crash'''. To debug it, you need to have compiled VLC as above and installed it on your device. Once your compiled VLC build is on your device, you can find the '''backtrace''' as follows:
 +
 +
# Make sure you are in the directory that you checked out VLC-Android in.
 +
# Migrate the libvlc folders. (Do this every time the code is recompiled)
 +
## cp -r libvlc/jni vlc-android
 +
## cp -r libvlc/libs vlc-android
 +
## cp -r libvlc/obj vlc-android
 +
## (This is because the libvlc and VLC for Android folders were split yet the debugger needs the object files from both.)
 +
# cd vlc-android
 +
# $ANDROID_NDK/ndk-gdb --verbose --force --start
 +
At this point, lots of stuff will appear:
 +
<pre>
 +
Android NDK installation path: /opt/android-ndk-r8c
 +
Using default adb command: /opt/android-sdk-linux_x86/platform-tools/adb
 +
ADB version found: Android Debug Bridge version 1.0.29
 +
Using ADB flags:
 +
Using auto-detected project path: .
 +
Found package name: org.videolan.vlc
 +
...bunch of stuff skipped...
 +
GNU gdb (GDB) 7.3.1-gg2
 +
Copyright (C) 2011 Free Software Foundation, Inc.
 +
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 +
This is free software: you are free to change and redistribute it.
 +
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
 +
and "show warranty" for details.
 +
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
 +
For bug reporting instructions, please see:
 +
<http://www.gnu.org/software/gdb/bugs/>.
 +
Remote debugging from host 0.0.0.0
 +
...bunch of stuff skipped...
 +
libthread_db:td_ta_new: Victory: We can debug theads!
 +
warning: Breakpoint address adjusted from 0x400deaa5 to 0x400deaa4.
 +
0x40107a40 in epoll_wait () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
 +
(gdb)
 +
</pre>
 +
<ol start="4">
 +
<li>At this point, type in "continue" and press Enter.</li>
 +
<li>Perform the actions you did to make it crash. It will spit out something like this:</li>
 +
</ol>
 +
<pre>
 +
Program received signal SIGSEGV, Segmentation fault.
 +
0x401120ae in ?? () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
 +
</pre>
 +
<ol start="6">
 +
<li>Now, just type in "'''bt full'''" (excluding the quotation marks) and press Enter. That is your backtrace that you should give to the developers when they ask for it (possibly on a [http://paste.kde.org/ pastebin], too).</li>
 +
</ol>
 +
<pre>
 +
(gdb) bt full
 +
#0  0x401120ae in ?? () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
 +
No symbol table info available.
 +
#1  0x40107bd8 in abort () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
 +
No symbol table info available.
 +
#2  0x40118e6a in __assert2 () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
 +
No symbol table info available.
 +
#3  0x5e0cdfdc in var_SetChecked (p_this=0x40134b94, psz_name=0x5ea2fcb8 "rate", expected_type=80, val=...) at ../../src/misc/variables.c:711
 +
        i_ret = 0
 +
        p_var = <optimized out>
 +
        oldval = {i_int = 4742037487051810480, b_bool = 176, f_float = 2.27765068e+14, psz_string = 0x574f26b0 "X\270|B\001\001", p_address = 0x574f26b0,
 +
          p_object = 0x574f26b0, p_list = 0x574f26b0, i_time = 4742037487051810480, coords = {x = 1464805040, y = 1104091640}}
 +
        __func__ = "var_SetChecked"
 +
        p_priv = <optimized out>
 +
#4  0x5e06dd9c in var_SetFloat (f=1.41421354, psz_name=0x5ea2fcb8 "rate____sample_backtrace", p_obj=0x0) at ../../include/vlc_variables.h:262
 +
        val = <optimized out>
 +
#5  libvlc_media_player_set_rate (p_mi=0x0, rate=1.41421354) at ../../lib/media_player.c:1252
 +
        p_input_thread = <optimized out>
 +
#6  0x5de7bd18 in Java_org_videolan_vlc_LibVLC_setRate (env=0x41cf0470, thiz=0x8ab00021, rate=1.41421354) at jni/libvlcjni.c:678
 +
        mp = 0x0
 +
#7  0x4076de34 in ?? ()
 +
No symbol table info available.
 +
#8  0x4076de34 in ?? ()
 +
No symbol table info available.
 +
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
 +
</pre>
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 197: Line 236:
 
If you're new to Ant, please be aware that some Linux distributions don't install it in the usual spot as with other programs. Try checking to see if the directory /usr/share/java/apache-ant/bin exists and add it to your path.
 
If you're new to Ant, please be aware that some Linux distributions don't install it in the usual spot as with other programs. Try checking to see if the directory /usr/share/java/apache-ant/bin exists and add it to your path.
  
[[Category:Building]]
+
===Outdated autotools-dev===
 +
If you get the following error message you may have have an outdated version of autotools-dev:
 +
  Invalid configuration `arm-linux-androideabi': system `androideabi' not recognized
 +
You may first want to check if your distribution has any available updates for this package.  Alternatively, you can manually update your config.guess and config.sub files from here: [http://git.savannah.gnu.org/gitweb/?p=config.git;a=tree].  These files are typically located in /usr/share/misc on Debian based distributions.
 +
 
 +
===autoreconf: automake failed with exit status: 1===
 +
automake: warnings are treated as errors
 +
configure.ac:41: warning: The 'AM_PROG_MKDIR_P' macro is deprecated, and will soon be removed.
 +
configure.ac:41: You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro instead,
 +
configure.ac:41: and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your Makefile.am files.
 +
 
 +
If you are using Automake 1.13 or higher, you must remove -Werror from vlc/contrib/android/gnutls/configure.ac to continue. (First reported in [http://forum.videolan.org/viewtopic.php?f=35&t=108927])
 +
 
 +
===autoreconf: automake failed with exit status: 1 ===
 +
make: *** [dvdnav] Error 1
 +
...
 +
... error: possibly undefined macro: AM_PROG_LIBTOOL
 +
 
 +
This error may occur when compiling with an older Linux distribution, such as Ubuntu 12.04, that doesn't meet bootstrap prerequisites. As of 2014-08-09, the master branch for vlc-ports/android.git [http://git.videolan.org/?p=vlc-ports/android.git;a=summary] lacks patch 5199 [https://patches.videolan.org/patch/5199/]. Without the patch, compile.sh builds out dated automake and autoconf that may not access libtool despite presence of a current libtool binary amongst supporting tools and a similar or more recent binary present as part of the OS.
 +
 
 +
To work around this error, patch the master branch or update the prerequisites. For Ubuntu 12.04, upgrade autoconf, automake, and cmake as dictated by vlc/extras/tools/bootstrap.
 +
 
 +
===Can't run aapt or adb on Linux 64-bit===
 +
You must install the 32-bit libraries of the following libraries, as the precompiled Google binaries depend on them: ''libc6'', ''libstdc++6'', and ''zlib''.
 +
 
 +
New versions of Debian and/or Ubuntu require you to install i386 versions of packages:
 +
sudo dpkg --add-architecture i386
 +
sudo apt-get update
 +
sudo apt-get install zlib1g:i386 libstdc++6:i386 libc6:i386
 +
 
 +
If you are under ''old versions'' of Ubuntu, install ia32-libs can help you solve this issue.
 +
sudo apt-get install ia32-libs
 +
 
 +
==See also==
 +
* [[Android Report bugs]] - Bug reporting guide for VLC-Android.
 +
 
 +
[[Category:Building]] [[Category:Android]]

Latest revision as of 15:01, 11 March 2020

This page is an introduction to the compilation of VLC for Android on Linux.

Android Studio, SDK and NDK installation

Requirements

  • You MUST build on Linux (or OSX if you know what you are doing).
  • The following packages MUST must be installed:
    • the GNU autotools: autoconf, libtool, automake and make (a.k.a. gmake)
    • ...and their dependencies: m4 and gawk, mawk or nawk,
    • the GNU C and C++ compilers a.k.a. gcc and g++,
    • some GNU build utilities: pkg-config and patch,
    • the following other build utilities: Apache Ant (or Ant), cmake, protobuf, ragel,
    • the Subversion and Git version control systems
    • unzip and either curl or wget for retreiving sources.
  • Very recent versions of some of those tools may be required. At the time of writing, notably gettext 0.19.3 or later is required.
  • If any of the above is missing, expect the build to fail at some point.
  • If targeting an Android-x86 device, yasm must be installed too.

Precise lists of tools dependencies is listed here.

64-bit users: You must install these 32-bit libs as specified here: #Can.27t_run_aapt_or_adb_on_Linux_64-bit

Example on Ubuntu

Install the packages as follow:

sudo apt-get install automake ant autopoint cmake build-essential libtool-bin \
     patch pkg-config protobuf-compiler ragel subversion unzip git \
    openjdk-8-jre openjdk-8-jdk flex python wget

SDK & Android Studio

  1. Go to Android SDK/IDE page.
  2. Android Studio is recommended, but not mandatory!

Android NDK

  1. Check that the SDK installation is correct.
  2. Go to the Android NDK page and download the NDK r21 for Linux.
  3. Decompress it to install

Environment setup

Set $ANDROID_SDK to point to your Android SDK directory

export ANDROID_SDK=/path/to/android-sdk

Set $ANDROID_NDK to point to your Android NDK directory

export ANDROID_NDK=/path/to/android-ndk

Add some useful binaries to your $PATH

export PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools

Building

Get VLC Source

Clone the source from the VLC git!

In your android source folder, run:

git clone https://code.videolan.org/videolan/vlc-android.git

Setup Gradle build system

Before using Android studio to compile the app, you must run compile.sh once to set up gradle build system.

It should automatically populate mandatory local.properties and gradle.properties files with:

local.properties

sdk.dir=<SDK path from $ANDROID_SDK>
ndk.dir=<NDK path from $ANDROID_NDK>

This sets up gradle to build with correct SDK/NDK.

Once this first compilation has succeeded, you can build from Android Studio with the Run command.

Devices

Find the ABI for the target device.

  • For a normal (2012-2015 consumer phone or tablet) device (e.g. Cortex-A8 or Cortex-A9)
armeabi-v7a
  • For a Tegra2 device (no NEON)
armeabi-v7a
  • For an ARMv6 device
armeabi
  • For an ARMv6 device that does not support FPU
armeabi-nofpu
  • For an ARMv5 device or the Android Emulator
armeabi-v5
  • For a x86 device (e.g. Android-x86, Google TV, Logitech TV, Android x86 smartphones, etc)
x86
  • For a MIPS device (i.e. Ainol Novo tablets):
mips

This value must be passed to the compile.sh script

Compile

Read compile.sh first, as it contains some very useful and important information. Then run it:

buildsystem/compile.sh -a <ABI>

Note: At this point, you will get an auto-generated debug APK in the vlc-android/build/outputs/apk folder, signed with a debug key.

In order to build a non-debug (release, and unsigned) package:

buildsystem/compile.sh release

Note: At this point, you will get an release APK in the same folder.

Build LibVLC

To build LibVLC, simply pass the -l option:

buildsystem/compile.sh -l -a <ABI> -r

.aar archive will be located in libvlc/build/outputs/aar/

Gradle tweaks

To improve gradle execution time, try these options by writing this in gradle.properties in vlc android project. Or directly in your ~/.gradle/gradle.properties

org.gradle.parallel=true
org.gradle.configureondemand=true
# If you have a BUNCH of RAM available
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048M

Run

Run it and enjoy!

Troubleshooting

Compilation error on Dependencies

Sometimes, especially when gradle dependencies have been upgraded, the compile.sh will fail to refetch dependencies. Just close Android Studio and re-run the script to fix this issue.

Debugging

Here are some helpful links if you wish to debug VLC on Android:

Native debugging

If you run VLC Android and you get a crash that looks something like this:

I/DEBUG   (  958): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  958): Build fingerprint: 'MOTO/MBTCA/sesame/XT300:2.1-update1/SESLA_U3_01.71.0/110110:user/release-keys'
I/DEBUG   (  958): pid: 1733, tid: 1733 >>> org.videolan.vlc <<<
I/DEBUG   (  958): signal 11 (SIGSEGV), fault addr 4237be3c
I/DEBUG   (  958):  r0 423640a0  r1 7ece77ac  r2 42bccdac  r3 4237be38
I/DEBUG   (  958):  r4 00000000  r5 42bccdac  r6 002ed088  r7 002ed018
I/DEBUG   (  958):  r8 7ece78e8  r9 2bafa844  10 0000000e  fp 7ece794c
I/DEBUG   (  958):  ip 00002ba0  sp 7ece7784  lr 423652e4  pc 4237be3c  cpsr 60000010
I/DEBUG   (  958):          #00  pc 0037be3c  /data/data/org.videolan.vlc/lib/libvlcjni.so
I/DEBUG   (  958):          #01  lr 423652e4  /data/data/org.videolan.vlc/lib/libvlcjni.so

You have a native crash. To debug it, you need to have compiled VLC as above and installed it on your device. Once your compiled VLC build is on your device, you can find the backtrace as follows:

  1. Make sure you are in the directory that you checked out VLC-Android in.
  2. Migrate the libvlc folders. (Do this every time the code is recompiled)
    1. cp -r libvlc/jni vlc-android
    2. cp -r libvlc/libs vlc-android
    3. cp -r libvlc/obj vlc-android
    4. (This is because the libvlc and VLC for Android folders were split yet the debugger needs the object files from both.)
  3. cd vlc-android
  4. $ANDROID_NDK/ndk-gdb --verbose --force --start

At this point, lots of stuff will appear:

Android NDK installation path: /opt/android-ndk-r8c
Using default adb command: /opt/android-sdk-linux_x86/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.29
Using ADB flags: 
Using auto-detected project path: .
Found package name: org.videolan.vlc
...bunch of stuff skipped...
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Remote debugging from host 0.0.0.0
...bunch of stuff skipped...
libthread_db:td_ta_new: Victory: We can debug theads!
warning: Breakpoint address adjusted from 0x400deaa5 to 0x400deaa4.
0x40107a40 in epoll_wait () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
(gdb)
  1. At this point, type in "continue" and press Enter.
  2. Perform the actions you did to make it crash. It will spit out something like this:
Program received signal SIGSEGV, Segmentation fault.
0x401120ae in ?? () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
  1. Now, just type in "bt full" (excluding the quotation marks) and press Enter. That is your backtrace that you should give to the developers when they ask for it (possibly on a pastebin, too).
(gdb) bt full
#0  0x401120ae in ?? () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
No symbol table info available.
#1  0x40107bd8 in abort () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
No symbol table info available.
#2  0x40118e6a in __assert2 () from /media/data/vlc_android/vlc-android/obj/local/armeabi/libc.so
No symbol table info available.
#3  0x5e0cdfdc in var_SetChecked (p_this=0x40134b94, psz_name=0x5ea2fcb8 "rate", expected_type=80, val=...) at ../../src/misc/variables.c:711
        i_ret = 0
        p_var = <optimized out>
        oldval = {i_int = 4742037487051810480, b_bool = 176, f_float = 2.27765068e+14, psz_string = 0x574f26b0 "X\270|B\001\001", p_address = 0x574f26b0, 
          p_object = 0x574f26b0, p_list = 0x574f26b0, i_time = 4742037487051810480, coords = {x = 1464805040, y = 1104091640}}
        __func__ = "var_SetChecked"
        p_priv = <optimized out>
#4  0x5e06dd9c in var_SetFloat (f=1.41421354, psz_name=0x5ea2fcb8 "rate____sample_backtrace", p_obj=0x0) at ../../include/vlc_variables.h:262
        val = <optimized out>
#5  libvlc_media_player_set_rate (p_mi=0x0, rate=1.41421354) at ../../lib/media_player.c:1252
        p_input_thread = <optimized out>
#6  0x5de7bd18 in Java_org_videolan_vlc_LibVLC_setRate (env=0x41cf0470, thiz=0x8ab00021, rate=1.41421354) at jni/libvlcjni.c:678
        mp = 0x0
#7  0x4076de34 in ?? ()
No symbol table info available.
#8  0x4076de34 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Troubleshooting

Outdated Awk

If you receive the error message while building:

Android NDK: Host 'awk' tool is outdated. Please define HOST_AWK to point to Gawk or Nawk !    

The prebuilt version of Awk that comes with the Android NDK is outdated. Defining HOST_AWK in your environment does nothing as the system still tries to just the one that comes with the Android NDK. To get around this issue, simply rename or delete the Awk binary that comes with the Android NDK. For example to move it:

mv $ANDROID_NDK/prebuilt/linux-x86/bin/awk $ANDROID_NDK/prebuilt/linux-x86/bin/awk.old

Can't find Ant

If you're new to Ant, please be aware that some Linux distributions don't install it in the usual spot as with other programs. Try checking to see if the directory /usr/share/java/apache-ant/bin exists and add it to your path.

Outdated autotools-dev

If you get the following error message you may have have an outdated version of autotools-dev:

 Invalid configuration `arm-linux-androideabi': system `androideabi' not recognized

You may first want to check if your distribution has any available updates for this package. Alternatively, you can manually update your config.guess and config.sub files from here: [1]. These files are typically located in /usr/share/misc on Debian based distributions.

autoreconf: automake failed with exit status: 1

automake: warnings are treated as errors
configure.ac:41: warning: The 'AM_PROG_MKDIR_P' macro is deprecated, and will soon be removed.
configure.ac:41: You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro instead,
configure.ac:41: and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your Makefile.am files.

If you are using Automake 1.13 or higher, you must remove -Werror from vlc/contrib/android/gnutls/configure.ac to continue. (First reported in [2])

autoreconf: automake failed with exit status: 1

make: *** [dvdnav] Error 1
...
... error: possibly undefined macro: AM_PROG_LIBTOOL

This error may occur when compiling with an older Linux distribution, such as Ubuntu 12.04, that doesn't meet bootstrap prerequisites. As of 2014-08-09, the master branch for vlc-ports/android.git [3] lacks patch 5199 [4]. Without the patch, compile.sh builds out dated automake and autoconf that may not access libtool despite presence of a current libtool binary amongst supporting tools and a similar or more recent binary present as part of the OS.

To work around this error, patch the master branch or update the prerequisites. For Ubuntu 12.04, upgrade autoconf, automake, and cmake as dictated by vlc/extras/tools/bootstrap.

Can't run aapt or adb on Linux 64-bit

You must install the 32-bit libraries of the following libraries, as the precompiled Google binaries depend on them: libc6, libstdc++6, and zlib.

New versions of Debian and/or Ubuntu require you to install i386 versions of packages:

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install zlib1g:i386 libstdc++6:i386 libc6:i386

If you are under old versions of Ubuntu, install ia32-libs can help you solve this issue.

sudo apt-get install ia32-libs

See also