【问题标题】:Cannot resolve symbol 'OnSuccessListener' in Android Studio无法在 Android Studio 中解析符号“OnSuccessListener”
【发布时间】:2019-02-07 17:25:23
【问题描述】:

在 git 克隆并在另一台机器上构建后,我无法将 OnSuccessListener 导入到我的代码中(这在我以前的机器中解决得很好)。然而,该项目构建良好并在模拟器上运行。但是由于监听器没有解析,我无法进一步编写与 firebase 相关的代码。

我尝试清理项目、重建、使缓存无效,但仍然没有运气。

Gradle 依赖项,

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-firestore:17.0.4'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.github.drawers:SpinnerDatePicker:1.0.6'
    implementation 'com.github.yalantis:ucrop:2.2.2'
}

【问题讨论】:

  • 你试过删除.idea/libraries吗?
  • 我尝试删除构建文件夹并重建项目。仍然项目构建良好,上面没有解决给定类中的错误。
  • 试过删除 .idea/* 还是不行
  • 我认为 OnSuccessListner 的方法可能属于不同的类。阻止此方法的代码。再写一遍,它会询问你想从哪个类创建方法。然后选择正确的。
  • 您是否尝试过使用import com.google.android.gms.tasks.OnSuccessListener; 这一行手动导入OnSuccessListener?请回复@。

标签: android firebase google-play-services google-cloud-firestore cannot-find-symbol


【解决方案1】:

请尝试将此添加到您的 app-gradle 文件中。

实现'com.google.android.gms:play-services-tasks:16.0.1'

【讨论】:

    【解决方案2】:

    你所做的就是让所有 firebase 和 gms 版本的数字相同,例如:

    实现 'com.google.firebase:firebase-auth:102.0' 实现 'com.google.android.gms:play-services-auth:10.2.0'

    【讨论】:

    • 这不再是要求,最新的库可以有不同的版本而不会冲突
    • 是的,这不是 firebase sdk 的要求。事实上,谷歌建议你使用最新的 firebase 库。有时也没有与相应的 Firebase 服务匹配的版本号。
    猜你喜欢
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2023-03-27
    • 2015-07-28
    • 2014-06-24
    相关资源
    最近更新 更多