簡體   English   中英

Android調試中的結構初始化非常慢

[英]very slow fabric initialization in android debug

我正在嘗試在Android上集成結構(包括帶有NDK支持和答案的NSD的rashlytics),並使它們正常工作。

但是,當我嘗試調試應用程序時,結構需要很長時間(大約500萬)來完成其工作。

這是日志:

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.

如您所見,

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

花了將近300萬,

Attempting to load unwinder...

也拿了好三百萬

當我嘗試在沒有調試器附加的情況下啟動應用程序時(只需在android studio中運行而不是在調試中運行),應用程序啟動就可以了。

任何在何處尋找此問題的方向將不勝感激。

吉揚

編輯1:

深入研究之后,實際上是由JniNativeApi進行的調用

System.loadLibrary("crashlytics");

首先,這需要很多時間。 不知道第二次凍結了。

這很奇怪,因為該庫似乎太輕了(libcrashlytics.so約為600ko)

編輯2:

這是我的gradle構建的結構:

在頂層,proj.android文件夾中有一個build.gradle,其中包含所有子項目(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'
}

然后我有一個用於所有子項目的build.gradle文件(1個com.android.application和4個com.android.library)

我不認為庫build.gradle文件是相關的,因為我沒有在其中添加任何與架構相關的初始化,因此這是主應用程序的build.gradle:

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')
}

我還在清單中添加了api鍵

...
<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"
        />
...

最后,我在活動的onCreate方法中設置Fabric,如下所示:

// 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);

非常感謝您的快速答復,希望其他信息對您有所幫助!

編輯3

我在幾種設備(銀河選項卡s3 @ 7.0和Google像素C @ 7.1.1)上進行了測試,它沒有任何區別,問題仍然存在。

我現在不怎么知道,但是一旦我重新啟動筆記本電腦,問題就消失了。 我想這與adb調試器以某種方式卡住有關?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM