Reprinted please indicate the source! After all, it's my painstaking efforts!
Link: http://blog.csdn.net/zgyulongfei/article/details/7440254
The purpose of this blog is to help friends who have failed to successfully transplant x264 to Android. It is also a summary of my learning experience during this period.
Bytes --------------------------------------------------------------------------------------
First, paste my compiling environment:
Operating System: Ubuntu 11.10
JDK: jdk-6u31-linux-i586
Eclipse: eclipse-SDK-3.7.2-linux-gtk
Ndk: due to the continuous improvement of the ndk version, but the directory structure of different versions of ndk and the use of GCC are different, this paper will introduce the two versions of ndk (android-ndk-r4b-linux-x86 and android-ndk-r6-linux-x86 ), you can configure according to your ndk directory.
X264 source code: last_x264
Bytes --------------------------------------------------------------------------------------
I remember when I was in class, Mr. Wang said, "forgetting the sufferings of the past is a disaster of the future !".
In order to make my future no disaster, I will record the sufferings suffered during the compilation process ^_^
(1) At the beginning, I compiled it in the Windows 7 + cygwin environment, but it never succeeded. Maybe it was because I did not trust the simulated environment like cygwin. I finally decided to switch to Linux, so a cainiao was born in the Linux world, but that's exactly the case ......
(2) Since I first came into contact with Linux, I was like a monk who worked hard to touch my mind. To tell the truth, I felt really tired, I am so used to the silly windows operation methods !!! Then I am confused about the Linux environment.
(3) At the beginning of compilation of x264, I was very happy to find some compilation methods on Google Baidu. For example, in this compilation of x264, I did nothing but follow the above. Directly./configure and then make. It is better to see that the libx264 library is generated than the ghost. However, when the JNI of libx264 is called by ndk compilation, there are a lot of errors.
=. |, And then you can find solutions that are inexplicably incorrect. Of course, there is no good result orz.
(PS: I want to criticize GFW here. Your sister's page shown on the pop-up page after Google just clicked the result is: you cannot access this page, an error occurred while searching for DNS ......!!!)
(4) I had a long struggle in step 1 and later learned how to use it. /configure uses the default GCC compiler set, while the files compiled by GCC are locally executed because x86 binary files are generated. The x264 we transplanted is not used locally, so cross-transplantation and cross-transplantation are required? Shenma? Knowing that cross-Compiling in Linux requires the use of arm-Linux-GCC, we should find the article "cross-compiling x264 Files" compiled with arm-Linux-GCC. previously, you had to configure config before make. all GCC in Mak is changed to arm-Linux-GCC, and some others must also be changed to the arm-Linux-compiler set. After the change, I still couldn't compile it because I didn't have this compiler on my machine. So I downloaded the arm-Linux-GCC compiler and made it again after the environment is configured. Now I am so happy that the compilation is successful, and the victory is in sight !!!
Pai_^
(5) Put the libx264 compiled in step 5 to Android for calling. When the JNI of libx264 is called by ndk compilation, the. So file is successfully generated. Does this mean I have succeeded ??
(6) When I was very happy to install and run the APK generated by my HTC G3, I encountered the error java. Lang. unsatifiedlinkerror: libx264 not found. I was dizzy. I even unwrapped the generated APK and found that libx264 was lying quietly in it. I remembered the story "Emperor's New Clothes". The emperor was not dressed clearly, people just want to say that he is wearing beautiful clothes. Nima and I put libx264 there. You just want to say that it is not there !??. This is a matter of being swollen, and I have been searching for some information for a long time to find a solution. The heart is cool !!!
(7) cough, get bored and take a bath. Come back and decide to try again, So Baidu to this Article "compile libx264 with android-ndk-r4b", because very early tried the configuration of this article, found the error, so gave up. Now there is no way to go, so I will use my dead horse as a live horse doctor. After running with this configuration, the error arm-Eabi-GCC is displayed: the file or directory does not exist... But there is clearly the GCC in the configuration, because there is a similar error when using ARM-Linux-GCC, because there is no such library, now we have this library and say it does not exist. Isn't it a pitfall? Then, with a try, I added the path of arm-Eabi-to path and compiled it again using this configuration file. tt was so touched that it was compiled successfully, then, the compiled database is used for testing and running successfully .. I was so happy that I couldn't sleep at night.
(8) In the past, arm-Linux-GCC was used to compile binary code that can be run on an arm machine on an x86 machine. It failed to run on Android because Android is not an ARM platform? I don't know if my analysis is correct. If there is a mistake, please correct me. For more information about GCC, arm-Linux-GCC, and arm-Eabi-GCC, I hope you can tell me this lesson for Linux cainiao. ^_^
(9) Conclusion: porting x264 to Android does not use GCC, rather than arm-Linux-GCC, but arm-Eabi-GCC.
Bytes --------------------------------------------------------------------------------------
After so long, I have finally entered the topic orz.
The compilation method described in this article finally generates a static library. If you need to compile it into a dynamic library, you can click here. However, this article only introduces the idea of compiling, the exact method is not provided. You have to think about it yourself!
[1: Compile x264 using ndk-r4b]
Steps:
1. decompress the x264 compressed package. Assume that the decompressed directory is libx264.
2, create a script file myconfig. Sh in the libx264 directory, and paste the code in compile libx264 with android-ndk-r4b to myconfig. Sh.
3, change the first configuration export arm_root =/home/Frank/android-ndk-r4b to the path of your ndk-r4b.
4. Open the terminal, locate the terminal to the libx264 directory, and enter sudo Sh./myconfig. Sh
5. When you are prompted to run make, enter make
6. If the program can be compiled normally, congratulations, you have succeeded. You don't have to read the following content. If you enter make, you will see the information: /bin/sh: Arm-Eabi-GCC: The command is not found, so you and I have encountered this problem. Please refer to step 2.
7. Enter sudo gedit/etc/profile on the terminal, locate at the end of the file in the opened text, and enter the following script
# Set arm-Eabi-GCC Environment
Export arm_eabi_gcc =/opt/Java/ndk/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin
Export Path = $ arm_eabi_gcc: $ path
Note: The/opt/Java/ndk/android-ndk-r4b in arm_eabi_gcc is the path of my ndk-r4b and you need to modify it according to your ndk path!
Save and close the text. This step aims to add environment variables for ARM-Eabi-GCC.
8. The configuration modified in the previous step takes effect only after the computer is restarted. To make the configuration take effect immediately, enter source/etc/profile on the terminal, and then enter: echo $ path: Check whether the path of arm_eabi_gcc is included in the output content. If yes, check Step 1. Otherwise, check carefully and reconfigure the environment variables.
9. After the environment variable is configured, enter the command: make. If you do not prompt that the arm-Eabi-GCC command is not found and the program is being compiled, congratulations, you will compile libx264successfully.
10. The size of the compiled libx264.a file is 773.8 kb. What about yours? Pai_^
[2: Compile x264 using ndk-r6]
Ndk-r6 is no longer used arm-embi-GCC, but arm-Linux-androideabi-GCC. For details about the compilation steps, see [1: compile with ndk-r4b], but use different myconfig. SH and arm_eabi_gcc.
Here I paste the myconfig. Sh script compiled with ndk-r6:
# ------------------------------ Myconfig. Sh ------------------------------
Export arm_root =/opt/Java/ndks/android-ndk-r6
Export arm_inc = $ arm_root/platforms/Android-8/arch-arm/usr/include/
Export arm_lib = $ arm_root/platforms/Android-8/arch-arm/usr/lib/
Export arm_tool = $ arm_root/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
Export arm_libo = $ arm_tool/lib/GCC/ARM-Linux-androideabi/4.4.3
Export Path = $ arm_tool/bin: $ path
Export arm_pre = arm-Linux-androideabi
. /Configure -- disable-gpac -- extra-cflags = "-I $ arm_inc-FPIC-dandroid-FPIC-mthumb-interwork-ffunction-sections-funwind-tables-fstack-protector-fno -Short-enums-d1_arm_arch_5 _-d1_arm_arch_5t _-d1_arm_arch_5e _-d1_arm_arch_5te __
-Wno-psabi-March = armv5te-mtune = XScale-msoft-float-mthumb-OS-fomit-frame-pointer-fno-strict-aliasing-Finline-Limit = 64-dandroid -Wa, -- noexecstack-MMD-MP "-- extra-ldflags ="-nostdlib-bdynamic-wl, -- no-undefined-wl,-Z, noexecstack-wl,-Z, nocopyreloc
-Wl,-soname,/system/lib/libz. so-wl,-rpath-link = $ arm_lib, -Dynamic-linker =/system/bin/linker-L $ arm_lib-nostdlib $ arm_lib/crtbegin_dynamic.o $ arm_lib/crtend_android.o-LC-lm-LDL-lgcc "-- Cross-Prefix = $ {arm_pre}--- disable-ASM -- Host = arm-Linux -- disable-shared
# ------------------------------ Myconfig. Sh -----------------------------
Note: The first arm_root still needs to be configured based on the location of your ndk-r6
In addition, add the configuration to/etc/profile:
# Set arm-Linux-androideabi-gcc
Export arm_linux_androideabi_gcc =/opt/Java/ndk/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
Export Path = $ arm_linux_androideabi_gcc: $ path
I use ndk-r6 compiled libx264.a size of 778.6 K, you can refer to your compiled file size.
Bytes --------------------------------------------------------------------------------------
This article is over. If you have compiled libx264 through this article, you can: "Sorry, don't forget to give a good review! ^_^"