writing Android.mk file

1,016 views
Skip to first unread message

kaushik mv

unread,
Jun 28, 2011, 2:12:09 PM6/28/11
to android-ndk
I have an application which consists of large set of C files and it
uses Makefile to create the executable. I have to put this in android.
I do not want to use ndk standalone tool chain. So I have to write
Android.mk file for it. I am not able to figure out how to write it.
What is the procedure for writing Android.mk file?

thanks,
kaushik.

Doug .

unread,
Jun 28, 2011, 10:17:54 PM6/28/11
to andro...@googlegroups.com
Have a look at the templates in the samples directory.

There is no good way to port an existing makefile to an android makefile if you don't want to use a stand alone toolchain.

A trivial makefile might look something like this for a shared library:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# Build source list
SOURCES :=  ... # list source files

# Includes
LOCAL_C_INCLUDES := \
  $(LOCAL_PATH)/include/ \
  $(NDK_MODULE_PATH)/libpng-android/jni/  # Some external library dependency

# Build library
LOCAL_MODULE := libsomething
include $(BUILD_STATIC_LIBRARY)

$(call import-module,libpng-android/jni)

Or perhaps this for an actual app (native activity):

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := native-activity
LOCAL_SRC_FILES := sample.c # all source files listed here
LOCAL_C_INCLUDES := \ # all includes here
  $(ROOT_PATH)/../../libsomething-android/jni/include
LOCAL_LDLIBS    := \
  -llog \
  -landroid \
  -lEGL \
  -lGLESv1_CM \
  -lz
LOCAL_STATIC_LIBRARIES := android_native_app_glue something
include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)
$(call import-module,libsomething-android/jni)

In summary, if you porting a non-trivial code base, you want to make a stand alone toolchain. Rewriting the makefile for android will be hard. 

Some nice folks have made these cmake tools, which significantly simply your life if you're already using cmake:

... of course, then you need to make multiple cmake profiles, but still. 

~
Doug.

kaushik mv

unread,
Jun 30, 2011, 2:34:37 PM6/30/11
to android-ndk
I did not actually get how to use cmake. I already used stand alone
tool chain to port it on android and I have some doubts regarding this

(1)When I execute the file from java code it is running slow. I mean
to say normal C codes on my computer are running fast but when i use
tool chain and execute them on emulator it is taking time to execute.
If I dont use the tool chain and if I make them as library using
Android.mk and call the function from java code will it run fast?

(2) Advantage of using cmake over stand alone tool chain

(3) Any other way to make the executable run fast ( like I compiling
with flag -Os )?

Thanks in advance

kaushik.

kaushik mv

unread,
Jul 1, 2011, 7:48:39 AM7/1/11
to android-ndk
Can you give me an example. Suppose If I want to execute the following
command how to write it in Android.mk file?

gcc -DPACKAGE_NAME=\"flite+hts_engine\" -DPACKAGE_TARNAME=\"flite-
hts_engine\" -DPACKAGE_VERSION=\"1.00\" -DPACKAGE_STRING=\"flite
+hts_engine\ 1.00\" -DPACKAGE_BUGREPORT=\"hts-engine-
us...@lists.sourceforge.net\" -DHAVE_LIBM=1 -DSTDC_HEADERS=1 -
DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -
DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -
DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -
DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_VPRINTF=1 -DHAVE_SQRT=1 -
DHAVE_STRCHR=1 -DHAVE_STRRCHR=1 -DHAVE_STRSTR=1 -
DFLITE_PLUS_HTS_ENGINE=1 -I. -I../include -I../flite/include -I../
flite/lang/cmu_us_kal -I../flite/lang/cmulex -I../flite/lang/usenglish
-I/home/kaushik/akshar_hts_engine_API-1.03/include/ -g -O2 -MT
flite_hts_engine.o -MD -MP -MF .deps/flite_hts_engine.Tpo -c -o
flite_hts_engine.o flite_hts_engine.c


And If two or more commands are to be executed how to specify it?
please help me regarding this.

thanks in advance
kaushik.


On Jun 29, 7:17 am, "Doug ." <douglas.lin...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages