tdlib / td

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

CMake Error: Could NOT find JNI #2345

Closed Ioakeimis closed 1 year ago

Ioakeimis commented 1 year ago

I am following the steps on the TDLib build instructions generator for Java on Apple Sillicon. when I enter the command:

sudo cmake -DCMAKE_BUILD_TYPE=Release -DJAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home/ -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl/ -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td -DTD_ENABLE_JNI=ON ..

I get the following message:

-- Could NOT find ccache (this is NOT an error) -- Found OpenSSL: /opt/homebrew/opt/openssl/include /opt/homebrew/opt/openssl/lib/libssl.dylib;/opt/homebrew/opt/openssl/lib/libcrypto.dylib -- Git state: 70bee089d492437ce931aa78446d89af3da182fc -- Found ZLIB: /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/lib/libz.tbd

Followed by the following error message:

CMake Error at /opt/homebrew/Cellar/cmake/3.25.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT) Call Stack (most recent call first): /opt/homebrew/Cellar/cmake/3.25.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /opt/homebrew/Cellar/cmake/3.25.3/share/cmake/Modules/FindJNI.cmake:562 (find_package_handle_standard_args) CMakeLists.txt:862 (find_package)

Any help would be appreciated. Thanks!

levlam commented 1 year ago

Did you follow https://tdlib.github.io/td/build.html?language=Java?

JDK should be isntalled by the command brew install openjdk.

Ioakeimis commented 1 year ago

Hello, yes I did and it installed me the following version:

19.0.2 (arm64) "Homebrew" - "OpenJDK 19.0.2" /opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home

And I also set it as my JAVA_HOME PATH using:

export JAVA_HOME=/opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home

Then I thought maybe the latest OpenJDK Version no longer includes JNI so I additionally installed Java Version 8 using homebrew:

1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

and then I set this one as my JAVA_HOME PATH and tried again and unfortunately yet again without success. The same error as in the beginning. :(

levlam commented 1 year ago

Homebrew tries to make things harder and harder all the time. Change -DJAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home/ to -DJAVA_HOME=/opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home in the following build instructions.

Ioakeimis commented 1 year ago

So I tried your suggestion. I typed the following command:

sudo cmake -DCMAKE_BUILD_TYPE=Release -DJAVA_HOME=/opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home/ -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl/ -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td -DTD_ENABLE_JNI=ON ..

And it basically gives me the exact same error :(

I understand your message and now I am also super confused. Because I realised Homebrew changed the path where it saves OpenJDK. And as far as I understand we do not need to set the JAVA HOME PATH because we pass it as an argument when we make the call. So now I really do not understand why it won't find JNI

Ioakeimis commented 1 year ago

I believe the following information can be useful. This was the message displayed on The terminal at the end of installing OpenJDK:

For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /opt/homebrew, because macOS provides similar software and installing this software in parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set: export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"

However, I did execute these commands so I do not know what is really happening anymore

levlam commented 1 year ago

Try to delete the build folder and recreate it with

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DJAVA_HOME=/opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home/ -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl/ -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td -DTD_ENABLE_JNI=ON ..

Also, don't use sudo. It must not be needed, unless something is very wrong with access rights already.

Ioakeimis commented 1 year ago

Perfect! It worked like a charm! Thanks :D

husanov98 commented 1 year ago

CMake Error at /usr/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT)
Call Stack (most recent call first):
/usr/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.26/Modules/FindJNI.cmake:569 (find_package_handle_standard_args)
CMakeLists.txt:923 (find_package) . I got this error. I think it likes your problems. But they aren't fully the same. Therefore if you have any idea . Please share it with me!

levlam commented 1 year ago

@husanov98 It is exactly the same error, just from a different CMake version.