使用androidx的Android Google登录提供了以下失败的解析:Landroid / support / v4 / util / ArraySet Error

时间:2018-12-09 15:36:23

标签: android google-signin androidx support-v4

我正在将Google登录与我的应用以及androidx集成在一起。因此,我不得不从实现'com.google.android.gms:play-services-auth:16.0.1'中排除支持库。使用以下错误日志崩溃。

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.android.app, PID: 12896
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArraySet;
    at com.google.android.gms.common.api.internal.GoogleApiManager.<init>(Unknown Source:29)
    at com.google.android.gms.common.api.internal.GoogleApiManager.zab(Unknown Source:8)
    at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source:27)
    at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source:51)
    at com.google.android.gms.auth.api.signin.GoogleSignInClient.<init>(Unknown Source:3)
    at com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(Unknown Source:3)
    at android.myapp.com.app.ui.LoginFragment.onViewCreated(LoginFragment.kt:59)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1471)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
    at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
    at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
    at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
    at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
    at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
    at android.app.Activity.performStart(Activity.java:7165)
    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2938)
    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6680)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArraySet" on path: DexPathList[[zip file "/data/app/com.myapp.android.local-U-XaL_44g3BXcX3gCLZB4g==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.android.local-U-XaL_44g3BXcX3gCLZB4g==/lib/arm64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

app / build.gradle:

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion rootProject.compileSdk

    baseFeature true

    defaultConfig {
        minSdkVersion rootProject.minSdk
        targetSdkVersion rootProject.targetSdk
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        pickFirst 'LICENSE.txt'
        pickFirst 'protobuf.meta'
    }

    flavorDimensions "default"

    productFlavors {
        local {
            resValue "string", "app_name", "Local"
        }
        production {
            resValue "string", "app_name", "MyApp"
        }
    }
}

dependencies {
    application project(':installed')
    feature project(':features:nearme')

    implementation 'com.android.support:multidex:1.0.3'

    api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    api 'com.google.android.instantapps:instantapps:1.1.0'

    api 'androidx.appcompat:appcompat:1.0.2'
    api 'androidx.constraintlayout:constraintlayout:1.1.3'

    // Kotlin
    api "androidx.core:core-ktx:$rootProject.ktxVersion"

    // Lifecycle components
    api "androidx.lifecycle:lifecycle-viewmodel:$rootProject.archLifecycleVersion"
    api "androidx.lifecycle:lifecycle-livedata:$rootProject.archLifecycleVersion"
    kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"

    // Google login
    implementation('com.google.android.gms:play-services-auth:16.0.1') {
        exclude group: 'com.android.support'
    }
}

project / build.gradle

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

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

ext {
    buildTools = "27.0.3"
    compileSdk = 28
    targetSdk = 28
    minSdkInstant = 21
    minSdk = 21
    archLifecycleVersion = "2.0.0"
    ktxVersion = "1.0.1"

    supportLibVersion = "27.1.1"
    playServicesAuthVersion = "11.8.0"
    espressoVersion = "3.0.1"
    androidTestVersion = "0.5"
    hamcrestVersion = "1.3"
    junitVersion = "4.12"
}

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

MyLoginFragment.java

val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(Constants.OAUTH_CLIENT_ID)
            .requestEmail()
            .build()

googleSignInClient = GoogleSignIn.getClient(context!!, googleSignInOptions)

崩溃日志指向GoogleSignIn.getClient(...)的最后一行。

1 个答案:

答案 0 :(得分:0)

这为我解决了问题: 删除应用程序build.gradle中play-services-auth库上的排除项,然后,如果出现“程序类型不存在...”错误,请将这些行添加到gradle.properties中:

android.useAndroidX = true
android.enableJetifier = true