tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
6.95k stars 1.42k forks source link

How to build .so file for android? #77

Closed mrH3ktor closed 3 months ago

mrH3ktor commented 6 years ago

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

levlam commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

What instructions you have followed?

mrH3ktor commented 6 years ago

this one example/java

levlam commented 6 years ago

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 commented 6 years ago

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

levlam commented 6 years ago

We will publish example project later.

andreiswsoft commented 6 years ago

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 commented 6 years ago

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

isopen commented 6 years ago

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 commented 6 years ago

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

isopen commented 6 years ago

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 commented 6 years ago

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

isopen commented 6 years ago

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

isopen commented 6 years ago

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 commented 6 years ago

@isopen you need to run native build first with

cmake --build . --target prepare_cross_compiling

to generate some source files.

isopen commented 6 years ago

@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 commented 6 years ago

Something wrong with yours TDLib source code. There is no c == '16' on this line: https://github.com/tdlib/td/blob/6c706f45e7a73c936b9f2f267785092c8a73348f/tdutils/td/utils/JsonBuilder.cpp#L433 as there is no line

case '16':

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

isopen commented 6 years ago

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:

levlam commented 6 years ago
  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 commented 6 years ago

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 commented 6 years ago
/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 commented 6 years ago

"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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

levlam commented 6 years ago

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 commented 6 years ago

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

levlam commented 6 years ago

build.gradle.txt

isopen commented 6 years ago

Happened. The file is too large at the output.

image

jnibuild# /home/user/prog/android-sdk/cmake/3.6.4111459/bin/cmake -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -G Ninja -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 -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
-- 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# /home/user/prog/android-sdk/cmake/3.6.4111459/bin/cmake --build .
[167/242] 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 {
                              ^
2 warnings generated.
[242/242] Linking CXX shared library libtdjni.so
levlam commented 6 years ago

For Android builds it is better to use MinSizeRel instead of Release.

You need to strip the file to reduce its size. Between, it will be automatically stripped before deploying to a device.

isopen commented 6 years ago

Thanks @levlam. Everything worked out.

As a material for thought: If you collect through android-27 and found version openssl 1.0.2j for android then the assembly will hang here

MessagesManager.cpp:15709:31: warning: lambda capture 'thumbnail_file_id' is not used [-Wunused-lambda-capture]
                              thumbnail_file_id](Result<Message *> result) mutable {
                              ^
2 warnings generated.
[240/242] Linking CXX shared library libtdjson.so

In fact, the files are already created and can be used. This is likely already on the side of android, but it still needs to be checked. It's worth waiting for some assembly is completed.

Instructions for those who have fun with openssl for android http://doc.qt.io/qt-5/opensslsupport.html dos2unix to convert the Setenv-android.sh file to Unix format

hnvn commented 6 years ago

@isopen , Can you show the hierarchy of your project directory and the CMakeList.txt? I am trying to build Tdlib for my own project, and I just have little of knowledge about Cmake and NDK. :(

isopen commented 6 years ago

Download NDK and CMake for NDK. You can do this using android studio or upload via console.

Assemble openssl and load into the appropriate folder NDK.

The hierarchy of the project has not changed much https://github.com/tdlib/td/issues/77#issuecomment-373172529 You must use the current project java. It shows an example of building the required library. You can also take from it all the necessary links for CMakeList.txt (If possible read about Boost in CMake)

Example of an assembly command /home/user/prog/android-sdk/cmake/3.6.4111459/bin/cmake -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -G Ninja -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 -DANDROID_STL=c++_static ..

Perhaps you will come across a lot of other plot events during the assembly process. Which will need to be addressed.

Let's wait for the solution of professionals.

hnvn commented 6 years ago

It's nice of you to respond promptly. I'll give it a try.

aaugmentum commented 5 years ago

@levlam, Can u give some hint or guide how to build TdJson lib for Android as I'm going to integrate it to a flutter project via platform channels. I want to use json interface on both iOS and Android, so I can write the same logic for both on flutter side.

levlam commented 5 years ago

@aaugmentum You will need two things:

  1. Write JNI wrappers for 5 methods from TDLib JSON interface. It should be easy.
  2. Build TDLib, including OpenSSL, and the JNI wrapper using Androind NDK. This is mostly covered by https://developer.android.com/studio/projects/configure-cmake and answers in this issue, but can take a lot of time if you have never done this before.
levlam commented 5 years ago

@aaugmentum This is, for example, the JNI wrapper: tdjsonjava.zip.

levlam commented 5 years ago

@aaugmentum Could you try these prebuilt libs: tdlib.zip. They are supposed to contain TDLib 1.4.0 with implementation of org.drinkless.tdlib.JsonClient from the previous comment and provide TDLib's JSON interface for Android.

isopen commented 5 years ago

https://github.com/tdlib/td/issues/77#issuecomment-376562359

It definitely worked. Next, from the archive of Leo, you can copy the interface in Java.

There are androidx imports. You may have to transfer the project to it.

The most important thing is to openssl competently assemble.

aaugmentum commented 5 years ago

@aaugmentum Could you try these prebuilt libs: tdlib.zip. They are supposed to contain TDLib 1.4.0 with implementation of org.drinkless.tdlib.JsonClient from the previous comment and provide TDLib's JSON interface for Android.

Yeah, it worked! Thank you very much :) image_2

The only problem was in library name in JsonClient.java. tdjsonjava is the right name.

static {
        try {
            System.loadLibrary("tdjsonjava");
        } catch (UnsatisfiedLinkError e) {
            e.printStackTrace();
        }
}
kikemascote commented 5 years ago

how the funk do I add the prebuilt tdlib for android to a project? just can't find any how still can't setup a working copy of tdlib or telegram official cllient

i-Naji commented 4 years ago

@aaugmentum Could you try these prebuilt libs: tdlib.zip. They are supposed to contain TDLib 1.4.0 with implementation of org.drinkless.tdlib.JsonClient from the previous comment and provide TDLib's JSON interface for Android.

There are any prebuilt libs for TDLib 1.5.0?

isopen commented 4 years ago

1.5 is deprecated. Need a newer version 1.6

levlam commented 4 years ago

@i-Naji Here is built for Android libtdjsonjava 1.5.1 (API compatible with 1.5.0): tdlib.zip.

whyoleg commented 4 years ago

Also, for building android lib you can look here ktd It's in code, but if you run it, it will also println command executed I've used that build of openssl

whyoleg commented 4 years ago

But also I have a question to @levlam I've build lib and strip it with ndk, but the size of lib is almost 2 times bigger, than prebuilt, that you provided? What more I can do it improve lib size?

levlam commented 4 years ago

@whyoleg Here are the CMakeLists.txt files I use to build TDLib for Android: libtdjsonjava and JNI.

The key part is likely to be

string(APPEND CMAKE_CXX_FLAGS " -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--gc-sections -Wl,--exclude-libs,ALL")
whyoleg commented 4 years ago

@levlam Thx! Will check in several hours

whyoleg commented 4 years ago

@levlam Big thx! It's work, cool, size even less, then in prebuilt version :)