"openssl/aes.h: No such file or directory" under Android - android

I'm trying to compile to android environment. And because of that I get the following error:
error: openssl/aes.h: No such file or directory
I find some solution in stack but, I don't get how to end the process to be able to compile.
I already compiled one version of openssl were should I add the libs? or how can I generate the *.a?
Do you know how can I add this library to the arm-linux-androideabi-g++ that I need to run to be able to pass this problem?

[1] Get openssl library which has aes.h file in its include folder.
[2] If you have compiled openssl library in your lib folder then add to -lssl or -lopenssl to your command line.

Here you can find openssl includes: openssl
Download this includes and put them in some folder in your project, i.e. project_dir/module_dir/jni/openssl-includes.
Then you need set a LOCAL_C_INCLUDES variable in your Android.mk (which also is in jni folder:
LOCAL_C_INCLUDES += ./openssl-includes
After that, you can include files in openssl-includes folder directly by name, i.e.:
#include <aes.h>
If you need an *.a file as output, you should include BUILD_STATIC_LIBRARY in Android.mk, if you need a *.so lib, include BUILD_SHARED_LIBRARY.

Related

howto use the libcurl by ndk standalone tool chainon on android

now, i have a question: first of all i already get the ndk standalone tool chain ---arm-linux-androideabi-g++ sucessful; now i have to write a commandline c++ program which will use libcurl to do http requests, i can successful compile it on my mac( which has the libcurl default? ) use g++, but when i use the arm-linux-androideabi-g++ to compile it, it produce following error:
arm-linux-androideabi-g++ -std=c++11 -lcurl upload.cpp -o upload
upload.cpp:12:23: fatal error: curl/curl.h: no such file or directory
compilation terminated
i have a libcurl(include files and .a lib file) which can used in android, so howto configure the arm-linux-androideabi-g++ so that it can compile it successfully? thanks advance
I guess you include your header like
#include <curl/curl.h>
if you do that, arm-linux-androideabi-g++ searches header file in some specific location. and if arm-linux-androideabi-g++ does not point same directory with g++, headers can not be found. try to copy just header files of curl to your project, jni/curl folder, and use " instead of <
#include "curl/curl.h"
if you have right .a file, functions in header files will be pointed to lib file successfully.

Android NDK: build after added a new library module directly under jni/ folder

In my Android NDK project, I used to have only one library module:
jni/
Android.mk
... (more source files)
Then, I need to add another new library module, which has no connection with the existing library module. I mean they are independent. I directly added the new library under jni/ folder.
jni/
Android.mk
... (more source files)
new-lib/
Android.mk
... (more source files)
Question 1:
I run ndk-build command under my Android project to build. But new-lib is not built at all. Is that because I need to declare the new-lib module in the Android.mk under jni/ folder ? If so, how to declare ?
Question 2: when I load the new-lib (suppose the module name is "newlib"), should I use
System.loadLibrary("new-lib/newlib");
or just
System.loadLibrary("newlib"); ?
First of all, you don't run android-ndk command, you run ndk-build command.
Question 1:
You can tell your top level Android.mk i.e. $PROJECT/jni/Android.mk to include another Android.mk that are located in different places/sub-directories.
If you have defined any Android.mk files in sub-directories, you have to include them explicitly in your top-level Android.mk. There is a helper function for that
include $(call all-subdir-makefiles)
Just add it in your top-level Android.mk file. This will include all the Android.mk files from sub-directories of the current file's path.
Question 2:
use System.loadLibrary("newlib");
No need to specify path.

fluidsynth library file compilation to .so file in android

I am trying to compile the files from https://bitbucket.org/kunstmusik/fluidsynth-android to .so file. The files from this site are .c and .h which have the include files. I have installed ndk, configured it.
I have created a new project in eclipse
created the jni folder and copied the files from the web site to this folder
in command prompt in the jni folder, I issued the command ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk. This ran without error
In the /obj/local/ folder, files were created with .o and .d in the fluidsynth-andriod folder. There is also a .a file in armeabi and aremabi-v7a. I assume the .a is a static library. Do I need to create a .so file? Do i need to link the c/c++ to java. If so how do I do this.
Please help...
I was running into this same issue myself. The Android.mk file included in the fluidsynth-android code contains the line
include $(BUILD_STATIC_LIBRARY)
This is what causes the .a files to be generated.
If you change this to
include $(BUILD_SHARED_LIBRARY)
you will get .so files instead of .a files.

Android NDK refer to external libraries in JNI

I have written C++ file in JNI folder of my application. I am using Windows system with NDK and Cygwin 1.7.I want reffer to CURL library available in Cygwin.How can we refer to external .h(libraries/header) files while creating JNI application in Android?I have created a combined Android and C++ project. But I am referring CURL header file. When I build the project I am getting fatal error: curl/curl.h: No such file or directory issue.
Follow these steps:
Converting from Android project to C/C++ project:
Right click on your project name, go to 'Android Tools' and click 'Add native support'
Adding paths to external .h files:
Right click on your project name, go to 'Properties', under 'C/C++ General', go to 'Paths and Symbols', under 'Includes' tab, add the folder in which your .h file is. Remember to add to all languages and configurations if asked.
Also, since you are in Windows, I think you will need to change your Build command (which is in the 'C/C++ Build' section in project properties) to "bash C:\Development\android-ndk-r8\ndk-build.cmd"
Add the following to your Android.mk:
LOCAL_CFLAGS += -I$/PATH/TO/YOUR/curl.h
LOCAL_LDLIBS += -L$/PATH/TO/YOUR/libcurl.a.for.android -lcurl
The libcurl.a you have installed in cygwin is not usable for android, you need a version targetting android. If you don't have it, build it yourself.
When you get that libcurl.a file, do not forget to copy the headers folder of curl (get into your usr/include/curl from Cygwin) and add this folder to the JNI one in your project, so it knows the headers while compiling.
Which means also referring in your Android.mk :
for the libcurl library
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/curl
and for your C++ files
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/curl
LOCAL_WHOLE_STATIC_LIBRARIES := libcurl
Please used this tutorial is nice one.
Don't forgot to change this setting after convert project to C / C ++ native project.
Builder Settings to Build Command
bash C:\tools\android-ndk-r8b-windows\android-ndk-r8b\ndk-build
This is my path of NDK you can change this path accordingly your NDK path.

Unable to build external OpenSSL library for Android NDK on Windows/Cygwin

I need to build the latest OpenSSL (1.0.0g) for an Android application. I am trying to follow the example given by https://github.com/fries/android-external-openssl, but I just can't get it built.
I am running Windows 7 Professional (64-bit) with a complete and recent Cygwin. I have installed the Android SDK and NDK, and I can successfully build and run the NDK's hello-jni sample application.
I created a new sample NDK app called hello-openssl. In its jni directory, I created an openssl directory. There, I unzipped https://github.com/fries/android-external-openssl/zipball/master, which gave me this tree structure under c:\android\android-ndk\samples\hello-openssl:
jni
+- openssl
+- apps
+- crypto
+- include
+- openssl
+- ssl
I then modified the Android.mk file in the jni directory in an attempt to include the OpenSSL files:
subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
openssl \
))
include $(subdirs)
Now when I execute ndk-build, it compiles several .c files, but then quickly fails:
Compile thumb : crypto <= cryptlib.c
In file included from jni/openssl/crypto/cryptlib.c:117:
jni/openssl/crypto/cryptlib.h:65:18: error: e_os.h: No such file or directory
jni/openssl/crypto/cryptlib.h:72:28: error: openssl/crypto.h: No such file or directory
I found http://osdir.com/ml/android-ndk/2010-07/msg00424.html, which tells me to "add
jni and jni/include to the above LOCAL_C_INCLUDES" in crypto/Android.mk, but I can't figure out the syntax I should use to achieve this.
I also can't figure out of I have the correct directory structure.
I sincerely appreciate any help that can be offered.
Thanks!
I solved this problem by abandoning https://github.com/fries/android-external-openssl and instead using https://github.com/guardianproject/openssl-android.
It is based on a more recent OpenSSL (1.0.0a), and it builds in the NDK without any modifications.
Note that in order to use these libraries in an Android app, you must rename them. If you simply include the resulting libssl.so and libcrypto.so in your app, then call System.LoadLibrary ("crypto") and System.LoadLibrary ("ssl"), you will get the OpenSSL libraries included in the Android system, not your custom libraries.
To do this, just do a full-word search and replace ("libssl" -> "libsslx", and "libcrypto" -> "libcryptox") in each Android.mk (i.e, in /crypto, /ssl, and /apps).
Then in your Android app, call SystemLoadLibrary ("cryptox") and System.LoadLibrary ("sslx")

Categories

Resources