简体   繁体   中英

very slow fabric initialization in android debug

I am trying to integrate fabric (both crashlytics with NDK support and answers) on android and I got them working.

However, when I try to debug my app, fabric take a long time (around 5 mn) to do its things.

Here is the log:

10-16 11:41:49.680 1534-1559/? V/WindowManager: Relayout Window{326db3dd0 u0 Starting app.company.com}: viewVisibility=0 req=2048x1536 WM.LayoutParams{(0,0)(fillxfill) sim=#20 ty=3 fl=#81830518 pfl=0x20011 wanim=0x103038a vsysui=0x600 needsMenuKey=2 naviIconColor=0}
10-16 11:41:49.701 1534-1559/? D/WindowManager: finishDrawingWindow: Window{326db3dd0 u0 Starting app.company.com} mDrawState=DRAW_PENDING
10-16 11:41:49.714 1534-1559/? I/WindowManager: Screen frozen for +113ms due to Window{326db3dd0 u0 Starting app.company.com}
10-16 11:41:49.945 21418-21684/app.company.com W/art: Verification of io.fabric.sdk.android.services.settings.Settings io.fabric.sdk.android.services.settings.Settings.initialize(io.fabric.sdk.android.Kit, io.fabric.sdk.android.services.common.IdManager, io.fabric.sdk.android.services.network.HttpRequestFactory, java.lang.String, java.lang.String, java.lang.String) took 173.644ms
10-16 11:44:51.139 21418-21684/app.company.com W/art: Verification of boolean io.fabric.sdk.android.services.settings.Settings.loadSettingsSkippingCache() took 181.194s
10-16 11:44:51.164 21418-21418/app.company.com D/libcrashlytics: Initializing libcrashlytics version 1.1.5
10-16 11:44:51.165 21418-21418/app.company.com D/libcrashlytics: Attempting to load unwinder...
10-16 11:49:24.955 21418-21684/app.company.com W/art: Verification of java.lang.String io.fabric.sdk.android.services.common.AbstractSpiCall.overrideProtocolAndHost(java.lang.String) took 303.615ms
10-16 11:49:25.366 21418-21418/app.company.com D/libcrashlytics: Done; using libunwind
10-16 11:49:25.366 21418-21418/app.company.com D/libcrashlytics: Attempting to register signal handler...
10-16 11:49:25.367 21418-21418/app.company.com D/libcrashlytics: Signal handler registered.
10-16 11:49:25.370 21418-21418/app.company.com D/libcrashlytics: Initializing native crash handling successful.

As You can see, the

Verification of boolean io.fabric.sdk.android.services.settings.Settings.loadSettingsSkippingCache() took 181.194s

took nearly 3 mn, and the

Attempting to load unwinder...

took also a good 3mn.

When I am trying to launch the app without the debugger attach (just run instead of debug in android studio), the app launches just fine.

Any direction on where to look for this issue would be very appreciated.

Guilhem

EDIT 1:

After digging a bit, it is actually the call made from JniNativeApi that calls the

System.loadLibrary("crashlytics");

That takes a lot of time in the first place. Don't know for the second freeze yet.

It is weird because the library seems lightweigth (libcrashlytics.so is around 600ko)

EDIT 2:

Here is the structure of my gradle build:

At the top level there is a build.gradle in a proj.android folder, that contains all the config options common to all sub-projects (abiFilters, minSdkVersion ...):

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

ext {
    minSdkVersion = 24
    targetSdkVersion = 26
    compileSdkVersion = 26
    buildToolsVersion = '26.0.1'
    abiFilters = [
            'XXX'
    ]
    cppDebugFlags = [
            'YYYYYY'
    ]
    cppReleaseFlags = [
            'ZZZZZ'
    ]
    arguments = [
            '-DANDROID_TOOLCHAIN=clang',
            '-DANDROID_PLATFORM=android-24',
            '-DANDROID_STL=c++_static',
            '-DANDROID_CPP_FEATURES=rtti exceptions'
    ]
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.1'
}

task clean(type: Delete) {
    delete 'stuff'
}

Then I have a build.gradle file for all my sub projects (1 com.android.application and 4 com.android.library)

I don't think the library build.gradle file are relevant as I didn't put any fabric related initialization in them, so here is my build.gradle for the main application:

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

    dependencies {
        // These docs use an open ended version so that our plugin
        // can be updated quickly in response to Android tooling updates

        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
        classpath 'io.fabric.tools:gradle:1.24.2'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

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

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    sourceSets.main {
        res.srcDir "res"
        assets.srcDirs 'sources'
        jniLibs.srcDirs "jni"
        java.srcDirs "java sources dirs"
        manifest.srcFile "AndroidManifest.xml"
    }

    defaultConfig {
        applicationId 'app.company.com'
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 2
        versionName '0.1'
        ndk {
            moduleName "moduleName"
            abiFilters rootProject.ext.abiFilters.join(",").split(",")
        }
        externalNativeBuild {
            cmake {
                cppFlags rootProject.ext.cppReleaseFlags.join(",").split(",")
                arguments rootProject.ext.arguments.join(",").split(",")
                targets "target"
            }
        }
    }

    buildTypes {
        debug {
            externalNativeBuild {
                cmake {
                    cppFlags rootProject.ext.cppDebugFlags.join(",").split(",")
                }
                // to do: swap those two lines when when debug testing will be done
                ext.alwaysUpdateBuildId = false // STACKOVERFLOW NOTE: commenting this line doesn't change anything to the problem
                //ext.enableCrashlytics = false
            }
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path "../../CMakeLists.txt"
        }
    }

    aaptOptions {
        cruncherEnabled = false
        noCompress 'zspine', 'zparticles', 'gz'
    }
}

crashlytics {
    enableNdk true
    manifestPath 'AndroidManifest.xml'
    // are these needed?
    // STACKOVERFLOW NOTE: I tried put the values that are given in the docs, but it doesn't seems to change anything
    //androidNdkOut 'build/intermediates/cmake/release/obj'
    //androidNdkLibsOut 'build/intermediates/bundles/default/jni'
}

// STACKOVERFLOW NOTE: here are some task definition to automatically update sources, I don't think they are relevant to the matter at hand
...

dependencies {
    compile fileTree(dir:'someJars')

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

    debugCompile project(path: ':lib1', configuration: 'debug')
    debugCompile project(path: ':lib2', configuration: 'debug')
    debugCompile project(path: ':lib3', configuration: 'debug')
    debugCompile project(path: ':lib4', configuration: 'debug')

    releaseCompile project(path: ':lib1', configuration: 'release')
    releaseCompile project(path: ':lib2', configuration: 'release')
    releaseCompile project(path: ':lib3', configuration: 'release')
    releaseCompile project(path: ':lib4', configuration: 'release')
}

I have also added in the manifest the api key in

...
<application android:label="@string/app_name"
    android:icon="@drawable/icon">

    <!-- name of our .so -->
    <meta-data android:name="android.app.lib_name"
        android:value="name" />

    <meta-data android:name="io.fabric.ApiKey"
        android:value="API Key"
        />
...

And finally I setup Fabric in the onCreate method of my activity like this:

// TODO uncomment this when testing's over
//Crashlytics crashlyticsKit = new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build();
//Fabric.with(this, crashlyticsKit);

Fabric fabric = new Fabric.Builder(this).kits(new Crashlytics(), new CrashlyticsNdk())
        .debuggable(true)
        .build();
Fabric.with(fabric);

Thanks a lot for your fast answer, I hope the additional informations will help!

EDIT 3

I tested on several devices (galaxy tab s3 @7.0 & google pixel C @7.1.1), it doesn't make any difference, the problem still occurs.

I don't exactly now how, but the problem disappeared once I restart my laptop. I guess it has to do with the adb debugger getting stucked somehow?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM