24

Unfortunally a similar question was removed at Stackoverflow some weeks ago, I must make a new question.

Im trying to build an own Telegram app for android via source @ https://github.com/DrKLO/Telegram

I can not get it to work, it stops on startup with the following error, any ideas on where to start, Im quite new to Android Studio.

11-17 19:55:04.142 2667-2667/org.telegram.messenger E/art: No implementation found for void org.telegram.tgnet.ConnectionsManager.native_setJava(boolean) (tried Java_org_telegram_tgnet_ConnectionsManager_native_1setJava and Java_org_telegram_tgnet_ConnectionsManager_native_1setJava__Z)
11-17 19:55:04.142 2667-2667/org.telegram.messenger D/AndroidRuntime: Shutting down VM
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime: FATAL EXCEPTION: main
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime: Process: org.telegram.messenger, PID: 2667
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime: java.lang.UnsatisfiedLinkError: No implementation found for void org.telegram.tgnet.ConnectionsManager.native_setJava(boolean) (tried Java_org_telegram_tgnet_ConnectionsManager_native_1setJava and Java_org_telegram_tgnet_ConnectionsManager_native_1setJava__Z)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at org.telegram.tgnet.ConnectionsManager.native_setJava(Native Method)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at org.telegram.messenger.ApplicationLoader.onCreate(ApplicationLoader.java:259)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.app.ActivityThread.-wrap1(ActivityThread.java)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-17 19:55:04.151 2667-2667/org.telegram.messenger E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
stavasknall
  • 381
  • 1
  • 2
  • 8

5 Answers5

21

The main problem is that you're running the project without generating the native library from the C/C++ codes. Because of that project based on Telegram, which you point it out with the link, has the file Android.mk on the jni directory , you have to compile the code manually. I fixed that exception following these steps:

  • Check that build.gradle contains:

source version 3.13.1 and newer:

sourceSets.main.jniLibs.srcDirs = ['./jni/']

source version lower than 3.13.1:

    sourceSets.main {
       jniLibs.srcDirs = 'libs'
       jni.srcDirs = [] //disable automatic ndk-build call
    }
  • Download the NDK

Proceed according to your operating system.

Linux / Mac

$ cd <path-to-Telegram>/TMessagesProj
$ <path-to-ndk>/ndk-build

Windows

  • Download Cygwin
  • Add on .bashrc file, which is placed on Cygwin root directory (use some utility to find that file). In my case, the file was placed in C:\cygwin64\home\myuser.

    export ndkbuild=/cygdrive/partition_name/your_ndk_directory/ndk-build.cmd
    
  • Open the Cygwin terminal and move yourself towards the jni directory of the project:

    cd /cygdrive/your_partition_name/project_jni_directory_path
    
  • Write $ndkbuild and wait the compiler finishes its task. If this process is right, two directories will show up, obj and libs. Check that libs directory contains some library with .so extension. Finally, run the project.

Siamak
  • 1,689
  • 1
  • 17
  • 26
