How to include AIDL-generated headers in native code in AOSP? - android

I have a native module under /devices:
- module
-- aidl
--- com
---- my
----- package
------ IMyInterface.aidl
-- Android.mk
-- Proxy.h
-- Proxy.cpp
I want to use binder in this module. My Android.mk:
LOCAL_PATH := $(call my-dir)
$(call emugl-begin-shared-library,libMyModule)
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl
LOCAL_SRC_FILES := \
aidl/com/my/package/IMyInterface.aidl \
Proxy.cpp \
LOCAL_HEADER_LIBRARIES := libbinder_headers \
libhidlbase_impl_internal \
libbase
LOCAL_SHARED_LIBRARIES := \
libbinder \
libutils \
liblog \
libcutils
$(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
$(call emugl-import,libOpenglCodecCommon$(GOLDFISH_OPENGL_LIB_SUFFIX))
$(call emugl-end-module)
When I'm building it, it generates C++ headers, but they are located in the intermediates directory only:
$ ls out/target/product/emulator_x86_64/obj/SHARED_LIBRARIES/libMyModule_intermediates/aidl-generated/include/com/my/package:
BnMyInterface.h BpMyInterface.h IMyInterface.h
How should I include them in my Proxy.cpp? If I just add #include "IMyInterface.h", build system doesn't see it: fatal error: 'IMyInterface.h' file not found

You may have to include it like #include <com/my/package/BnMyInterface.h>

Related

Compiling native android library with multiple c files using ndk build errors * No rule to make target

I am having an issue compiling a shared C library into a .so for android. I've copied all the .c and .h files into the jni folder. I posted a screenshot below to show the contents of the Android.mk file as well as the folder hierarchy.
below is the output of ndk-build run in the project root folder NTRUMLS
[kenway#jackdaw NTRUMLS]$ ndk-build
make: *** No rule to make target '/media/bigdata/Android/Sdk/ndk-bundle/build/core/crypto_hash_sha512.c', needed by 'obj/local/arm64-v8a/objs/ntrumls/crypto_hash_sha512.o'. Stop.
i checked for spaces and typo's. here's the contents of my Android.mk copied directly below.
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_PATH := $(call my-dir)
LOCAL_MODULE := libntrumls
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := crypto_hash_sha512.c \
crypto_stream.c \
convert.c \
randombytes.c \
fastrandombytes.c \
pack.c \
pol.c \
params.c \
pqntrusign.c \
shred.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
Move
LOCAL_PATH := $(call my-dir)
to be the first statement of your Android.mk script.
Try following
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libntrumls
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := Main_M1_play.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

How to compile ZBar to work on x64 Android device

The actual problem is with compiling native library using ndk-build - libiconv - that ZBar has in dependencies.
Did anyone successfully got ZBar to work on x64 Android device?
EDIT: To be more specific.
I followed all steps from this article:
http://danilogiulianelli.blogspot.com/2012/12/how-to-cross-compile-libiconv-for.html
Using libiconv version 1.13.1 - same as used in article.
Content of Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
TARGET_ARCH_ABI := arm64-v8a
LOCAL_MODULE := iconv
LOCAL_CFLAGS := \
-Wno-multichar \
-D_ANDROID \
-DLIBDIR="\"c\"" \
-DBUILDING_LIBICONV \
-DIN_LIBRARY
LOCAL_C_INCLUDES := \
../libiconv-1.13.1 \
../libiconv-1.13.1/include \
../libiconv-1.13.1/lib \
../libiconv-1.13.1/libcharset/include
LOCAL_SRC_FILES := \
../libiconv-1.13.1/lib/iconv.c \
../libiconv-1.13.1/lib/relocatable.c \
../libiconv-1.13.1/libcharset/lib/localcharset.c
include $(BUILD_SHARED_LIBRARY)
Then execution of ndk-build V=1 ends with an error:
(output omitted)
/Users/mrtowel/workspace/jni/../libiconv-1.13.1/libcharset/lib/localcharset.c:49:24: fatal error: langinfo.h: No such file or directory
# include <langinfo.h>
^
compilation terminated.
make: *** [/Users/mrtowel/workspace/obj/local/armeabi/objs/iconv/__/libiconv-1.13.1/libcharset/lib/localcharset.o] Error 1
Any help will be appreciated.

Building mdadm tool for android platform

I have downloaded mdadm source code from below location
https://www.kernel.org/pub/linux/utils/raid/mdadm/
Copied these files at /system/extras/mdadm
And, added Android.mk file for the executable binary of mdadm.
But, I am seeing following error when I compiled it:
target thumb C: mdadm <= system/extras/mdadm/sg_io.c
**arm-linux-androideabi-gcc: fatal error: cannot specify -o with -c, -S or -E with multiple files**
compilation terminated.
make: *** [out/target/product/<prod_name>/obj/EXECUTABLES/mdadm_intermediates/sg_io.o] Error 1
Any pointers to resolve this issue. Thanks in advance.
My Android.mk file looks like
LOCAL_PATH := $(call my-dir)
mdadm_src_files := Build.c mdopen.c mdmon.c monitor.c \
managemon.c util.c maps.c mdstat.c \
sysfs.c policy.c lib.c Kill.c sg_io.c \
dlink.c super0.c super1.c super-intel.c \
super-mbr.c super-gpt.c super-ddf.c sha1.c \
crc32.c msg.c bitmap.c xmalloc.c platform-intel.c \
probe_roms.c config.c Manage.c Assemble.c Create.c Detail.c \
Examine.c Grow.c Monitor.c Query.c Incremental.c Dump.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(mdadm_src_files)
LOCAL_MODULE := mdadm
LOCAL_SHARED_LIBRARIES := libc
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../kernel/include/
LOCAL_C_INCLUDES +=
$(LOCAL_PATH)/../../../kernel/arch/arm/include/asm/*
include $(BUILD_EXECUTABLE)

ndk build_static_library make: Nothing to be done for `all'

I meet a problem when I build the libjpeg on android in eclipse. The jni contains Android.mk as follow:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/jpeg8d-master
#LOCAL_STATIC_LIBRARIES := libjpeg
include $(BUILD_STATIC_LIBRARY)
#include $(LOCAL_PATH)/jpeg8d-master/Android.mk
The jpeg8d is the source code I download from github. The android.mk
LOCAL_PATH:= $(call my-dir)
# ------------------------------------------------------------------
# Static library for Cocos
# ------------------------------------------------------------------
include $(CLEAR_VARS)
LOCAL_MODULE := cocos_jpeg_static
LOCAL_MODULE_FILENAME := libjpeg
LOCAL_SRC_FILES := \
jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c \
jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \
jquant2.c jutils.c jmemmgr.c jcarith.c jdarith.c jaricom.c
# Use the no backing store memory manager provided by
# libjpeg. See install.txt
LOCAL_SRC_FILES += \
jmemnobs.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_STATIC_LIBRARY)
ndk-build give the tips :
make: Nothing to be done for `all'.
But if I Set the jpeg8d Android.mk BUILD_SHARED_LIBRARY,I get the libjpeg.so.
I don't know why. Can anyone help me ?
Solution:
You can redefine the library name by the LOCAL_MODULE_FILENAME. In my problem, I have set the LOCAL_MODULE_FILENAME=libjpeg, but I don't add the
APP_MODULES:=cocos_jpeg_static (remember cocos_jpeg_staic is the LOCAL_MODULE not the LOCAL_MODULE_FILENAME) into the Application.mk which is in the jni directory not in the jpeg8d-master directory.
I generate the libjpeg.a when i add this line into the Appliction.mk
APP_MODULES:=cocos_jpeg_static

Compiling tesseract through android NDK

I am trying to compile tesseract for android using android ndk r5, code of tesseract is obtained by checking out http://code.google.com/p/tesseract-android-tools/, i am unable to compile tesseract and got errors,
Install : libjpeg.so => libs/armeabi/libjpeg.so
make: *** No rule to make target `//cygdrive/e/DemoExamples_WorkSpace/tesseract-android-tools/jni/../external/leptonlib-1.66/src/adaptmap.c', needed b
y `/cygdrive/e/DemoExamples_WorkSpace/tesseract-android-tools/obj/local/armeabi/objs/lept//cygdrive/e/DemoExamples_WorkSpace/tesseract-android-tools/j
ni/../external/leptonlib-1.66/src/adaptmap.o'. Stop.
Please help me to sort out this problem.
I had the same issue and I think I solved it. May be helpful for those who get similar errors:
On OSX, I just changed the Android.mk files by giving the absolute paths as follows
First: jni/Android.mk
TESSERACT_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/external/tesseract-3.00
LEPTONICA_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/external/leptonlib-1.66
LIBJPEG_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/external/libjpeg
Then: jni/com_googlecode_leptonica_android/Android.mk
REAL_LOCAL_PATH := /Users/.../tesseract-android-tools/tesseract-android-tools/jni/com_googlecode_leptonica_android
and jni/com_googlecode_tesseract_android/Android.mk accordingly.
I believe the problem is caused by the relative path which is returned by the following command:
$(call my-dir)
Then I needed to run the ndk-build as superuser and all compiled just fine.
Search for adaptmap among the makefiles. Build the makefile that creates this module first.
So, I have compiled in windows 7 and windows xp, but it´s an ugly workaround.
The basic problem is "LOCAL_PATH := "with blank value, I don´t know why cygwin have problem with this, so you have to change paths on Android.mk files to work.
I will refer for Android.mk using numbers, my jni path is:
-jni
Android.mk(1)
Aplication.Mk
-com_googlecode_tesseract_android(dir)
Android.mk(2)
tesseract(dir)
-com_googlecode_leptonica_android(dir)
Android.mk(3)
leptonlib(dir)
-libjpeg
Android.mk(4)
=================================
Android.mk(1)
Put tesseract and leptonica sources on googlecode subdirectories like this:
TESSERACT_PATH := $(call my-dir)/com_googlecode_tesseract_android/tesseract -- directory to source, change for respective name
LEPTONICA_PATH := $(call my-dir)/com_googlecode_leptonica_android/leptonlib -- directory to source, change for respective name
LIBJPEG_PATH := $(call my-dir)/libjpeg
=================================
Android.mk(2)
1 - Change:
LOCAL_PATH:=
to
LOCAL_PATH:= $(call my-dir)
2 - Change:
BLACKLIST_SRC_FILES := \
%endiantest.c \
%freetype.c \
%xtractprotos.c
LOCAL_SRC_FILES := \
$(filter-out $(BLACKLIST_SRC_FILES),$(wildcard $(LEPTONICA_PATH)/src/*.c))
to
LOCAL_SRC_FILES := \
leptonlib/src/adaptmap.c \
leptonlib/src/affine.c \
leptonlib/src/affinecompose.c \ ... continue (Put all the files on src directory, without files listed on blacklist).
Note: replace leptonlib for subrectory name of leptonlib source.
3- Change:
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SRC_FILES += \
$(REAL_LOCAL_PATH)/stdio/open_memstream.c \
$(REAL_LOCAL_PATH)/stdio/fopencookie.c \
$(REAL_LOCAL_PATH)/stdio/fmemopen.c
LOCAL_C_INCLUDES += \
$(REAL_LOCAL_PATH)/stdio
endif
# jni
LOCAL_SRC_FILES += \
$(REAL_LOCAL_PATH)/box.cpp \
$(REAL_LOCAL_PATH)/pix.cpp \
$(REAL_LOCAL_PATH)/pixa.cpp \
$(REAL_LOCAL_PATH)/utilities.cpp \
$(REAL_LOCAL_PATH)/readfile.cpp \
$(REAL_LOCAL_PATH)/writefile.cpp \
$(REAL_LOCAL_PATH)/jni.cpp
LOCAL_C_INCLUDES += \
$(REAL_LOCAL_PATH) \
$(LEPTONICA_PATH)/src
to
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SRC_FILES += \
stdio/open_memstream.c \
stdio/fopencookie.c \
stdio/fmemopen.c
LOCAL_C_INCLUDES += \
stdio
endif
# jni
LOCAL_SRC_FILES += \
box.cpp \
pix.cpp \
pixa.cpp \
utilities.cpp \
jni.cpp
LOCAL_C_INCLUDES += \
leptonlib/src
=================================
Android.mk(3)
1 - Change:
LOCAL_PATH:=
to
LOCAL_PATH:= $(call my-dir)
2 - Change
On LOCAL_SRC_FILES change $(TESSERACT_PATH) to tesseract --Note: replace tesseract for subrectory name of tesseract source.
DON´T REPLACE $(TESSERACT_PATH) on LOCAL_C_INCLUDES only LOCAL_SRC_FILES.
DON´T REPLACE $(LEPTONICA_PATH) on LOCAL_C_INCLUDES.
3 - Change:
In #jni
LOCAL_SRC_FILES += \
$(REAL_LOCAL_PATH)/tessbaseapi.cpp
LOCAL_C_INCLUDES += \
$(REAL_LOCAL_PATH) \
$(TESSERACT_PATH)/api \
$(LEPTONICA_PATH)/src
to
LOCAL_SRC_FILES += \
tessbaseapi.cpp
LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
$(TESSERACT_PATH)/api \
$(LEPTONICA_PATH)/src
For me working on windows 7, windows xp, Mac and Ubuntu.

Categories

Resources