howto use the libcurl by ndk standalone tool chainon on android - 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.

Related

PJSIP + FFMPEG build error

I'm trying to build PJSIP with FFMPEG for Android.
For building FFMPEG with rtmp and openssl, I use this project:
https://github.com/cine-io/android-ffmpeg-with-rtmp
and it compiles pretty well.
Then I'm compiling pjsip 2.6 with ffmpeg. Here is the part from my build file:
APP_PLATFORM=android-${TARGET_ANDROID_API} NDK_TOOLCHAIN_VERSION=4.9 TARGET_ABI=$arch ./configure-android --use-ndk-cflags \
--with-ssl="${OPENSSL_BUILD_OUT_PATH}/libs/${arch}" \
--with-ffmpeg="${BASE_DIR}/ffmpeg-output"
>>"${FINAL_BUILD_LOGS}/${arch}.log" 2>&1
My target ABI is armeabi.
Also, i've defined these two flags:
#define PJMEDIA_HAS_VIDEO 1
#define PJMEDIA_HAS_FFMPEG 1
But the build failed with a bunch of these two errors:
error: cannot find -lbz2
error: cannot find -lasound
A have libasound2-dev and bzip2 installed on my Ubuntu 16.04 LTS VM.
Before that, I've successfully made pjsip builds with OpenH264 with no errors like this.
Is there any way to tell linker(or whatever it is) how to find those packages?
Solve that problem (thx #NandhaKumar) by compiling .a libs for each library above and adding them to pjsip library path:
Build .a libs.
Copy libs to {PJPROJECT}/third_party/lib/ folder.
Go to the build.mak.in file in your PJSIP project folder.
Add the following lines:
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libbz2.a
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libasound.a
In my case (and I still don't know why) second line and defining another line
(APP_THIRD_PARTY_LIBS += -lsound or APP_THIRD_PARTY_LIBS += -lasound) doesn't help, so I just copied this library into the android_ndk folder:
android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9/libasound.a

"openssl/aes.h: No such file or directory" under 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.

How to compile telegram jni folder

I am trying to compile jni folder in telegram source code in github.com/DrKLO/Telegram/ with ndk
But when i am write ndk-build in cmd in ndk folder
like:
F:\ndk\android-ndk-r10>ndk-build -C F:\Workspace\Android\Telegram-master-1-12-2016\Telegram-master\TMessagesProj\jni
I get some error and libs folder not created
When i add ndk path to android studio and add jni folder manually android studio say can not find some header files
Following this question download Cygwin and use it, but again get this error like ndk-build
$ndkbuild
[armeabi] SharedLibrary : libtmessages.15.so
process_begin: CreateProcess(........,
F:/ndk/android-ndk-r10/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi
/thumb/libgnustl_static.a -lgcc -no-canonical-prefixes
-Wl,--no-undefined -Wl,-z ,noexecstack -Wl,-z,relro -Wl,-z,now
-LF:/ndk/android-ndk-r10/platforms/android-
9/arch-arm/usr/lib -ljnigraphics -llog -lz -ldl -lc -lm -o
F:/Workspace/Android/
Telegram-master-1-12-2016/Telegram-master/TMessagesProj//obj/local/armeabi/libtm
essages.15.so, ...) failed
make (e=87): The parameter is incorrect.
make.exe: *** [F:/Workspace/Android/Telegram-master-1-12-2016/Telegram-master/TMessagesProj//obj/local/armeabi/libtmessages.15.so] Error 87
How fix this?
Important update issue:
in 3.18 version, after downloading telegram source project, if you go to jni folder you will find and empty folder named libtgvoip, to fill it with needed files:
1- go to telegram source from githum, goto jni folder and click on libtgvoip # eb813e1 folder (# means that this is a refrence folder).
2- download that library too!
3- copy its content in empty folder discussed earlier!
Now lets begin:
Its very easy.
1- Add NDK directory to environment PATH variable.
2- open Android.mk and add the following line:
LOCAL_SHORT_COMMANDS := true
3- open Application.mk and add the following line:
APP_SHORT_COMMANDS := true
4- open command prompt as administrator and navigate to jni folder like this:
(important: in last version of telegram you should navigate to jni parent folder instead of jni folder)
5- just execute ndk-build command
Then ndk will start building .so files:
wait until it finish the task, maybe some warnings displayed but not important. finally you will have all shared library (.so files) in the obj directory:
(important: in last version of telegram .so files will create in lib folder and everything is ready to build)
then goto each of these folders and delete everything except libtmessages.22.so.
create a libs folder and copy that three directory into it:
Build and have fun! (remember to fill out variables in org.telegram.messenger.BuildVars class with your app id and app_hash. read more here)
Just remove the object file.
This error most likely appeared after the previous build was interrupted and object file was not generated completely.
Download the android-ndk Then go to the Project directory (./TMessagesProj) and execute ndk-build.
Then re-run the gradle build which packages the native libs into the apk.

How can I link cpufeatures lib for a native android library?

I'm trying to link android's cpu_features to a native library.
I'm using android's gcc compiler directly as a cross compiler. (NOT ndk-build).
I've included the header ($NDK_PATH/sources/android/cpufeatures/cpu-features.h), but i don't see a prebuilt libcpufeatures.a file anywhere under the ndk folder.
How can I build that library? Or where can it be found so i can link it properly?
You can just include the source file cpu-features.c in your project, or build it manually with gcc:
arm-linux-androideabi-gcc -c cpu-features.c -o cpu-features.o --sysroot=$SYSROOT
arm-linux-androideabi-ar rcs libcpufeatures.a cpu-features.o
It shouldn't require any special compiler flags or extra defines, but when linking to it, you may need to add -ldl since it uses dlopen.

Android NDK doesn't support header files?

This page has instuctions for compiling iwlist and other commands for Android:
https://code.google.com/p/haggle/wiki/WirelessTools
Unfortunately I'm getting the same type of error as the commenter on that page:
Android NDK: WARNING: Unsupported source file extensions in /home/simon/Android-SDK/wireless_tools.29/Android.mk for module iwlist Android NDK: iwlib.h
When I remove the iwlib.h from the LOCAL_SRC_FILES of the Android.mk, it doesn't show that warning, but it still fails with the same error:
./iwlist.c:633:7: error: 'IW_EV_LCP_PK2_LEN' undeclared (first use in this function)
This is undeclared because it is in the iwlib.h file it's warning about.
So why does the Android NDK not recognize header .h files?
To build the libraries, you unpacked the gz file, and ran make, didn't you? Or you simply renamed wireless.22.h? Anyways, before you runndk-build, you have a wireless.h file in the package directory. Add the following two lines to the end of this file:
#undef IW_EV_LCP_PK_LEN
#undef IW_EV_POINT_PK_LEN
And remove the iwlib.h from the LOCAL_SRC_FILES of the Android.mk. #Gabe is right, header files should not be compiled separately. In iwlist.c you will find line 14:
#include "iwlib.h"
You normally don't compile header files. You include them in a .c or .cpp file that you do compile. But you wouldn't pass them into the compiler as a source file.

Categories

Resources