How to compile telegram jni folder - android

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.

Related

How to generate armeabi-v7a of libassimp.so.4.1.0 for Assimp

I am using Assimp source code to generate Android ARM binary. After CMake it provide me x86_64 libassimp.so every time.
I am using Assimp Source code 4.1.0 and compile it using following steps -
1. Set up android toolchain
export NDK_PATH=/path/to/your/android/ndk/
not go to android-ndk-r8c\build\tools
run the command:
sh make-standalone-toolchain.sh –platform=android-8 –ndk-dir=$NDK_PATH –install-dir=/Android/sdk/android-toolchain –toolchain=arm-linux-androideabi-4.4.3
which will build file scripts of the toolchain
now run the command
export ANDROID_NDK_TOOLCHAIN=$HOME/Android/sdk/android-toolchain
and also
export ANDTOOLCHAIN=$HOME/Android/android-cmake/toolchain/android.toolchain.cmake
to the path need to add :
export PATH=$PATH:$HOME/Android/sdk/tools
export PATH=$PATH:$HOME/Android/sdk/platform-tools
export PATH=$PATH:$HOME/Android/sdk/android-toolchain/bin
so lets begin, download the last source of assimp library from http://assimp.sourceforge.net and open terminal(cygwin or mac terminal) , go to assimp directory and type :
mkdir buildandroid
cd buildandroid
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN -DENABLE_BOOST_WORKAROUND=ON -DCMAKE_INSTALL_PREFIX=/assimp-2.0 -DANDROID_ABI=armeabi-v7a _DANDROID_NATIVE_API_LEVEL=android-8 -DANDROID_FORCE_ARM_BUILD=TRUE ..
this will create files and folders in the build directory, now go to the file link.txt inside : buildandroid => code => cMakeFiles => assimp.dir => link.txt
search for the string -soname, libassimp.so.3 and remove the .3 from the extension of the library (if not it will make problems in loading later from the android)
do the same thing with file name relink.txt
now go back to the root directory of buildandroid and run :
make
process of building will begin, the shared library will be in parent lib folder and wll consist from symbolic links and so library which will called libassimp.so.version_number. remove the version number makeing the file name only be libassimp.so
In the end, I am getting x86_64 libassimp.so instead armeabi-v7a. Please let me know if anybody now, how to generate armeabi-v7a libassimp.so. Any help will be appreciated.

"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 does one Android NDK library without a Android Project

I would like to be able to build a shared library in using the android ndk-build script, but for some reason I get a bunch of errors:
# I have Application.mk and Android.mk in the current folder
ndk-build -C .
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
Is there a way to build the Android shared library with only the source and header files?$$\int$$
Yes, you can write
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk
But it's much easier to create ./jni directory and put both Application.mk and Android.mk there.

Putting SO (shared object) file in android build path showing red exclamation mark on project

I have an SO file which is compiled with GCC compiler with command -
gcc -mandroid -c ret.c
Here is the link to the SO file.
Just put the .so file in your libs/armeabi/ subdirectory, and it should automatically be included as part of your build. Don’t mention it in LOCAL_SRC_FILES, as it’s not a source file.

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.

Categories

Resources