Jesús Castro
  • 2,061
  • 1
  • 22
  • 26
  • Should we have to download both NDK and Cywing? – Sharath Dec 28 '15 at 14:07
  • @Sharath yes. Android SDK doesn't bring along NDK, so you should download it in order to compile the code C/C++. However, for windows, you should compile the code with an unix-like terminal, thus, Cywing is useful for this purpose. However, if you know another unix-like terminal for Windows, you can try it out. – Jesús Castro Dec 28 '15 at 19:18
  • 1
    Thanks! Can you tell me where should we add this?export ndkbuild=/cygdrive/partition_name/your_ndk_directory/ndk-build.cmd – Sharath Dec 29 '15 at 04:03
  • I get an error ndkbuild command not found.I have set the ndk path correctly even. – Sharath Dec 29 '15 at 05:14
  • @Sharath there is a file `.bashrc` in your Cwying directory, you should search it. In my case, it was C:\cygwin64\home\myuser\.bashrc, where `myuser` is your windows username. You can use F3 option or search tab for that. In my case, it was this [file](https://www.dropbox.com/s/nla755riw52h4sq/stack_cygwin_bashrc.png?dl=0) – Jesús Castro Dec 30 '15 at 16:34
  • Ya for me also its in the same folder. C:\cygwin64\home\myuser\.bashrc.Can you share the file?so that i can replace it? – Sharath Dec 31 '15 at 05:36
  • @Sharath It's no need, you simply copy that `export` line for the indicated file, replacing `partition_name` and `your_ndk_directory` for your case. e.g. `export ndkbuild=/cygdrive/c/android-ndk-r10e/ndk-build.cmd` – Jesús Castro Dec 31 '15 at 05:59
  • 1
    Ok.Where to add that line in .bashrc? – Sharath Dec 31 '15 at 06:00
  • 1
    @Sharath No matter, it may be the last line. Leftover content must be the same, thus, don't change anything different than that line. – Jesús Castro Dec 31 '15 at 06:16
  • I added the line in .bashrc,and i couldn't find in the PATH. – Sharath Dec 31 '15 at 06:35
  • I have followed the steps mentioned above but I got message as ndk build command not found. – Somasundaram NP Jan 06 '16 at 06:29
  • i have this error when i type ndkbuild. [armeabi] Compile++ arm : tmessages.19 <= NativeLoader.cpp In file included from C:/users/sajad/desktop/TelegramNew/TMessagesProj//jni/./NativeLoader.cpp:3:0: C:/users/sajad/desktop/TelegramNew/TMessagesProj//jni/./breakpad/client/linux/handler/exception_handler.h:36:26: fatal error: sys/ucontext.h: No such file or directory #include ^ compilation terminated. make.exe: *** [C:/../TelegramNew/TMessagesProj//obj/local/armeabi/objs/tmessages.19/./NativeLoader.o] Error 1 – sajad mohammadi Mar 16 '16 at 10:20
  • 1
    open terminal $ cd /TMessagesProj/jni $ /ndi-build – Bincy Baby May 24 '16 at 11:32
  • 1
    I tried to 'cd /TMessagesProj/jni' in linux but it gave me NO_SUCH_FILE error! then I tried to build ndk with root directory of TMessangerProj it Worked! So actually 'cd /TMessagesProj' is right answer . Error took about 3 days of mine and I hope others wont face it.. – Siamak Nov 23 '16 at 07:11
  • should we add libs path to build.gradle file? – masoud vali Nov 14 '17 at 10:28
5

As Jesús Castro mentioned, you have to compile native codes to libraries with .so suffix that android can use them for running app.

But why this is happened newly? Because in the last commit of DrKLO's Telegram repository they have removed the prebuilt libraries according to commit message in git:

Removing prebuilt libraries. The source code for all libraries is (and always was) available here: https://github.com/DrKLO/Telegram/tree/master/TMessagesProj/jni

You can find the commit here.

Navid Eivazzadeh
  • 337
  • 3
  • 13
2

So, to solve your issue, you can remove your 64-bit libs from your build, or set abiFilters to package only 32-bit architectures:

android {
....
defaultConfig {
    ....
    ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
    }
}

}

add android.useDeprecatedNdk=true to a file named gradle.properties at the root of your project

FeelCode
  • 491
  • 4
  • 5
0

@Rajsundar . If adding the line :

export ndkbuild=/cygdrive/c/android-ndk-r10e/ndk-build.cmd

is not working. After doing everything else you can simply run the command directly from the jni directory.

/cygdrive/c/android-ndk-r10e/ndk-build.cmd
0

I had a similar error message. The solution for me was to deinstall the app from the simulator, clean the project (including all libraries) and do a rebuild. Now the app starts fine.

testing
  • 19,681
  • 50
  • 236
  • 417
  • I still have an error: `JNI NewGlobalRef called with pending exception java.lang.NoSuchMethodError: no non-static method "Lcom/sipo/messenger/AnimatedFileDrawableStream;.read(II)I"` every time I launch the app (force closed). Where am I wrong? – Justinus Hermawan Sep 09 '19 at 15:17
  • Don't know, but reading your error message says that there could be a mismatch between `static` and `non-static` method declaration vs. call. Perhaps there was an error on compiling? – testing Sep 09 '19 at 16:07
  • Oh I found the mistake, it was on `proguard-rules.pro` where `-keep class org.telegram.** { *; }` and `-dontwarn org.telegram.**` still are `org.telegram`. – Justinus Hermawan Sep 10 '19 at 01:06