4

i want create an app or .apk file which can play video in particular format.

For this I had compiled my source files and taken object files, from object files i have generated one shared library file (.so) using command

gcc -c -fPIC hello.c -o hello.o
gcc hello.o -shared -o libhello.so 

can somebody please help me with the steps to create apk file from .so file in android Eclipse or android sdk

what is the importence of java files while creating an apk file...

sayedjuned
  • 183
  • 2
  • 10

3 Answers3

4

From what you have put up above, i presume that you are not compiling your custom decoder code using the tool chains provided by android ndk. I have performed the same task which you are supposed to do.

First of all what you need to do is:

1) Create a Android project

2) In side the root directory of the Android project, create a folder called "jni"

3) Dump in all your "C" code (custom decoders code) into this folder.

4) Create a file in the same /jni folder which has the decoder code and name the file as Android.mk . If you know the concept of make files in linux, the same thing implies here, only the syntax changes.(you can refer to some sample examples that comes along android ndk).

5) Download Android-ndk from the developers website ( it also has sample examples you can refer them to learn it).

6) Configure PATH variable to ndk directory.

Eg: export NDK_PATH=/home/myPC/android-ndk-r7b

7) cd to jni directory and type the command ndk-build. If everyting goes well you will now have a .so file generated, which means your code has been successfully cross-compiled to android platform.

8) Now in the /src folder you will have a .java file, from which you will have to load the .so file generated. For this you can refer the sample examples in android ndk.

9) Use JNI to interface between your application and .so generated. For example if your custom decoder is designed to take an input file pointer to decode the file, the accordingly you will have to implement the JNI code.

10) Finally when you have done all, and if your decoder is providing you with RGB data, then you can use openGL ES to display the decoded pictures from the native code only.

Zax
  • 2,870
  • 7
  • 52
  • 76
  • Thanks for the reply, i tried above steps. When i tried to run on my code on visual studio 2010 it is ok with no error and output completely good. When i run on the same source code in eclipse with the above steps Up to steps 6 I didn’t found any issue. In step 7 I found huge number of errors and warnings. Are there any settings in eclipse Help me… – sayedjuned Feb 22 '14 at 11:39
  • @sayedjuned: You need not export the path in case you are finding it difficult. What you can do is, skip step 6 and goto step 7. There instead of ndk-build, give the absolute path to the ndk-build thats it. – Zax Feb 22 '14 at 17:41
  • @sayedjuned: also you need not do this in eclipse, via the ternimal you can do the above steps. – Zax Feb 22 '14 at 17:46
  • Thanks for the reply. Can you please clarify after doing the above steps, is there a need of any container format like flv, MP4 to play the video on android device. Is there any role of any specific players or framework to display my decoded YUV. If not how does my YUV play in Android device – sayedjuned Mar 14 '14 at 14:26
  • @sayedjuned: If the task is just to display the YUV image, then you need not have any container format. Various API used to render YUV from native code are discussed here: https://vec.io/posts/how-to-render-image-buffer-in-android-ndk-native-code – Zax Mar 17 '14 at 07:21
1

You need to install NDK first. Then you need to provide JNI wrapper for your library. The easiest way is to have a look into hello-jni and two-libs sample apps to learn how to do this. You will find the app under ndk_home/samples/.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
1

I would try using ant. http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html

Please let me know how it goes (not sure about all this .so thing).

If you have any trouble with the tutorial I linked, let me know for that too, I've been through it and could help with it.

Chris Neve
  • 2,164
  • 2
  • 20
  • 33