AndroidX迁移后,在KitKat上应用程序崩溃

4

我已经将我的应用迁移到AndroidX以便使用app:drawableLeftCompat。在迁移后,应用在某些屏幕上在运行时崩溃了,这些屏幕使用的是Android KitKat。而在Android 7上运行良好。ADB日志中没有堆栈跟踪。以下是部分日志:

E/dalvikvm: Could not find class 'android.view.textclassifier.TextClassificationManager', referenced from method androidx.appcompat.widget.AppCompatTextClassifierHelper.getTextClassifier
W/dalvikvm: VFY: unable to resolve const-class 759 (Landroid/view/textclassifier/TextClassificationManager;) in Landroidx/appcompat/widget/AppCompatTextClassifierHelper;
D/dalvikvm: VFY: replacing opcode 0x1c at 0x000a
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/textclassifier/TextClassifier;)
    VFY: unable to find class referenced in signature (Landroid/view/textclassifier/TextClassifier;)
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/ViewStructure;)
I/dalvikvm: Could not find method android.widget.LinearLayout.dispatchProvideAutofillStructure, referenced from method com.google.android.material.textfield.TextInputLayout.dispatchProvideAutofillStructure
W/dalvikvm: VFY: unable to resolve virtual method 5194: Landroid/widget/LinearLayout;.dispatchProvideAutofillStructure (Landroid/view/ViewStructure;I)V
D/dalvikvm: VFY: replacing opcode 0x6f at 0x002e
W/dalvikvm: VFY: unable to resolve virtual method 4274: Landroid/view

/ViewConfiguration;.shouldShowMenuShortcutsWhenKeyboardPresent ()Z
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
D/EGL_emulation: eglMakeCurrent: 0xb7961980: ver 2 0
E/EGL_emulation: tid 3996: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)
W/HardwareRenderer: Backbuffer cannot be preserved
D/dalvikvm: Trying to load lib /data/app-lib/ru.septagon.android.cashregister-2/librsjni_androidx.so 0xa4ffabd0
    Added shared lib /data/app-lib/ru.septagon.android.cashregister-2/librsjni_androidx.so 0xa4ffabd0
A/libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 3996 (id.cashregister)
Application terminated.

从这个日志中我无法理解崩溃的原因。有什么想法吗?

这是应用程序模块的build.gradle文件。

apply plugin: 'com.android.application'
apply plugin: 'io.sentry.android.gradle'

def versionMajor = 1
def versionMinor = 3
def versionPatch = 0

repositories {
    jcenter()
    flatDir {
        dirs 'libs'
    }
}

android {
    if (project.hasProperty('debBuild')) {
        splits.abi.enabled = false
        splits.density.enable = false
    }
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    compileOptions.encoding = 'UTF-8'

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
        disable 'MissingTranslation'
    }
    dataBinding {
        enabled = true
    }

    dexOptions {
        preDexLibraries true
        javaMaxHeapSize "4g"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    splits {
        abi {
            enable true
            reset()
            universalApk true
        }
    }

    defaultConfig {
        applicationId "ru.septagon.android.cashregister"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
        versionName generateVersionName("${versionMajor}.${versionMinor}.${versionPatch}")
        setProperty("archivesBaseName", "cashregister-$versionName")

        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField 'int', 'SYNC_PERIOD_SEC', '360'
            signingConfig signingConfigs.release
        }

        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField 'int', 'SYNC_PERIOD_SEC', '60'
        }

    }

    packagingOptions {
        exclude 'lib/mips/libRSSupport.so'
        exclude 'lib/mips/librsjni.so'
    }
}


private String generateVersionName(String version) {
    String versionName = version
    if (project.hasProperty("buildVersion")) {
        versionName += "." + project.getProperties().get("buildVersion").toString()
    }
    return versionName;
}

dependencies {

    implementation project(':log')
    implementation project(':esptouch')
    implementation project(':pinpad')

    implementation(name: 'android_util_fr_drv_ng-release', ext: 'aar')

    // Google support
    implementation "androidx.core:core:$rootProject.supportVersion"
    implementation "androidx.legacy:legacy-support-core-ui:$rootProject.supportVersion"
    implementation "androidx.legacy:legacy-support-v13:1.0.0"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "androidx.appcompat:appcompat:1.1.0-alpha02"
    implementation "androidx.cardview:cardview:$rootProject.supportVersion"
    implementation "androidx.recyclerview:recyclerview:$rootProject.supportVersion"
    implementation "com.google.android.material:material:$rootProject.supportVersion"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.multidex:multidex:2.0.0'

    implementation 'com.annimon:stream:1.2.0'

    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation 'com.github.mmin18:realtimeblurview:1.1.2'
    implementation 'com.ms-square:etsyblur:0.2.1'

    // Google common
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'

    // google arch
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archVersion"
    implementation "androidx.lifecycle:lifecycle-runtime:$rootProject.archVersion"

    // Rx
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
    implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'

    // DI
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
    annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"

    // recycler view
    implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:2.3.0-beta1'
    implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:2.3.0-beta1'

    // Network
    implementation "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"
    implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'

    // DB
    implementation 'com.j256.ormlite:ormlite-android:5.0'
    annotationProcessor "org.projectlombok:lombok:1.16.12"

    // Glide
    implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
    annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
    implementation 'jp.wasabeef:glide-transformations:3.0.1'

    implementation 'joda-time:joda-time:2.10'
    implementation 'me.jessyan:autosize:0.9.5'
    implementation 'jp.wasabeef:recyclerview-animators:2.3.0'
    implementation 'io.sentry:sentry-android:1.7.10'
    implementation 'com.github.Kyash:rx-keyboard-detector:0.1.2'

    // Test
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
}

