Finding out Android's version in AOSP on native code compile time? - android

I am building AOSP for a device. Is there a way to get the current AOSP version at native code compile time? I am looking for something similar to the LINUX_VERSION_CODE and KERNEL_VERSION(X,Y,Z) directives in Linux. More specifically, I would like to do something that looks like this in one of my own AOSP add-on projects:
#if (ANDROID_VERSION_CODE >= ANDROID_VERSION(4,2,1))
... compile something ...
#else
... compile something else...
#endif

Probably, you can use PLATFORM_VERSION and/or PLATFORM_SDK_VERSION, please see version_defaults.mk

The PLATFORM_VERSION is defined in the AOSP build directory:
build/core/version_defaults.mk:
ifeq "" "$(PLATFORM_VERSION)"
# This is the canonical definition of the platform version,
# which is the version that we reveal to the end user.
# Update this value when the platform version changes (rather
# than overriding it somewhere else). Can be an arbitrary string.
PLATFORM_VERSION := 5.1
endif
In a makefile of your product (or anywhere else) define the following make variables and pass them as macros to the compiler:
# Passing Android version to C compiler
PLATFORM_VERSION_MAJOR := $(word 1, $(subst ., ,$(PLATFORM_VERSION)))
PLATFORM_VERSION_MINOR := $(word 2, $(subst ., ,$(PLATFORM_VERSION)))
PLATFORM_VERSION_REVISION := $(word 3, $(subst ., ,$(PLATFORM_VERSION)))
COMMON_GLOBAL_CFLAGS += -DPLATFORM_VERSION_MAJOR=$(PLATFORM_VERSION_MAJOR) \
-DPLATFORM_VERSION_MINOR=$(PLATFORM_VERSION_MINOR)
ifneq ($(PLATFORM_VERSION_REVISION),)
COMMON_GLOBAL_CFLAGS += -DPLATFORM_VERSION_REVISION=$(PLATFORM_VERSION_REVISION)
endif
Define a header file with the version code:
android_version.h:
#define ANDROID_VERSION(major, minor, rev) \
((rev) | (minor << 8) | (major << 16))
#ifndef PLATFORM_VERSION_REVISION
#define PLATFORM_VERSION_REVISION 0
#endif
#define ANDROID_VERSION_CODE ANDROID_VERSION( \
PLATFORM_VERSION_MAJOR, \
PLATFORM_VERSION_MINOR, \
PLATFORM_VERSION_REVISION)
Now, to make compile time decisions based on android version simply include the android_version.h file and use pre-processer #if's.

Related

How to create a single native shared library with no dependency for Android using Qt Creator

