cs guy
cs guy

Reputation: 939

C++ Crashlytics NDK crashes when used with header

I followed all the steps listed here: crashlytics NDK Android

I copy pasted this file into my project: crashlytics.h

I am calling it with the following:

#include "Crashlytics.h"
    
void NDKCrashlytics::logToCrashlytics(char *result) {
    firebase::crashlytics::Initialize();
    firebase::crashlytics::Log(result);
}

As soon as I call the method my app crashes and this is the log I get:

E/AndroidRuntime(20818): FATAL EXCEPTION: Thread-10 E/AndroidRuntime(20818): Process: com.insync.loopad, PID: 20818 E/AndroidRuntime(20818): java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.crashlytics.FirebaseCrashlytics" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/lib64]] E/AndroidRuntime(20818): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196) E/AndroidRuntime(20818): at java.lang.ClassLoader.loadClass(ClassLoader.java:379) E/AndroidRuntime(20818): at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 2 (greylist, linking, allowed) D/libcrashlytics(20818): Initializing libcrashlytics version 3.0.0

I also saw this issue here but it is not solved. What am I doing wrong?

Upvotes: 0

Views: 452

Answers (1)

Boris
Boris

Reputation: 206

On C++ side (replace com_xxx_lib with your package id):

#include "Crashlytics.h"
extern "C"
{
    JNIEXPORT void JNICALL
    Java_com_xxx_lib_MyNativeActivity_jniCrashlyticsInit(JNIEnv * env ) {
        firebase::crashlytics::Initialize();
    }
}
void CrashlyticsLog(char const *msg)
{
    firebase::crashlytics::Log(msg);
}

On Java side: call jniCrashlyticsInit() in onCreate() in your NativeActivity

public class MyNativeActivity extends NativeActivity
{
    static {
        System.loadLibrary("XXX");//your c++ library
    }
    public native void jniCrashlyticsInit();

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        jniCrashlyticsInit();
    }
}

After that you can use firebase::crashlytics::Log(msg) in your C++ code.

Upvotes: 1

Related Questions