Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build .so file for android? #77

Closed
mrH3ktor opened this issue Feb 13, 2018 · 151 comments
Closed

How to build .so file for android? #77

mrH3ktor opened this issue Feb 13, 2018 · 151 comments

Comments

@mrH3ktor
Copy link

i'm on Mac and could not found a way to build .so file for android. any solution?

@levlam
Copy link
Contributor

levlam commented Feb 13, 2018

You can use our Java example to build the library for Android yourself. It could be used almost without modifications. You can also download prebuilt Android library available at http://core.telegram.org/tdlib/tdlib.zip.

@mrH3ktor
Copy link
Author

I follow the instruction but it's not generate .so file. i want to know how to get .so file from this library like the prebuilt Android library at http://core.telegram.org/tdlib/tdlib.zip.
i try on ubuntu and get libtdjni.so but it's size is about 18mb.

@levlam
Copy link
Contributor

levlam commented Feb 14, 2018

What instructions you have followed?

@mrH3ktor
Copy link
Author

this one example/java

@levlam
Copy link
Contributor

levlam commented Feb 16, 2018

To build TDLib for Android you need to use Android NDK. You can use JNI bindings from Java example, but CMakeLists.txt should be adopted to build everything using NDK.

@mrH3ktor
Copy link
Author

can you give me a instruction to how to do it?

@levlam
Copy link
Contributor

levlam commented Feb 17, 2018

We will publish example project later.

@andreiswsoft
Copy link

I tried to use prebuilt Android library available at http://core.telegram.org/tdlib/tdlib.zip, but for some reason I always received error: "File "/td.binlog" can't be opened/created for reading and writing"
Could you please tell me what's the problem?

@levlam
Copy link
Contributor

levlam commented Mar 7, 2018

You haven't specified databaseDirectory available for writing in setTdlibPatameters.

@isopen
Copy link
Contributor

isopen commented Mar 13, 2018

Lion, I got to this meat. Which compilation flags will you recommend? (in files Android.mk, Application.mk)

../android-sdk/ndk-bundle# ./ndk-build NDK_PROJECT_PATH=testproj
../android-sdk/ndk-bundle/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): mips64 armeabi mips    
../android-sdk/ndk-bundle/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.    
[arm64-v8a] Compile++      : tdjni <= td_json_client.cpp
[arm64-v8a] SharedLibrary  : libtdjni.so
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `ClientJson':
../prog/android-sdk/ndk-bundle/testproj/jni/td/telegram/ClientJson.h:24: undefined reference to `td::Client::Client()'
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `~ClientJson':
../prog/android-sdk/ndk-bundle/testproj/jni/td/telegram/ClientJson.h:24: undefined reference to `td::Client::~Client()'
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `Slice':
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::verbosity_level'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::verbosity_level'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::log_interface'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::log_interface'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::Logger::Logger(td::LogInterface&, int, td::Slice, int, td::Slice, bool)'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::Logger::~Logger()'
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `td_json_client_send':
../prog/android-sdk/ndk-bundle/testproj/jni/td/telegram/td_json_client.cpp:26: undefined reference to `td::ClientJson::send(td::Slice)'
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `td_json_client_receive':
../prog/android-sdk/ndk-bundle/testproj/jni/td/telegram/td_json_client.cpp:30: undefined reference to `td::ClientJson::receive(double)'
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `Slice':
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::verbosity_level'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::verbosity_level'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::log_interface'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::log_interface'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::Logger::Logger(td::LogInterface&, int, td::Slice, int, td::Slice, bool)'
../prog/android-sdk/ndk-bundle/testproj/jni/td/utils/Slice.h:142: undefined reference to `td::Logger::~Logger()'
testproj/obj/local/arm64-v8a/objs/tdjni/td/telegram/td_json_client.o: In function `td_json_client_execute':
../prog/android-sdk/ndk-bundle/testproj/jni/td/telegram/td_json_client.cpp:39: undefined reference to `td::ClientJson::execute(td::Slice)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [testproj/obj/local/arm64-v8a/libtdjni.so] Error 1

@levlam
Copy link
Contributor

levlam commented Mar 13, 2018

We recommend to use CMake for Android builds, which automatically will manage all dependencies.

@isopen
Copy link
Contributor

isopen commented Mar 13, 2018

Lion
It seems to me that it remains to understand why one does not see in one namespace
../prog/android-sdk/ndk-bundle/testproj/jni/td/telegram/ClientJson.h:24: undefined reference to `td::Client::Client()'
I can be mistaken, but if you know how to correct, then tell me :)

