title: Link static libraries Android.mk ffmpeg on Android
body: <p>I built FFMPEG with the guardian's script (<a href="https://github.com/guardianproject/android-ffmpeg/" rel="nofollow">here</a>). All went good and I have the following structure : </p>
  
  <pre><code>jni/
  |-- Android.mk
  |-- demo.c
  |-- include/
  |   |-- libavcodec/
  |   |   |-- headers files
  |   |-- libavdevice/
  |   |   `-- avdevice.h
  |   |-- libavfilter/
  |   |   |-- headers files
  |   |-- libavformat/
  |   |   |-- headers files
  |   |-- libavresample/
  |   |   |-- headers files
  |   |-- libavutil/
  |   |   |-- headers files
  |   |-- libpostproc/
  |   |   |-- headers files
  |   |-- libswresample/
  |   |   |-- headers files
  |   |-- libswscale/
  |   |   |-- headers files
  |   `-- sox.h
  `-- lib/
      |-- libavcodec.a
      |-- libavdevice.a
      |-- libavfilter.a
      |-- libavformat.a
      |-- libavresample.a
      |-- libavutil.a
      |-- libpostproc.a
      |-- libsox.a
      |-- libswresample.a
      |-- libswscale.a
      |-- libx264.a
  </code></pre>
  
  <p>Here is my Android.mk file :</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  
  FFMPEG_LIBS := $(addprefix lib/, \
   libavformat.a \
   libavcodec.a \
   libpostproc.a \
   libswscale.a \
   libavutil.a \
   x264.a )
  
  LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
  LOCAL_SRC_FILES := demo.c
  LOCAL_LDLIBS := -llog
  LOCAL_STATIC_LIBRARY := $(FFMPEG_LIBS)
  LOCAL_MODULE := demo
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p>And my demo.c file :</p>
  
  <pre><code>#include &lt;jni.h&gt;
  
  #include &lt;libavcodec/avcodec.h&gt;
  #include &lt;libavformat/avformat.h&gt;
  #include &lt;libavformat/avio.h&gt;
  #include &lt;libswscale/swscale.h&gt;
  #include &lt;libavutil/avstring.h&gt;
  
  JNIEXPORT jint JNICALL Java_com_example_ffmpeg_guardian_MainActivity_logFileInfo(JNIEnv *env, jclass this, jstring filename)
  {
      av_register_all();
  
      AVFormatContext *pFormatCtx;
      const jbyte *str;
      str = (*env)-&gt;GetStringUTFChars(env, filename, NULL);
  
      if(avformat_open_input(&amp;pFormatCtx, str, NULL, NULL)!=0)
          return 1;
      else
         return 2;
  
      return 0;
  }
  </code></pre>
  
  <p>The problem is when I try to compile with the NDK (r8) I got this message :</p>
  
  <pre><code>Compile thumb  : demo &lt;= demo.c
  SharedLibrary  : libdemo.so
  demo.o: In function `Java_com_example_ffmpeg_guardian_MainActivity_logFileInfo':
  demo.c:11: undefined reference to `av_register_all'
  demo.c:17: undefined reference to `avformat_open_input'
  collect2: ld returned 1 exit status
  make: *** [ffmpeg-guardian/obj/local/armeabi/libdemo.so] Error 1
  </code></pre>
  
  <p>After some research, this problem appears because libraries are not linked in the right order. I tried to change this order but nothing changed.</p>
  
  <p>Can Someone help me to fix this final step to get ffmpeg working on android ? Thanks !</p>