无法初始化Crashlytics NDK [英] Cannot initialize Crashlytics NDK

查看:189
本文介绍了无法初始化Crashlytics NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启动Android的Crashlytics时遇到问题。 Java部分正常工作,但是我无法使NDK部分工作,因为crashlytics_init()返回空值;

I got a problem in initalizing Crashlytics for Android. The Java part works correctly but i cannot make NDK part to work because crashlytics_init() return a null value;

我的project / build.gradle

My project/build.gradle

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'io.fabric.tools:gradle:1.24.4'
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google()

        maven {
            url 'https://maven.fabric.io/public'
        }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app / build.gradle包含

app/build.gradle containing

compileSdkVersion 26

android {

    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 22
        ...
    }

    ...
}

crashlytics {
    enableNdk true
    manifestPath 'C:\\full\\path\\to\\manifest\\AndroidManifest.xml'
}

dependencies {
    implementation 'com.google.firebase:firebase-crash:11.6.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true
    }
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
        transitive = true;
    }

    compile 'com.google.firebase:firebase-core:11.6.0'

    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'org.apache.commons:commons-compress:1.12'
    compile 'org.tukaani:xz:1.5'
}

主要活动代码

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    jniCrashlyticsInit();

    ...
}

以及jniCrashlyticsInit()

and the native content of jniCrashlyticsInit()

void Java_com_my_app_MainActivity_jniCrashlyticsInit(JNIEnv *env,
                                                     jobject thiz)
{
    crashlytics = crashlytics_init();

    if (crashlytics == NULL)
        log("CRASHLYTICS NULL");
    else
        log("CRASHLYTICS NON NULL");
}

如您所想,记录了 CRASHLYTICS NULL,它无法初始化所有东东。
我也将日志也放入了 crashlytics.h 内,它恰好在此行失败(返回空值)

As you imagine, "CRASHLYTICS NULL" is logged and it cannot initialize all the stuff. I've put logs also inside crashlytics.h and it happens to fail on this line (returning a null value)

__crashlytics_unspecified_t* ctx = ((__crashlytics_initialize_t) sym_ini)();

由于我没有更多的信息,所以我真的不知道该如何进行。
的想法?

Since i got no further infos, i really don't know how to proceed. Ideas?

更多信息:
我使用Android Studio 3.0.0,并使用以下命令手动编译NDK库

Some info more: I use Android studio 3.0.0, and the NDK libraries are compiled manually with the following command

/cygdrive/c/Android/ndk-r15c/ndk-build.cmd NDK_DEBUG=0 APP_BUILD_SCRIPT=./Android.mk NDK_PROJECT_PATH=. APP_PLATFORM=android-19    

**** 11月20日更新****

**** Update November 20th ****

按照Todd Burner的建议,在 build.gradle上,我从 compile 切换为 implementation 来自

As suggested by Todd Burner, I switched from "compile" to "implementation" on build.gradle from

compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
    transitive = true
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
    transitive = true;
}

implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
    transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
    transitive = true;
}

然后我跑了

./gradlew assemble --refresh-dependencies

不幸的是, crashlytics_init()仍返回NULL

Unfortunally, crashlytics_init() still returns NULL

推荐答案

同样的问题。就我而言,我会部分归咎于Fabric网站上不够完善的文档,部分归咎于缺乏阅读理解力。

I struggled days with this same issue. In my case I would blame partly the not-so-very-thorough documentation in the Fabric website and partly the lack of my reading comprehension.

我不确定您是否遇到同样的事情,但是我的问题是我尝试两次加载Crashlytics NDK。

I cannot be sure if you experience just the same thing, but my problem was that I tried to load Crashlytics NDK twice.

如果您是通过Java这样的初始化:

If you do the initialization from java like this:

Fabric.with(this, new Crashlytics(), new CrashlyticsNdk()); 

本机Crashlytics将自动加载,您无需从C ++初始化Crashlytics 。如果您从 CrashlyticsNdk.class 开始进入反编译的Crashlytics .class文件,您会看到 JniNativeApi.class 已经调用 System.loadLibrary( crashlytics)

the native Crashlytics is automatically loaded and you don't need to initialize Crashlytics from C++. If you step into the decompiled Crashlytics .class files starting from CrashlyticsNdk.class you can see that JniNativeApi.class already calls System.loadLibrary("crashlytics").

实际上,如果您仍然尝试从本机端初始化Crashlytics之后,

In fact, if you still try to initialize Crashlytics from native side after that, the line

__crashlytics_unspecified_t* ctx = ((__crashlytics_initialize_t) sym_ini)();

将返回NULL,因为该库已被加载。

will return NULL because the library has been already loaded.

让我感到困惑的是,官方面料文档没有不要用亮红色闪烁的字母说,如果您从Java调用 new CrashlyticsNdk(),则不应尝试从C ++加载本机Crashlytics。公平地说,文档确实会说明以下内容:在通过Fabric.with()进行初始化的过程中,NDK Kit使用System.loadLibrary加载libcrashlytics。但是,它仅在Native之前一行。 API说明开始,并且容易被忽略。

What confused me is that the Official Fabric documentation doesn't say with bright red flashing letters that if you call new CrashlyticsNdk() from Java, you shouldn't try to load native Crashlytics from C++. To be fair, the documentation does say the following: In the process of initialization via Fabric.with(), the NDK Kit uses System.loadLibrary to load libcrashlytics. But it's a single line right before the Native API explanation starts and is easily overlooked.

这篇关于无法初始化Crashlytics NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