I have created a shared library using Qt Creator and I have added the Android SDK, Android NDK and Android Qt kit. Then I compiled my library for Android successfully. I even tested it in an Android application successfully.
As I am not using the Qt libraries, my library does not depend on huge Qt libraries. But unexpectedly, here is my dependencies:
[matin#Lenovo-X1-Fedora ~]$ ndk-depends libMatinChess.so
WARNING: Could not find library: libgnustl_shared.so
libMatinChess.so
libz.so
libstdc++.so
libm.so
liblog.so
libgnustl_shared.so
libdl.so
libc.so
And when I checked the libgnustl_shared.so it has more than 5 MBs size. So I have to place this huge library next to my tiny library in every project.
Another option is to link it statically. I previously asked the question about how is it possible to link a dependency statically and I figured out that it is possible by adding the QMAKE_LFLAGS += -static in my .pro file:
This flags works perfect and removes the dependency of stdc++ on Windows compilation. But in android I get the following errors:
error: cannot find -lgnustl_shared
error: cannot find -llog
error: cannot find -lz
error: cannot find -ldl
I searched my android-ndk folder and I realized that there is no liblog.a, libz.a and libdl.a files located in it but there is a libgnustl_static.a file.
I tried to add it using LIBS += -Lpath/to/libdir -lgnustl_static but the result was the same.
There is a solution in CMake that was mentioned in the previous question as a comment that there is the option to set APP_STL := gnustl_static in the makefile. But there seems to be no equivalent in QMake.
And a complicated issue is that when I use CONFIG += static, it compiles successfully but my library is not shared anymore. it becomes a static library.
How can I link gnustl statically so that my library works with no other dependencies?
Edit
I read the compile output and found the following line:
/home/matin/Applications/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
--sysroot=/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm/
-static -Wl,--no-undefined -Wl,-z,noexecstack -shared -Wl,-soname,libMatinChess.so -o libMatinChess.so matinchessdll.o bishop.o piece.o board.o king.o memorymanager.o pawn.o queen.o
blackpawn.o knight.o rook.o whitepawn.o squarelist.o game.o
boardhistory.o
-L/home/matin/Applications/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a
-L/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm//usr/lib
-lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
And I was not able to remove gnustl_shared using LIB -= -lgnustl_shared
By reading the compile output, I executed the following command manually and created my library with 1 MB size. And it works correctly.
/home/matin/Applications/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
--sysroot=/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm/
-Wl,--no-undefined -Wl,-z,noexecstack -shared -Wl,-soname,libMatinChess.so -o libMatinChess.so matinchessdll.o bishop.o piece.o board.o king.o memorymanager.o pawn.o queen.o
blackpawn.o knight.o rook.o whitepawn.o squarelist.o game.o
boardhistory.o
-L/home/matin/Applications/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a
-L/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm//usr/lib
-lgnustl_static
But still I don't know how to automate this command in QMake
Below script android.pri did help for me which I include in my projects to get rid of some QtCreator related bugs:
## this file changes many values set by "Qt/mkspec/android-g++/qmake.conf"
## since the failed to work with newest Android SDK and/or NDK
##
## use below lines before including this file
##
#ANDROID_API = 21
#ANDROID_ARCH = armeabi-v7a
#do you after using this have still problems?
#there is an bug inside "QtCreator" (not inside "Gradle")
# that leads to .o and .so files get not found
#solved: not required to change "QMAKE_LIBDIR" just open "AndroidManifest.xml"
# and change "Minimum required SDK" to "not set" save then restore to last
# value and save agian to force "QtCreator" update
isEmpty(ANDROID_API): ANDROID_API = 21
isEmpty(ANDROID_ARCH): ANDROID_ARCH = armeabi-v7a #ANDROID_TARGET_ARCH=armeabi-v7a
#remove old values
CONFIG -= $$ANDROID_PLATFORM
QMAKE_CFLAGS -= --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_CXXFLAGS -= --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_LFLAGS -= --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
#NDK Root directory
ANDROID_NDK_ROOT = $$(ANDROID_NDK_ROOT) #first try Environment variable
isEmpty(ANDROID_NDK_ROOT) | !exists($$ANDROID_NDK_ROOT) {
ANDROID_NDK_ROOT = D:/android/sdk/ndk-bundle }
NDK_ROOT = $$ANDROID_NDK_ROOT
#API Level
ANDROID_NDK_PLATFORM = android-$$ANDROID_API
ANDROID_PLATFORM = $$ANDROID_NDK_PLATFORM
CONFIG += $$ANDROID_PLATFORM
DEFINES += __ANDROID_API__=$$ANDROID_API
#Architecture
ANDROID_TARGET_ARCH = $$ANDROID_ARCH
equals(ANDROID_TARGET_ARCH, x86): ANDROID_ARCHITECTURE = x86
else: equals(ANDROID_TARGET_ARCH, x86_64): ANDROID_ARCHITECTURE = x86_64
else: equals(ANDROID_TARGET_ARCH, mips): ANDROID_ARCHITECTURE = mips
else: equals(ANDROID_TARGET_ARCH, mips64): ANDROID_ARCHITECTURE = mips64
else: equals(ANDROID_TARGET_ARCH, arm64-v8a): ANDROID_ARCHITECTURE = arm64
else: ANDROID_ARCHITECTURE = arm
#API Path
ANDROID_PLATFORM_ROOT_PATH = $$NDK_ROOT/platforms/$$ANDROID_PLATFORM/arch-$$ANDROID_ARCHITECTURE/
ANDROID_PLATFORM_PATH = $$ANDROID_PLATFORM_ROOT_PATH/usr
QMAKE_CFLAGS += --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_CXXFLAGS += --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_LFLAGS += --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
# used to compile platform plugins for android-4 and android-5
QMAKE_ANDROID_PLATFORM_INCDIR = $$NDK_ROOT/sysroot/usr/include #headers bundled
QMAKE_ANDROID_PLATFORM_LIBDIR = $$ANDROID_PLATFORM_PATH/lib #same as before
ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/libs/$$ANDROID_TARGET_ARCH
ANDROID_SOURCES_CXX_STL_INCDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/include $$ANDROID_SOURCES_CXX_STL_LIBDIR/include
equals(ANDROID_TARGET_ARCH, x86_64)|equals(ANDROID_TARGET_ARCH, mips64): \
QMAKE_ANDROID_PLATFORM_LIBDIR = $${QMAKE_ANDROID_PLATFORM_LIBDIR}64
#additionl fix
QMAKE_CFLAGS += -Wno-attributes #ignore Android Macros
QMAKE_CFLAGS += \
-Wno-unused-parameter \
-Wno-unused-variable \
-Wno-unused-but-set-variable \
-Wno-unused-value \
-Wno-unused-function
INCLUDEPATH += $$ANDROID_NDK_ROOT/sysroot/usr/include
INCLUDEPATH += $$ANDROID_NDK_ROOT/sysroot/usr/include/arm-linux-androideabi
## you most times need set "ANDROID_PACKAGE_SOURCE_DIR" manualys
isEmpty(ANDROID_PACKAGE_SOURCE_DIR) {
DISTFILES += \
$$PWD/res/android/AndroidManifest.xml \
$$PWD/res/android/gradle/wrapper/gradle-wrapper.jar \
$$PWD/res/android/gradlew \
$$PWD/res/android/res/values/libs.xml \
$$PWD/res/android/build.gradle \
$$PWD/res/android/gradle/wrapper/gradle-wrapper.properties \
$$PWD/res/android/gradlew.bat
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/res/android
!build_pass:warning(no ANDROID_PACKAGE_SOURCE_DIR defaulted to $$ANDROID_PACKAGE_SOURCE_DIR)
}
#ANDROID_EXTRA_LIBS = $$PWD/libTest.so ## you may need
#ANDROID_DEPLOYMENT_SETTINGS_FILE = $$PWD/android-settings.json ## no need ever
#QML_IMPORT_PATH
#QML_DESIGNER_IMPORT_PATH
#QMAKE_PROJECT_NAME
#isEmpty(ANDROID_PACKAGE_SOURCE_DIR) {
# # note that $$PWD/android/assets directory is "QFile::ReadOnly" on android
# android: varDirInstall.path =/assets
# else: varDirInstall.path =$$OUT_PWD
#
# varDirInstall.files = $$files($$PWD/android/assets)
# win32: varDirInstall.files ~= s|\\\\|/|g
# varDirInstall.depends += FORCE
# INSTALLS += varDirInstall
#}
usage sample:
ANDROID_API = 21
ANDROID_ARCH = armeabi-v7a
include($$PWD/android.pri)
but I do get below error some times any way for TEMPLATE = app:
No Android arch set by the .pro file. Error while building/deploying
project vpnAndroid (kit: Qt5_android_armeabi-v7a) When executing step
"Deploy to Android device"
This special QtCreator related bug costs time to fix:
Close IDE and delete all the QtCreator setting files (in windows "C:\Users\Admin\UserName\Roaming\QtProject")
Start IDE again and reconfigure Android Paths, Compilers, Debugers and Kits in this order
Close IDE to save changes
Backup the folder mentioned before to save time see below:
the QtCreator plugins related to Android do store there failure in settings and so you need to backup since the plugins may do that again

Android NDK for x86_64 has no reference for bcopy and index

I am trying to compile Lame sound library with Android NDK for x86_64 architecture. I am getting the below link error for undefined references to bcopy and index:
jni/libmp3lame/encoder.c:471: error: undefined reference to 'bcopy'
jni/libmp3lame/encoder.c:476: error: undefined reference to 'bcopy'
jni/libmp3lame/id3tag.c:1125: error: undefined reference to 'index'
jni/libmp3lame/newmdct.c:1036: error: undefined reference to 'bcopy'
jni/libmp3lame/util.c:685: error: undefined reference to 'bcopy'
The code successfully compiles for x86 and arm architectures.
So I digged through NDK's libs a bit and noticed that bcopy and index are both exported in libc.so for x86 and arm platforms but not for x86_64 (see below objdump outputs).
$> objdump -d android-ndk-r10d/platforms/android-21/arch-arm/usr/lib/libc.so | grep bcopy -A 6
0000b000 <bcopy>:
b000: e52db004 push {fp} ; (str fp, [sp, #-4]!)
b004: e28db000 add fp, sp, #0
b008: e28bd000 add sp, fp, #0
b00c: e8bd0800 ldmfd sp!, {fp}
b010: e12fff1e bx lr
$> objdump -d android-ndk-r10d/platforms/android-21/arch-x86/usr/lib/libc.so | grep -A 6 bcopy
00009fb0 <bcopy>:
9fb0: 55 push %ebp
9fb1: 89 e5 mov %esp,%ebp
9fb3: 5d pop %ebp
9fb4: c3 ret
$> objdump -d android-ndk-r10d/platforms/android-21/arch-x86_64/usr/lib/libc.so | grep -A 6 bcopy
<<NOTHING FOUND>>
Any thoughts? Below are my Android.mk and Application.mk files.
Application.mk:
APP_ABI:=x86_64
APP_PLATFORM := android-21
Android.mk:
LOCAL_PATH := $(call my-dir)
APP_PLATFORM := android-21
include $(CLEAR_VARS)
LOCAL_MODULE := libmp3lame
LOCAL_SRC_FILES := \
...<list-of-.c-files>...
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
You can fix this cleanly with a single line in Application.mk (docs):
APP_CFLAGS += -DSTDC_HEADERS
Why?
LAME assumes that certain symbols will be accessible without explicit inclusion via #include. However, it also provides a way to signal that explicit inclusion is necessary.
In my distribution, the conflictive files (machine.h and id3tag.c) have something like this:
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
This is the block you need to trigger, by setting the STDC_HEADERS preprocessor variable. The line above, with the -D flag, tells the C compiler to create it.
To fix bcopy issue, I added #include <strings.h> in machine.h and id3tag.h.
To fix index issue, I ended up commenting out the #define strchar index line in both machine.h and id3tag.c:
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#else
# ifndef HAVE_STRCHR
//# define strchr index
# define strrchr rindex
# endif
char *strchr(), *strrchr();
# ifndef HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
# define memmove(d, s, n) bcopy ((s), (d), (n))
# endif
#endif
I have it in strings.h, but its a #define:
$ cd /opt/android-ndk-r10d
$ grep -R bcopy * | grep x86_64
platforms/android-21/arch-x86_64/usr/include/linux/mroute6.h:#define IF_COPY(f, t) bcopy(f, t, sizeof(*(f)))
platforms/android-21/arch-x86_64/usr/include/strings.h:#define bcopy(b1, b2, len) \
platforms/android-21/arch-x86_64/usr/include/strings.h:#define bcopy(b1, b2, len) (void)(__builtin_memmove((b2), (b1), (len)))
Here's what it looks like (taken from the header strings.h):
#if defined(__BIONIC_FORTIFY)
# define bcopy(b1, b2, len) \
(void)(__builtin___memmove_chk((b2), (b1), (len), __bos0(b2)))
# define bzero(b, len) \
(void)(__builtin___memset_chk((b), '\0', (len), __bos0(b)))
#else
# define bcopy(b1, b2, len) (void)(__builtin_memmove((b2), (b1), (len)))
# define bzero(b, len) (void)(__builtin_memset((b), '\0', (len)))
#endif
Earlier version of the Android runtime provided it as a library call. See, for example, How to understand this code snippet in the bcopy.c of bionic?.
It sounds like its another case of the headers changing at android-21. That is, its a function that used to present as an export in a library, but now available in a headers. See, for example, Cannot load library: reloc_library[1285]: cannot locate 'rand'.
I think the workaround is to re-compile the Lame sound library with android-21, and not an earlier version of the toolchain.
Also, there are various config.h that have the following comment:
/* HAS_BCOPY:
* This symbol is defined if the bcopy() routine is available to
* copy blocks of memory.
*/
#define HAS_BCOPY /**/
You can find the config.h at, for example, android-ndk-r10d/prebuilt/darwin-x86_64/lib/perl5/5.16.2/darwin-2level/CORE/config.h.
If its not something obvious (like you already are compiling under android-21 and arch is correct), then we'll need to see how your project is setup (like what does Application.mk look like, or what --sysroot is being used).

No qsort_r for Android (or how to disable force Thumb to use CLZ in Android ARM code)

What I want to do (high-level): use qsort_r on Android.
There is no default implementation. So I've grabbed one from BSD. Unfortunately it needs fls functions which is also unavailable on Android. So I've grabbed Apple Open Source Libc library and copied ARM implementation into an inline assembly. Now I'm getting this:
Assembler messages:
Error: selected processor does not support Thumb mode `clz r3,r0'
Error: cannot honor width suffix -- `rsb r0,r3,#32'
AFAIR ARM-6 doesn't support it in Thumb mode. So how can I force non-Thumb mode for this one file, or is pure C implementation available for fls?
(and God, why do I have to play such low-level just to have qsort_r...)
In your Android.mk file, here is how to set things up to compile thumb, arm and neon versions of your code. The assembly language source files need to have the "S" capitalized in the makefile, but the actual name doesn't need to be capitalized. The suffixes ".arm" and ".arm.neon" are only in the makefile and not part of the name (e.g. the files below are named main.c, main_asm.s, test.c and test_asm.s).
LOCAL_ARM_MODE := arm # remove this if you want thumb mode
LOCAL_ARM_NEON := true # remove this if you want armv5 mode
# this flag will allow neon intrinsics in your C files
LOCAL_CFLAGS := -mfpu=neon -march=armv7
LOCAL_SRC_FILES := \
main.c.arm \
test.c.arm.neon \
main_asm.S.arm \
test_asm.S.arm.neon \

Build OpenJPEG for Android

I have a question.
What would I do I use the OpenJPEG on Android?
(I'm "j2k_to_image" is primarily want to use.)
I would like you to tell me how do I write a makefile.
Thanks in advance.
I was able to build + use OpenJPEG to load JPEG2000 images into my app using the following outline. You'll have to customize it according to your environment and how you want to utilize it. My answer provides rough guidelines along with specific answers to the major stumbling blocks I encountered (what my Android.mk and Application.mk files should be, as well as how to deal with the fact that the OpenJPEG library requires cmake).
Since we're talking OpenJPEG, this answer assumes you are familiar with and plan to use the Android NDK for your app. It also assumes you are using the Eclipse version of the Android IDE. The answer also assumes you are familiar with how static libraries work with the Android NDK and how to reference them into your main app. You can extend my answer below to create a shared library or to include the code directly into your app. If you are unfamiliar with these prerequisites, stackoverflow and Google can help.
I was successful with Android NDK r8e and OpenJPEG 2.0.0.
Steps:
Download and expand OpenJPEG 2.0.0 from http://www.openjpeg.org/index.php?menu=download
Create a native project in Eclipse. I created a project that allows me to utilize OpenJPEG as a static library
Within the jni folder of my project, I utilized the following for my Application.mk and my Android.mk files. See below.
Create a custom opj_config.h. OpenJPEG is meant to be compiled with cmake. I didn't want to deal with it for a number of reasons -- none of my other content relies on it (so it would add another layer of complexity), I'm on Windows (which doesn't have it built-in, and this stackoverflow post references android-cmake, the docs for android-cmake indicate that it may not work on Windows). See below for my opj_config.h. It should work for you. Make sure you put it somewhere in your include paths.
Build the Android NDK static library project
Reference your static library into your main project
With that, I was able to successfully load a JPEG2000 image into my Android NDK-based app.
Application.mk:
APP_ABI := all
APP_PLATFORM := android-9
APP_MODULES := openjpeg
Android.mk (you will have to customize all of the paths below):
# Taken from https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile
# The trailing slash is required.
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
ALL_CPPS := $(call rwildcard,../../openjpeg-2.0.0/src/lib/openjp2,*.c)
ALL_CPPS += $(call rwildcard,../../openjpeg-2.0.0/src/lib/openjpip,*.c)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := openjpeg
LOCAL_C_INCLUDES := /path/to/openjpeg-2.0.0/src/lib/openjp2
LOCAL_SRC_FILES := $(addprefix ../,$(ALL_CPPS))
LOCAL_CFLAGS = -DUSE_JPIP
include $(BUILD_STATIC_LIBRARY)
opj_config.h (normally cmake creates this for the platform you're building for -- but as I mention above, I didn't want to deal with cmake, so I hand-created this file):
#ifndef OPJ_CONFIG_H
#define OPJ_CONFIG_H
#define OPJ_PACKAGE_VERSION "2.0.0"
#define HAVE_INTTYPES_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STDINT_H 1
#ifndef HAVE_STDLIB_H // I had a conflict with this somewhere else in my project -- good form dictates that I should probably ifndef guard the other defines in this file as well....that is a TODO for later
#define HAVE_STDLIB_H 1
#endif
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1
// I'm not utilizing libpng or libtiff, so don't set these
//#cmakedefine HAVE_LIBPNG #HAVE_LIBPNG#
//#cmakedefine HAVE_PNG_H #HAVE_PNG_H#
//#cmakedefine HAVE_LIBTIFF #HAVE_LIBTIFF#
//#cmakedefine HAVE_TIFF_H #HAVE_TIFF_H#
#define HAVE_SSIZE_T 1
//#cmakedefine _LARGEFILE_SOURCE
//#cmakedefine _LARGE_FILES
//#cmakedefine _FILE_OFFSET_BITS #_FILE_OFFSET_BITS#
#define HAVE_FSEEKO 1
//#cmakedefine HAVE_LIBLCMS1
//#cmakedefine HAVE_LIBLCMS2
//#cmakedefine HAVE_LCMS1_H
//#cmakedefine HAVE_LCMS2_H
#endif // OPJ_CONFIG_H

Build Android-openssl library for platform 2.1

I am using open-ssl source given at https://github.com/eighthave/openssl-android
to build a library which can be used in android project.
As per instructions given at README.txt, I am able to compile it for the the Android platform version 2.2 (level -8)
But my app requires it to be 2.1 (level -7) compatible.
I tried following options with the default.properties file ( https://github.com/eighthave/openssl-android/blob/master/default.properties )
1) set target=android-7
2) set target=android-5
But when I compile it using command ndk-build, it gives following error
Compile thumb : crypto <= dsa_vrf.c
Compile thumb : crypto <= dso_dl.c
Compile thumb : crypto <= dso_dlfcn.c
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c: In function 'dlfcn_pathbyaddr':
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: 'Dl_info' undeclared (first use in this function)
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: (Each undeclared identifier is reported only once
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: for each function it appears in.)
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: expected ';' before 'dli'
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:455: error: 'dli' undeclared (first use in this function)
make: *** [obj/local/armeabi/objs/crypto/dso/dso_dlfcn.o] Error 1
As per error message- Dl_info is not defined. but if we go to file dso_dlfcn.c , the definition for the structure is already provided. (https://github.com/eighthave/openssl-android/blob/master/crypto/dso/dso_dlfcn.c)
And this code compiled for target=android-8 in default properties file, but not for android-7 or android-5.
Request you to help me to resolve this error. and let me know what all changes needs to be done in order to compile it for android 2.1 platform.
Thanks in advance.
Try to include the following piece of code into dso_dlfcn.c:
typedef struct {
const char *dli_fname; /* Pathname of shared object that
contains address */
void *dli_fbase; /* Address at which shared object
is loaded */
const char *dli_sname; /* Name of nearest symbol with address
lower than addr */
void *dli_saddr; /* Exact address of symbol named
in dli_sname */
} Dl_info;
int dladdr(const void *addr, Dl_info *info) { return 0; }
Before:
#ifdef __linux
# ifndef _GNU_SOURCE
# define _GNU_SOURCE /* make sure dladdr is declared */
# endif
#endif
After that in my case the library is built.
Try to install with latest NDK version and update Application.mk file appropriately.
LOCAL_PATH := $(call my-dir)
APP_PLATFORM := android-19
NDK_TOOLCHAIN_VERSION := clang
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DANDROID
APP_PROJECT_PATH := $(shell pwd)
APP_BUILD_SCRIPT := $(LOCAL_PATH)/../Android.mk
The above 2 problems will be solved.
I had one issue with #Yuri's solution and had to improve it alittle. My APP_ABI is set to all in Application.mk. In my case it meant that among armeabi and armeabi-v7a I'm building also for x86 and mips. I have also android-9 target installed in android sdk to use in other projects. x86 and mips are supported by ndk starting from android-9. As written in the docs, when ndk-build will start building these targets, it will switch to android-9 target automatically. And what? - Yes, it will fail to compile :-). Here is my solution:
In crypto/Android.mk find the line local_c_flags :=
-DNO_WINDOWS_BRAINDEATH. After the line write this http://pastebin.com/7euUVD7A.
Yuri's code has to be inserted into if defined: http://pastebin.com/V58gTSBU
By the way, I've inserted Yuri's block after #include <openssl/dso.h> but not before #ifdef __linux

Categories

Resources