Android JetPack Jetifier 的 Crashlytics 问题

Android Crashlytics issue with JetPack Jetifier

好吧,我创建了一个项目并添加了 Fabric 插件和 Crashlytics 依赖项,我也对其进行了测试并且它有效。但是当我重构项目以使用 AndroidX 并启用 jetifier 工具时 android.enableJetifier=true 项目不会构建并且我收到多个错误,例如:

Failed to transform file 'crashlytics-2.9.2.aar' to match attributes {artifactType=jetified-aar} using transform JetifyTransform

jetifier 工具和 Crashlytics 依赖似乎有问题。有没有办法关闭单个依赖项的 JetifyTransform

项目级别gradle文件:

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

buildscript {
    ext.kotlin_version = '1.2.41'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:3.1.2'
        classpath 'io.fabric.tools:gradle:1.25.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

模块级别gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "ir.scannpay.person"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
}

gradle.properties 文件:

android.enableJetifier=true
android.useAndroidX=true

并且我没有忘记将Fabric键放在manifest中,我还将google-services.json文件放在app模块中。

当我尝试构建时,出现多个错误:

Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'crashlytics-2.9.2.aar' to match attributes {artifactType=jetified-aar} using transform JetifyTransform

Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'crashlytics-core-2.6.2.aar' to match attributes {artifactType=jetified-aar} using transform JetifyTransform

Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'beta-1.2.7.aar' to match attributes {artifactType=jetified-aar} using transform JetifyTransform

好吧,我找到了解决方案。

您需要做的是在您的项目级别 build.gradle 文件中将您的结构版本升级到 1.25.4

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:3.2.0'
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}