Skip to content
This repository has been archived by the owner on Aug 22, 2021. It is now read-only.

Can't find class [org/drinkless/tdlib/Client] #56

Open
theapache64 opened this issue Apr 5, 2020 · 9 comments
Open

Can't find class [org/drinkless/tdlib/Client] #56

theapache64 opened this issue Apr 5, 2020 · 9 comments

Comments

@theapache64
Copy link

theapache64 commented Apr 5, 2020

I've added the depency

implementation "dev.whyoleg.ktd:ktd-api-coroutines-jvm:0.5.0-1.5.4"

I've libtdjni.so in my /usr/local/bin. So I've passed -Djava.library.path=/usr/local/bin to VM options (IntelliJ IDEA Run Configuration)

But when I try to create TelegramClient, am getting below error

Try to load tdlib as library
FATAL ERROR in native method: Can't find class [org/drinkless/tdlib/Client]
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1946)
	- locked <0x00000007825868b8> (a java.util.Vector)
	- locked <0x00000007825dc1c8> (a java.util.Vector)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1861)
	at java.lang.Runtime.loadLibrary0(Runtime.java:871)
	at java.lang.System.loadLibrary(System.java:1124)
	at dev.whyoleg.ktd.LinkKt.loadTdlib(Link.kt:8)
	at dev.whyoleg.ktd.TelegramRawClient.<clinit>(TelegramRawClient.kt:8)
	at dev.whyoleg.ktd.NativeClient.<init>(NativeClient.kt:8)
	at dev.whyoleg.ktd.Telegram.client(Telegram.kt:11)
	at MainKt.main(Main.kt:13)
[ 1][t 0][1586099161.561222076][tl_jni_object.cpp:37]	Can't find class [org/drinkless/tdlib/Client]

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

@whyoleg
Copy link
Owner

whyoleg commented Apr 6, 2020

Hi
Lib already contains prebuilt libtdjni.so inside Jar
In current version, exists bug that first it tries to load it using System.loadLibrary here is the logic for it
It was needed to support Android target
In new version, which is currently in development, it was already fixed. So in you case, you can just remove libtdjni.so from /usr/local/bin. Then it will be automatically extracted from Jar

@theapache64
Copy link
Author

I've removed libtdjni.so and treid below code

@ExperimentalTime
fun main(args: Array<String>) {
    val telegram = Telegram(
        configuration = TelegramClientConfiguration(
            maxEventsCount = 1000,
            receiveTimeout = 1.seconds //ms
        )
    )
    val client = telegram.client()
}

But am getting below error

Try to load tdlib as library
Try to load tdlib from artifact
java.lang.UnsatisfiedLinkError: no tdjni in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1871)
	at java.lang.Runtime.loadLibrary0(Runtime.java:871)
	at java.lang.System.loadLibrary(System.java:1124)
	at dev.whyoleg.ktd.LinkKt.loadTdlib(Link.kt:8)
	at dev.whyoleg.ktd.TelegramRawClient.<clinit>(TelegramRawClient.kt:8)
	at dev.whyoleg.ktd.NativeClient.<init>(NativeClient.kt:8)
	at dev.whyoleg.ktd.Telegram.client(Telegram.kt:11)
	at Main2Kt.main(Main2.kt:14)
java.lang.UnsatisfiedLinkError: /tmp/libtdjni5596519461042064073.so: /usr/local/lib/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by /tmp/libtdjni5596519461042064073.so)
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1946)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1828)
	at java.lang.Runtime.load0(Runtime.java:810)
	at java.lang.System.load(System.java:1088)
	at dev.whyoleg.ktd.LinkKt.loadTdlib(Link.kt:22)
	at dev.whyoleg.ktd.TelegramRawClient.<clinit>(TelegramRawClient.kt:8)
	at dev.whyoleg.ktd.NativeClient.<init>(NativeClient.kt:8)
	at dev.whyoleg.ktd.Telegram.client(Telegram.kt:11)
	at Main2Kt.main(Main2.kt:14)
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /home/theapache64/Documents/projects/ktd-test/libs/linux/libtdjni.so
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1831)
	at java.lang.Runtime.load0(Runtime.java:810)
	at java.lang.System.load(System.java:1088)
	at dev.whyoleg.ktd.LinkKt.loadTdlib(Link.kt:27)
	at dev.whyoleg.ktd.TelegramRawClient.<clinit>(TelegramRawClient.kt:8)
	at dev.whyoleg.ktd.NativeClient.<init>(NativeClient.kt:8)
	at dev.whyoleg.ktd.Telegram.client(Telegram.kt:11)
	at Main2Kt.main(Main2.kt:14)
Try to load tdlib from local path: /home/theapache64/Documents/projects/ktd-test/libs/linux/libtdjni.so
Can't load tdlib

NOTE: I am using Ubuntu 16.04

@whyoleg
Copy link
Owner

whyoleg commented Apr 6, 2020

tdlib for linux was prebuilt using github actions, on ubuntu 18.04, OPENSSL version there is 1.1.1d-1+ubuntu18.04
So I think you need to update OPENSSL
even 16.04 is LTS, new LTS will come soon (20.04) so I think I will not support old OPENSSL version

@theapache64
Copy link
Author

Okay. I didn't know it was built using Ubuntu 18.04. You found it so fast ⏩ 👍 😄 Good job

@whyoleg
Copy link
Owner

whyoleg commented Apr 6, 2020

I will add info about build environment and versions of dependencies during the next release phase. Thx that you found it!

@rndev-io
Copy link

I have similar exception. I try to run example on OSX. Build TDLib with this instruction (v1.6.0), move dynamic library to project's root.

Traceback
FATAL ERROR in native method: Can't find class [org/drinkless/tdlib/Client]
	at java.lang.ClassLoader$NativeLibrary.load0([email protected]/Native Method)
	at java.lang.ClassLoader$NativeLibrary.load([email protected]/ClassLoader.java:2452)
	at java.lang.ClassLoader$NativeLibrary.loadLibrary([email protected]/ClassLoader.java:2508)
	- locked <0x000000070ff02160> (a java.util.HashSet)
	at java.lang.ClassLoader.loadLibrary0([email protected]/ClassLoader.java:2704)
	at java.lang.ClassLoader.loadLibrary([email protected]/ClassLoader.java:2637)
	at java.lang.Runtime.load0([email protected]/Runtime.java:745)
	at java.lang.System.load([email protected]/System.java:1871)
	at dev.whyoleg.ktd.LinkKt.loadTdlib(Link.kt:27)
	at dev.whyoleg.ktd.TelegramRawClient.<clinit>(TelegramRawClient.kt:8)
	at dev.whyoleg.ktd.TelegramClient$Companion.exec(TelegramClient.kt:13)
	at dev.whyoleg.ktd.api.sync.SetLogVerbosityLevelKt.execute(SetLogVerbosityLevel.kt:38)
	at dev.whyoleg.ktd.api.sync.SetLogVerbosityLevelKt.setLogVerbosityLevel(SetLogVerbosityLevel.kt:25)
	at MainKt.main(Main.kt:10)
	at MainKt$$$main.invoke(Unknown Source)
	at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:199)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:114)
	at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19)
	at MainKt.main(Main.kt)

@whyoleg
Copy link
Owner

whyoleg commented Jun 29, 2020

@rusnasonov So, the exception is expected... Because that lib uses custom pre-built tdlib with different package names, and in next release it will even change a lot...
So for now, you need to build tdlib using cli module inside project, or I can create jar for you, if needed. In next release it will be just a jar published in github releases, so it will be much easier.
For now: you need to checkout master of ktd and 1.6.0 tag(or any other commit) of tdlib submodule and then in cli/src/main/kotlin/dev/whyoleg/ktd/cli/App.kt change main method to

fun main(args: Array<String>) {
    parser().parse("tdlib -p jvm -t mac".cmd())
}

It will build tdlib, which then can be used with lib as you want

@whyoleg
Copy link
Owner

whyoleg commented Jun 29, 2020

For now I will reopen that issue, and before next release document that and provide links to CLI and how to use it

@whyoleg whyoleg reopened this Jun 29, 2020
@slavaatsig
Copy link

@whyoleg I have tried your approach on macOS Catalina 10.15.7 but getting this error:

HEAD is now at b7928e64 try to fix build
JniConfig(cmakePath=cmake, td=TdConfig(buildType=MinSizeRel, tdPath=td, jniPath=tdlib/jni), linux=LinuxJniConfig(llvmPath=/usr/bin, clangPath=/usr/bin/clang-6.0, clangPlusPlusPath=/usr/bin/clang++-6.0), macos=MacosJniConfig(opensslPath=/usr/local/opt/openssl), windows=WindowsJniConfig(gperfPath=gperf, vcpkgPath=vcpkg), android=AndroidJniConfig(ndkPath=/usr/local/lib/android/sdk/ndk-bundle, opensslPath=openssl, apiLevel=21, jdkPath=/usr/lib/jvm/java-11-openjdk-amd64))
Prepare build folders
Build dir:           /Users/JohnDoe/IdeaProjects/ktd/td/build
Cross compile dir:   /Users/JohnDoe/IdeaProjects/ktd/tdlib/jni/bin
Generated dir:       /Users/JohnDoe/IdeaProjects/ktd/tdlib/jni
Generated build dir: /Users/JohnDoe/IdeaProjects/ktd/tdlib/jni/build
Install dir:         /Users/JohnDoe/IdeaProjects/ktd/tdlib/jni/td
Lib dir:             /Users/JohnDoe/IdeaProjects/ktd/tdlib/jni/bin
cmake -GNinja -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DTD_ENABLE_JNI=ON -DCMAKE_INSTALL_PREFIX:PATH=/Users/JohnDoe/IdeaProjects/ktd/tdlib/jni/td ..
CMake Error at CMakeLists.txt:3 (project):
Running
-- Configuring incomplete, errors occurred!
'ninja' '--version'
See also "/Users/JohnDoe/IdeaProjects/ktd/td/build/CMakeFiles/CMakeOutput.log".
failed with:
No such file or directory
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
Execution time: 37.0ms

And inside td/td/build/CMakeFiles/CMakeOutput.log there is only one line saying: The system is: Darwin - 19.6.0 - x86_64

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

No branches or pull requests

4 participants