Fabric and Crashlytics not working with Bazel build

三世轮回 提交于 2019-12-11 09:08:57

问题


I'am building an android app which uses fabric-crashlytics for logging all the crashes in devices. This particular line of code:

    Crashlytics crashlyticsKit = new Crashlytics.Builder()
            .core(new CrashlyticsCore.Builder().disabled(false).build())
            .build();
    Fabric.with(this, crashlyticsKit);

is crashing with Bazel, but, when I set this value to "true"..(i.e., I'am disabling Crashlytics ), this application's Bazel build is working fine. But, If I'am building a normal android app it's not crashing weather the value is "true" or "false". But, in Bazel the build is completely crashing on start. The error is:

2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     |  | 
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     |  |
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     |  |
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .   \ |  | /
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .    \    /
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     \  /
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .      \/
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
    install an Android build tool and ask a team member to invite you to this app's organization.
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .      /\
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     /  \
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .    /    \
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .   / |  | \
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     |  |
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .     |  |
2019-01-11 15:55:55.808 19850-19850/com.sensennetworks.senanpr E/CrashlyticsCore: .
2019-01-11 15:55:55.812 19850-19850/com.sensennetworks.senanpr E/AndroidRuntime: FATAL EXCEPTION: main

How do I properly integrate fabric and crashlytics for them to work in Bazel?

My dependencies in BUILD file are:

 deps = [
        ":tensorflow_native_libs",
        "//tensorflow/contrib/lite/java:tensorflowlite",
        "@com_google_code_gson_gson//jar",
        "@com_mcxiaoke_volley_library//jar",
        #"@com_sun_mail_android_activation//jar",
        #"@com_sun_mail_android_mail//jar",
        gmaven_artifact("com.google.android.gms:play-services-location:aar:15.0.1"),
        gmaven_artifact("com.android.support:appcompat-v7:aar:26.1.0"),
        gmaven_artifact("com.android.support:design:aar:26.1.0"),
        gmaven_artifact("com.android.support:recyclerview-v7:aar:26.1.0"),
        gmaven_artifact("com.android.support:support-v4:aar:26.1.0"),
        gmaven_artifact("io.fabric.sdk.android:fabric:aar:1.3.17"),
        gmaven_artifact("com.crashlytics.sdk.android:crashlytics:aar:2.9.0"),
        #gmaven_artifact("com.crashlytics.sdk.android:crashlytics-core:aar:2.6.4"),
        gmaven_artifact("com.google.firebase:firebase-core:aar:15.0.2")]

回答1:


You can now integrate Crashlytics directly into your Bazel build with crashlytics_android_library using bazelbuild/tools_android.

load("@rules_maven//:defs.bzl", "artifact")
load("@tools_android//tools/crashlytics:defs.bzl", "crashlytics_android_library")
load("@tools_android//tools/googleservices:defs.bzl", "google_services_xml")

GOOGLE_SERVICES_RESOURCES = google_services_xml(
    package_name = "com.example.package",
    google_services_json = "google-services.json",
)

crashlytics_android_library(
    name = "crashlytics_lib",
    package_name = "com.example.package",
    build_id = "9dfea8fe-4d75-48a7-ba28-4ddb7fe74780",
    resource_files = GOOGLE_SERVICES_RESOURCES,
)

android_library(
    name = "crashlytics_deps",
    exports = [
        artifact("com.crashlytics.sdk.android:crashlytics"),
        artifact("io.fabric.sdk.android:fabric"),
    ],
)

android_library(
    name = "my_release_lib",
    srcs = glob(["src/main/**/*.java"]),
    manifest = "AndroidManifest.xml",
    resource_files = glob(["res/**/*"]),
    deps = [
        ":crashlytics_lib",
        ":crashlytics_deps", 
    ],
)

For more information, read https://github.com/bazelbuild/tools_android/blob/master/tools/crashlytics/README.md



来源:https://stackoverflow.com/questions/54144989/fabric-and-crashlytics-not-working-with-bazel-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!