这是主build.gradle文件。
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'io.sentry:sentry-android-gradle-plugin:1.7.10'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'http://srv-recs-dev01:8081/nexus/content/repositories/releases/' }
        maven { url 'http://srv-recs-dev01:8081/nexus/content/repositories/snapshots/' }
        mavenLocal()
        flatDir {
            dirs 'libs'
            dirs project(':pinpad').file('libs')
        }
    }
//    buildScan { licenseAgreementUrl = 'https://gradle.com/terms-of-service'; licenseAgree = 'yes' }
}

task printVersion{
    doLast {
        print rootProject.childProjects.get("app").android.defaultConfig.versionName
    }
}

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

ext {
    compileSdkVersion = 28
    buildToolsVersion = '28.0.3'

    minSdkVersion = 19
    targetSdkVersion = 26

    supportVersion = '1.0.0-beta01'
    servicesVersion = '11.8.0'
    androidAnnotationVersion = '4.3.1'
    archVersion = '2.0.0-beta01'

    daggerVersion = '2.16'
    okhttpVersion = '3.10.0'
    retrofitVersion = '2.4.0'
    glideVersion = '4.7.1'
    crashlyticsVersion = '2.6.8'
    commonsVersion = "1.3.0.3"
}

请展示您的 .gradle 文件。 - Alan Deep
@AlanDeep在问题中添加了配置。 - Fyodor Sherstobitov
请检查我的答案。 - Alan Deep
尝试重写您的Gradle导入,无论您在哪里使用$rootProject.archVersion,请明确放置这些库的最新稳定版本。 - MD Naseem Ashraf
4个回答

3
这次崩溃的原因在于这些依赖关系。
implementation 'com.github.mmin18:realtimeblurview:1.1.2'
implementation 'com.ms-square:etsyblur:0.2.1'

这些库使用了来自Support Library的一些渲染机制,但在AndroidX中存在问题。因此,我们决定在应用程序中放弃模糊视图并删除依赖项。


1
这个问题应该在29.0.2版本的构建工具发布中得到解决。对于我来说,与renderscript相关的SIGSEGV已经消失了,使用以下配置:
android {
  compileSdkVersion 29
  buildToolsVersion "29.0.2"
  defaultConfig {
    ...
    minSdkVersion 17
    targetSdkVersion 29
    ...
    renderscriptTargetApi 21
    renderscriptSupportModeEnabled true

0

我遇到了这个问题,并且很容易地使用AppCompatImageView代替ImageView来解决它。此外,我还将所有设置矢量图形的XML视图中的android:src替换为app:srcCompat

不要忘记其他视图!如果您使用TextView或EditText,请将它们更改为AppCompatTextViewAppCompatEditText,然后在需要时使用drawable compat

<TextView
    android:id="@+id/search_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableStart="@drawable/ic_search_24px_vector"
    android:drawablePadding="8dp" />

替换后:

<androidx.appcompat.widget.AppCompatTextView
    android:id="@+id/search_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:drawableStartCompat="@drawable/ic_search_24px_vector"
    android:drawablePadding="8dp" />

-1
我遇到了同样的问题,并通过以下方法解决了它:
替换这两行代码:
  // google arch
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archVersion"
    implementation "androidx.lifecycle:lifecycle-runtime:$rootProject.archVersion"

通过这些:

    implementation group: 'android.arch.persistence.room', name: 'runtime', version: '1.1.0'
    annotationProcessor group: 'android.arch.persistence.room', name: 'compiler', version: '1.1.1'

我在应用程序中没有使用Room。为什么我需要添加它的依赖项?这些更改后,应用程序无法编译。 - Fyodor Sherstobitov
没有解决问题。建议添加完全不同的库。 - Manu
这是一个对于那些遇到相同问题但使用其他库的人非常有用的评论。我不认为Alan建议你添加那些库。 - babibo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接