td_json_client_create() - managed to collect
the rest is not yet clear

@levlam
Copy link
Contributor

levlam commented Mar 13, 2018

You need to link against tdclient, tdutils and other libraries.

@isopen
Copy link
Contributor

isopen commented Mar 14, 2018

Good. Yesterday I came to this.
tdtl was successful
I continue to dance with a tambourine

@isopen
Copy link
Contributor

isopen commented Mar 14, 2018

cmake(ndk) log

jnibuild# /home/user/prog/Android/Sdk/cmake/3.6.4111459/bin/cmake -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/home/user/prog/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=23 -DANDROID_TOOLCHAIN=gcc -DOPENSSL_INCLUDE_DIR=/home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/user/proj/tdlib/td/jnibuild/ ..
-- The CXX compiler identification is GNU 4.9.0
-- The C compiler identification is GNU 4.9.0
-- Check for working CXX compiler: /home/user/prog/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
-- Check for working CXX compiler: /home/user/prog/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /home/user/prog/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
-- Check for working C compiler: /home/user/prog/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found ccache
-- Found OpenSSL: /home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libssl.so;/home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libcrypto.so  
-- Found OpenSSL: /home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a /home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libssl.so;/home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libcrypto.so
-- Performing Test HAVE_STD14
-- Performing Test HAVE_STD14 - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 - Failed
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH - Success
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE - Success
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES - Failed
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND - Failed
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO - Failed
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP - Success
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE - Failed
-- Performing Test HAVE_CXX_FLAG_WVLA
-- Performing Test HAVE_CXX_FLAG_WVLA - Success
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER - Success
-- Performing Test HAVE_CXX_FLAG_WCONVERSION
-- Performing Test HAVE_CXX_FLAG_WCONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC - Failed
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS - Failed
-- Performing Test HAVE_CXX_FLAG_WODR
-- Performing Test HAVE_CXX_FLAG_WODR - Failed
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING - Failed
-- Found ZLIB: /home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libz.so (found version "1.2.3") 
-- Found ZLIB: /home/user/prog/Android/Sdk/ndk-bundle/sysroot/usr/include /home/user/prog/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libz.so
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/prog/td/jnibuild

It's time to rejoice. But it's too early.

/home/user/prog/Android/Sdk/cmake/3.6.4111459/bin/cmake --build .
Scanning dependencies of target git_commit
[  0%] Generate git_commit.h
[  0%] Built target git_commit
Scanning dependencies of target tdutils
[  1%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/Fd.cpp.o
[  1%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/FileFd.cpp.o
[  1%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/IPAddress.cpp.o
[  2%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/path.cpp.o
[  2%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/ServerSocketFd.cpp.o
[  3%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/signals.cpp.o
[  3%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/sleep.cpp.o
[  4%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/SocketFd.cpp.o
[  4%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/Stat.cpp.o
[  4%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/thread_local.cpp.o
[  5%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/wstring_convert.cpp.o
[  5%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/Epoll.cpp.o
[  6%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/EventFdBsd.cpp.o
[  6%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/EventFdLinux.cpp.o
[  7%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/EventFdWindows.cpp.o
[  7%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/KQueue.cpp.o
[  8%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/Poll.cpp.o
[  8%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/Select.cpp.o
[  8%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/ThreadIdGuard.cpp.o
[  9%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/port/detail/WineventPoll.cpp.o
make[2]: *** Нет правила для сборки цели «../tdutils/generate/auto/mime_type_to_extension.cpp», требуемой для «tdutils/CMakeFiles/tdutils.dir/generate/auto/mime_type_to_extension.cpp.o».  Останов.
CMakeFiles/Makefile2:473: ошибка выполнения рецепта для цели «tdutils/CMakeFiles/tdutils.dir/all»
make[1]: *** [tdutils/CMakeFiles/tdutils.dir/all] Ошибка 2
Makefile:138: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2

gperf and readline? :)

@levlam
Copy link
Contributor

levlam commented Mar 14, 2018

@isopen you need to run native build first with

cmake --build . --target prepare_cross_compiling

to generate some source files.

@isopen
Copy link
Contributor

isopen commented Mar 14, 2018

@levlam Many thanks. Now there is no error.

jnibuild# /home/user/prog/android-sdk/cmake/3.6.4111459/bin/cmake -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/home/user/prog/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=23 -DANDROID_TOOLCHAIN=gcc -DOPENSSL_ROOT_DIR=/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/ -DOPENSSL_INCLUDE_DIR=/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/include/ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/user/proj/td/jnibuild/ -DANDROID=ON ..
-- The CXX compiler identification is GNU 4.9.0
-- The C compiler identification is GNU 4.9.0
-- Check for working CXX compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
-- Check for working CXX compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
-- Check for working C compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found ccache
-- Found OpenSSL: /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libssl.so;/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libcrypto.so (found version "1.0.0a") 
-- Found OpenSSL: /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/include /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libssl.so;/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libcrypto.so
-- Performing Test HAVE_STD14
-- Performing Test HAVE_STD14 - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 - Failed
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH - Success
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE - Success
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES - Failed
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND - Failed
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO - Failed
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP - Success
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE - Failed
-- Performing Test HAVE_CXX_FLAG_WVLA
-- Performing Test HAVE_CXX_FLAG_WVLA - Success
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER - Success
-- Performing Test HAVE_CXX_FLAG_WCONVERSION
-- Performing Test HAVE_CXX_FLAG_WCONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC - Failed
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS - Failed
-- Performing Test HAVE_CXX_FLAG_WODR
-- Performing Test HAVE_CXX_FLAG_WODR - Failed
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING - Failed
-- Found ZLIB: /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libz.so (found version "1.2.3") 
-- Found ZLIB: /home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libz.so
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/prog/td/jnibuild
jnibuild# cmake --build . --target prepare_cross_compiling
make: *** Нет правила для сборки цели «prepare_cross_compiling».  Останов.
(If this is done after the usual `cmake ..` then everything is fine)
jnibuild# /home/user/prog/Android/Sdk/cmake/3.6.4111459/bin/cmake --build .
[ 15%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/JsonBuilder.cpp.o
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:431:10: warning: multi-character character constant [-Wmultichar]
     case '16':
          ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:434:74: warning: multi-character character constant [-Wmultichar]
           [](char c) { return c == '-' || ('0' <= c && c <= '9') || c == '16' || c == 'e' || c == 'E' || c == '+' || c == '.'; });
                                                                          ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:541:10: warning: multi-character character constant [-Wmultichar]
     case '16':
          ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:544:74: warning: multi-character character constant [-Wmultichar]
           [](char c) { return c == '-' || ('0' <= c && c <= '9') || c == '16' || c == 'e' || c == 'E' || c == '+' || c == '.'; });
                                                                          ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp: In function 'td::Result<td::JsonValue> td::do_json_decode(td::Parser&, td::int32)':
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:431:10: warning: case label value exceeds maximum value for type
     case '16':
          ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp: In lambda function:
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:434:71: warning: comparison is always false due to limited range of data type [-Wtype-limits]
           [](char c) { return c == '-' || ('0' <= c && c <= '9') || c == '16' || c == 'e' || c == 'E' || c == '+' || c == '.'; });
                                                                       ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp: In function 'td::Status td::do_json_skip(td::Parser&, td::int32)':
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:541:10: warning: case label value exceeds maximum value for type
     case '16':
          ^
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp: In lambda function:
/home/user/prog/td/tdutils/td/utils/JsonBuilder.cpp:544:71: warning: comparison is always false due to limited range of data type [-Wtype-limits]
           [](char c) { return c == '-' || ('0' <= c && c <= '9') || c == '16' || c == 'e' || c == 'E' || c == '+' || c == '.'; });
                                                                       ^
[ 15%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/logging.cpp.o
/home/user/prog/td/tdutils/td/utils/logging.cpp:44:29: error: td::Logger::__emutls_t._ZN2td6Logger4tag_E causes a section type conflict with td::Logger::tag_
 TD_THREAD_LOCAL const char *Logger::tag_ = nullptr;
                             ^
/home/user/prog/td/tdutils/td/utils/logging.cpp:44:29: note: 'td::Logger::tag_' was declared here
/home/user/prog/td/tdutils/td/utils/logging.cpp:45:29: error: td::Logger::__emutls_t._ZN2td6Logger5tag2_E causes a section type conflict with td::Logger::tag2_
 TD_THREAD_LOCAL const char *Logger::tag2_ = nullptr;
                             ^
/home/user/prog/td/tdutils/td/utils/logging.cpp:45:29: note: 'td::Logger::tag2_' was declared here
tdutils/CMakeFiles/tdutils.dir/build.make:878: ошибка выполнения рецепта для цели «tdutils/CMakeFiles/tdutils.dir/td/utils/logging.cpp.o»
make[2]: *** [tdutils/CMakeFiles/tdutils.dir/td/utils/logging.cpp.o] Ошибка 1
CMakeFiles/Makefile2:473: ошибка выполнения рецепта для цели «tdutils/CMakeFiles/tdutils.dir/all»
make[1]: *** [tdutils/CMakeFiles/tdutils.dir/all] Ошибка 2
Makefile:138: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2

Warning can be ignored for example with the flag -Wno-multichar. But it is not yet clear how to avoid fatal errors. How?

Changed to Clang. This place has passed without error. Warnings are the same.
-DANDROID_TOOLCHAIN=clang

[ 18%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/StringBuilder.cpp.o
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:22:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%d", x);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:30:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%u", x);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:38:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%ld", x);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:46:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%lu", x);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:54:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%lld", x);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:62:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%llu", x);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:95:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%p", ptr);
                  ^~~~~~~~~~~~~
                  snprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:252:5: note: 'snprintf' declared here
int snprintf(char* __buf, size_t __size, const char* __fmt, ...)
    ^
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:106:13: error: no member named 'vsnprintf' in namespace 'std'; did you mean simply 'vsnprintf'?
  int len = std::vsnprintf(current_ptr_, left, fmt, list);
            ^~~~~~~~~~~~~~
            vsnprintf
/home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include/stdio.h:256:5: note: 'vsnprintf' declared here
int vsnprintf(char* __buf, size_t __size, const char* __fmt, va_list __args)
    ^
8 errors generated.
tdutils/CMakeFiles/tdutils.dir/build.make:1022: ошибка выполнения рецепта для цели «tdutils/CMakeFiles/tdutils.dir/td/utils/StringBuilder.cpp.o»
make[2]: *** [tdutils/CMakeFiles/tdutils.dir/td/utils/StringBuilder.cpp.o] Ошибка 1
CMakeFiles/Makefile2:473: ошибка выполнения рецепта для цели «tdutils/CMakeFiles/tdutils.dir/all»
make[1]: *** [tdutils/CMakeFiles/tdutils.dir/all] Ошибка 2
Makefile:138: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2

Fixed StringBuilder.cpp for the current build (delete std) TODO:: there meat.
Build...33%

[ 58%] Building CXX object CMakeFiles/tdcore.dir/td/telegram/MessagesManager.cpp.o
/home/user/prog/td/td/telegram/MessagesManager.cpp:15708:100: warning: lambda capture 'file_id' is not used [-Wunused-lambda-capture]
      PromiseCreator::lambda([this, dialog_id, secret_input_media = std::move(secret_input_media), file_id,
                                                                                                   ^
/home/user/prog/td/td/telegram/MessagesManager.cpp:15709:31: warning: lambda capture 'thumbnail_file_id' is not used [-Wunused-lambda-capture]
                              thumbnail_file_id](Result<Message *> result) mutable {
[ 58%] Building CXX object CMakeFiles/tdcore.dir/td/telegram/misc.cpp.o
...
[ 71%] Building CXX object CMakeFiles/tdcore.dir/td/telegram/Td.cpp.o
...
/home/user/prog/td/tdutils/td/utils/crypto.cpp::250
error: undefined reference to 'AES_ige_encrypt'
/home/user/prog/td/tdutils/td/utils/logging.cpp::[149, 152, 155, 158, 161]
error: undefined reference to '__android_log_write'
While it is not clear what is this stuff. I commented the lines. Continued build...
...
[100%] Built target all_tests

Did not appear libtdjson.so(joke). Perhaps it's warnings and errors in the assembly.
Especially the last full meat :) Perhaps it is in openssl...

libtdjson.so(weight 150mb) appeared in the /home/user/proj/td/jnibuild/
But I'm not sure about this meat ...

@levlam
Copy link
Contributor

levlam commented Mar 14, 2018

Something wrong with yours TDLib source code. There is no c == '16' on this line:

[](char c) { return c == '-' || ('0' <= c && c <= '9') || c == 'e' || c == 'E' || c == '+' || c == '.'; });

as there is no line

case '16':

For Android it is better to use ANDROID_STL=c++_static additionally to ANDROID_TOOLCHAIN=clang.

@isopen
Copy link
Contributor

isopen commented Mar 14, 2018

Yes '16' is just not a critical warning(it does not apply to your code). I'm sorry my girlfriend added this. I'll try to explain to her about the type char.

i try -DANDROID_STL=c++_static
Maybe there will not be this

[ 18%] Building CXX object tdutils/CMakeFiles/tdutils.dir/td/utils/StringBuilder.cpp.o
/home/user/prog/td/tdutils/td/utils/StringBuilder.cpp:22:19: error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?
  current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%d", x);
...

This is not very critical.:))

That's what I'm interested:

  • Why does it output libtdjson.so instead of libtdjni.so?
    CMakeLists::if (TD_ENABLE_JNI AND NOT ANDROID) # jni is available by default on Android
    But there is no jni initialization.
    Are these lines not exactly needed?
Found JNI: /usr/lib/jvm/java-8-openjdk-amd64/lib  
Found JNI: /home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include;/usr/lib/jvm/java-8-openjdk-amd64/include;/usr/lib/jvm/java-8-openjdk-amd64/include /usr/lib/jvm/java-8-openjdk-amd64/lib;/usr/lib/jvm/java-8-openjdk-amd64/jre/lib
  • Why does the output file weigh ~^ 150 MB?
  • Did before this git clone td ...
/home/user/prog/td/td/telegram/MessagesManager.cpp:15708:100: warning: lambda capture 'file_id' is not used [-Wunused-lambda-capture]
      PromiseCreator::lambda([this, dialog_id, secret_input_media = std::move(secret_input_media), file_id,
                                                                                                   ^
/home/user/prog/td/td/telegram/MessagesManager.cpp:15709:31: warning: lambda capture 'thumbnail_file_id' is not used [-Wunused-lambda-capture]
                              thumbnail_file_id](Result<Message *> result) mutable {

@levlam
Copy link
Contributor

levlam commented Mar 14, 2018

  1. To use native Java bindings you need to use Td::TdStatic library compiled with TD_ENABLE_JNI and the wrapper exactly the same as in our Java example. You will need to additionally compile td_jni.cpp and link it with Td::TdStatic to obtain libtdjni.so.
  2. It is not stripped file. You need to strip them using strip from NDK.
  3. These warnings will be fixed.

@isopen
Copy link
Contributor

isopen commented Mar 15, 2018

Good.

(1) This is not about the current manual :)
CMakeLists.txt
It turns out that this condition is redundant(those. not always like this).
if (TD_ENABLE_JNI AND NOT ANDROID) # jni is available by default on Android

if (TD_ENABLE_JNI) 
  if (NOT JNI_FOUND)
    find_package(JNI REQUIRED)
  endif()
  message(STATUS "Found JNI: ${JNI_INCLUDE_DIRS} ${JNI_LIBRARIES}")
  target_include_directories(tdcore PUBLIC ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
  target_link_libraries(tdcore PUBLIC ${JAVA_JVM_LIBRARY})
endif()

@isopen
Copy link
Contributor

isopen commented Mar 15, 2018

/home/user/prog/android-sdk/cmake/3.6.4111459/bin/cmake -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/home/user/prog/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=23 -DANDROID_TOOLCHAIN=clang -DOPENSSL_ROOT_DIR=/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/ -DOPENSSL_INCLUDE_DIR=/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/include/ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/user/prog/td/jnibuild/ -DTD_ENABLE_JNI=ON -DJAVA_AWT_LIBRARY=/usr/lib/jvm/java-8-openjdk-i386/lib/i386/libawt.so -DJAVA_JVM_LIBRARY=/usr/lib/jvm/java-8-openjdk-i386/jre/lib/i386/server/libjvm.so -DJAVA_INCLUDE_PATH2=/usr/lib/jvm/java-8-openjdk-i386/include -DJAVA_AWT_INCLUDE_PATH=/usr/lib/jvm/java-8-openjdk-i386/include -DANDROID_STL=c++_static ..

-- Check for working CXX compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/user/prog/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found ccache
-- Found OpenSSL: /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libssl.so;/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libcrypto.so (found version "1.0.0a") 
-- Found OpenSSL: /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/include /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libssl.so;/home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/armeabi-v7a/libcrypto.so
-- Performing Test HAVE_STD14
-- Performing Test HAVE_STD14 - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 - Failed
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH - Success
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE - Success
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES - Failed
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND - Failed
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO - Failed
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP - Failed
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE - Success
-- Performing Test HAVE_CXX_FLAG_WVLA
-- Performing Test HAVE_CXX_FLAG_WVLA - Success
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER - Success
-- Performing Test HAVE_CXX_FLAG_WCONVERSION
-- Performing Test HAVE_CXX_FLAG_WCONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS - Success
-- Performing Test HAVE_CXX_FLAG_WODR
-- Performing Test HAVE_CXX_FLAG_WODR - Success
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING - Failed
-- Found ZLIB: /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libz.so (found version "1.2.3") 
-- Found ZLIB: /home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include /home/user/prog/android-sdk/ndk-bundle/platforms/android-23/arch-arm/usr/lib/libz.so
-- Found JNI: /usr/lib/jvm/java-8-openjdk-i386/lib/i386/libawt.so  
-- Found JNI: /home/user/prog/android-sdk/ndk-bundle/sysroot/usr/include;/usr/lib/jvm/java-8-openjdk-i386/include;/usr/lib/jvm/java-8-openjdk-i386/include /usr/lib/jvm/java-8-openjdk-i386/lib/i386/libawt.so;/usr/lib/jvm/java-8-openjdk-i386/jre/lib/i386/server/libjvm.so
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/prog/td/jnibuild

How cool everything goes!
...
Nezhdanchik...
[ 79%] Built target tdclient
Scanning dependencies of target tdjson_private
make[2]: *** Нет правила для сборки цели «../td/generate/auto/td/telegram/td_api_json.cpp», требуемой для «CMakeFiles/tdjson_private.dir/td/generate/auto/td/telegram/td_api_json.cpp.o».  Останов.
CMakeFiles/Makefile2:188: ошибка выполнения рецепта для цели «CMakeFiles/tdjson_private.dir/all»
make[1]: *** [CMakeFiles/tdjson_private.dir/all] Ошибка 2
Makefile:138: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2

This error occurs if you do
cmake --build . --target prepare_cross_compiling
before assembly.

[ 82%] Linking CXX shared library libtdjson.so
/home/user/prog/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /usr/lib/jvm/java-8-openjdk-i386/jre/lib/i386/server/libjvm.so: incompatible target
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/tdjson.dir/build.make:132: ошибка выполнения рецепта для цели «libtdjson.so»
make[2]: *** [libtdjson.so] Ошибка 1
CMakeFiles/Makefile2:232: ошибка выполнения рецепта для цели «CMakeFiles/tdjson.dir/all»
make[1]: *** [CMakeFiles/tdjson.dir/all] Ошибка 2
Makefile:138: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2

What to do?

@levlam
Copy link
Contributor

levlam commented Mar 15, 2018

"error: /usr/lib/jvm/java-8-openjdk-i386/jre/lib/i386/server/libjvm.so: incompatible target" is because you have removed check if (TD_ENABLE_JNI AND NOT ANDROID) # jni is available by default on Android and CMake has found wrong JNI libraries, instead of the correct one. To build for Android you should use CMake which is a part of Android NDK.

@isopen
Copy link
Contributor

isopen commented Mar 15, 2018

I'm using this CMake to build (It seems to be part of the NDK)
https://developer.android.com/ndk/guides/cmake.html
With this check does not see jni at all if (TD_ENABLE_JNI AND NOT ANDROID)
So I wrote down like this if (TD_ENABLE_JNI)
Next, I set the paths to jni (with great certainty that this jni would not work - It turned out to be true)
Please tell me where to get the right jni?

@levlam
Copy link
Contributor

levlam commented Mar 15, 2018

Correct JNI headers can be found inside Android NDK. I'm not sure that you need to link with JRE libraries on Android at all when JNI is used.

@isopen
Copy link
Contributor

isopen commented Mar 16, 2018

Can you drop the already prepared cmake(ndk) command with which you collected?

@levlam
Copy link
Contributor

levlam commented Mar 16, 2018

We built TDLib for Android inside Android Studio project. It is hard to drop the whole project, but we will be publish it in the future.

@isopen
Copy link
Contributor

isopen commented Mar 16, 2018

It's brilliant. Can you somehow pull out the build.gradle files?

@levlam
Copy link
Contributor

levlam commented Mar 16, 2018

build.gradle.txt

@levlam
Copy link
Contributor

levlam commented Jun 3, 2022

@TomyChu90 Ensure that you copied all java source files without changing their package.

@Tamada4a
Copy link

Does anyone know what the problem might be?

error: ./build.sh: 26: export: Files/Git/cmd:/mnt/c/Program: bad variable name

build.sh:
export ANDROID_NDK=/c/Android/Sdk/ndk
HOST_ARCH=windows-x86_64

PATH:
image

@levlam
Copy link
Contributor

levlam commented Jun 14, 2022

@Tamada4a
There is a space in $PATH, which is used in export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_ARCH/bin:$PATH, so you need to add quotes.

@Tamada4a
Copy link

Tamada4a commented Jun 14, 2022

@levlam
Slightly misunderstood. Add quotes where? My head doesn't think at all

Do you mean Program Files_(x86)?

@levlam
Copy link
Contributor

levlam commented Jun 14, 2022

export PATH="$ANDROID_NDK"/toolchains/llvm/prebuilt/$HOST_ARCH/bin:"$PATH"

@Tamada4a
Copy link

I fixed some problems, but now i have this one:

Configuring OpenSSL version 1.1.1g (0x1010107fL) for android-x86_64
Using os-specific seed configuration
no NDK x86_64-linux-android-gcc on $PATH at (eval 10) line 142.
Configuring OpenSSL version 1.1.1g (0x1010107fL) for android-arm
Using os-specific seed configuration
no NDK arm-linux-androideabi-gcc on $PATH at (eval 10) line 142.
Configuring OpenSSL version 1.1.1g (0x1010107fL) for android-x86
Using os-specific seed configuration
no NDK i686-linux-android-gcc on $PATH at (eval 10) line 142.
Configuring OpenSSL version 1.1.1g (0x1010107fL) for android-arm64
Using os-specific seed configuration
no NDK aarch64-linux-android-gcc on $PATH at (eval 10) line 142.

build.sh:
export ANDROID_NDK=/mnt/c/Users/volce/AppData/Local/Android/Sdk/ndk/24.0.8215888
HOST_ARCH=windows-x86_64

export PATH="$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_ARCH/bin:$PATH"

But on the path ANDROID_NDK there is a folder with ndk:
image

@levlam
Copy link
Contributor

levlam commented Jun 14, 2022

@Tamada4a The correct NDK path would be export ANDROID_NDK=/c/Android/Sdk/ndk/android-ndk-r22b.

@Tamada4a
Copy link

@levlam if I use the correct path, I get the following error:
image

@Tamada4a
Copy link

I fixed NDK path error. I downloaded openssl 1.1.1o and now
image

@feelgood4
Copy link

in new versions change td_api.tlo path in Cmake file, when build jni archive

@levlam
Copy link
Contributor

levlam commented Sep 14, 2022

Now you can use https://github.com/tdlib/td/tree/master/example/android to build libtdjni for Android.

@AndrewTran2018
Copy link

Now you can use https://github.com/tdlib/td/tree/master/example/android to build libtdjni for Android.

@levlam hi, I need to build libtdjsonandroid.so can you send me the script?

@AndrewTran2018
Copy link

Now you can use https://github.com/tdlib/td/tree/master/example/android to build libtdjni for Android.

@levlam hi, I need to build libtdjsonandroid.so can you send me the script?

@levlam I modify the current make file to build libtdjsonandroid, it looks ok now. Thanks.

@romausnul
Copy link

I have an idea. There will be a type of park that cannot be deleted. All posts will be randomly placed in this folder. I'll send you a ready-made pezultat soon. romausnul@gmail.com

Screenshot_20230522_204150_RM Me

@MorozovStVl
Copy link

Good evening! I'm building the TDLib library for Telegram. It will be used on Android. We assemble in Windows OS.

When running the command "./build-openssl.sh" an error occurs:

process_begin: CreateProcess(NULL, aarch64-linux-android21-clang -Iinclude -Iproviders/implementations/include -Iproviders/common/include -fPIC -pthread -Wa,--noexecstack -Qunused-arguments -Wall -O3 -ffunction-sections -fdata-sections -U__ANDROID_API__ -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -D__ANDROID_API__=21 -MMD -MF providers/legacy-dso-legacyprov.d.tmp -MT providers/legacy-

Please tell me how to fix it?

@levlam
Copy link
Contributor

levlam commented Feb 26, 2024

@MorozovStVl
Do you use https://github.com/tdlib/td/tree/master/example/android? If not, you need to switch to these build instructions. Despite the example works on all OS that are supported by Android NDK, it could be hard to install all build dependencies on Windows, so it can be simpler to use the provided Dockerfile.

@MorozovStVl
Copy link

I'm just using this example to build for Android.

Tell me, do the Dockerfile need to be launched by some program? Please guide me. I haven't encountered Dockerfile before

@levlam
Copy link
Contributor

levlam commented Feb 26, 2024

The README contains the exact command to be invoked:

Alternatively, you can use Docker to build TDLib for Android. Use `docker build --output tdlib .` to build the latest TDLib commit from Github, or `docker build --build-arg COMMIT_HASH=<commit-hash> --output tdlib .` to build specific commit. The output archives will be placed in the tdlib directory as specified.

You can download and install Docker at https://www.docker.com/products/docker-desktop/.

@RB105
Copy link

RB105 commented May 15, 2024

I prepared scripts which can be used to build all flavours of TDLib for Android. You will need Bash, cmake, ninja, C++14 compatible compiler, PHP (optional, for documentation generation), Android NDK and system JDK preinstalled. Make sure that ANDROID_SDK_ROOT environment variable is correctly set before using the scripts.

You can build desired TDLib version using: libtdjni.zip - native JNI wrapper for TDLib with autogenerated Java classes. libtdjsonandroid.zip - TDLib JSON interface built for Android. All TDLib JSON interface methods have ordinary names prefixed with undescore, for example _td_json_client_create. libtdjsonjava.zip - JNI wrapper for TDLib JSON interface.

You will need to unpack the desired archive to td/example directory. Then download the latest OpenSSL 1.1.1 source code as a .tar.gz archive from OpenSSL 1.1.1 release page and place it in the third_party/crypto subfolder. After that you need to adjust variables ANDROID_NDK and HOST_ARCH in third_party/crypto/build.sh and run third_party/crypto/build-all.sh script to build OpenSSL. After that run the script export.sh in the unpacked archive top-level directory to build TDLib.

I used libtdjsonandroid.zip for my android app, is that possible to built .so file for my app in Macos

@levlam
Copy link
Contributor

levlam commented May 15, 2024

@RB105
Copy link

RB105 commented May 15, 2024

@RB105 See https://tdlib.github.io/td/build.html.

I have problem with openssl always :
CMake Warning at CMakeLists.txt:185 (message):
Can't find OpenSSL: stop TDLib building

Ps: I did as instructions for libtdjsonandroid

@levlam
Copy link
Contributor

levlam commented May 15, 2024

If you want to build TDLib for macOS, you need to follow the instructions at https://tdlib.github.io/td/build.html. If you want to build TDLib for Android, then see https://github.com/tdlib/td/tree/master/example/android.

@levlam
Copy link
Contributor

levlam commented Jun 3, 2024

Now you can use the Android example to build TDLib for Android.

@levlam levlam closed this as completed Jun 3, 2024
@RB105
Copy link

RB105 commented Jun 3, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests