我正在将 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)
应用程序/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'
}
}
项目/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(...) 的最后一行。