【问题标题】:Error: cannot access zzbgl错误:无法访问 zzbgl
【发布时间】:2019-01-21 06:52:18
【问题描述】:

我正在开发应用程序,但出现以下错误:

error: cannot access zzbgl
class file for com.google.android.gms.internal.zzbgl not found

我知道 StackOverflow 中有一个问题,与我 4 天前发布的错误相同,但答案对我的情况没有帮助。 (我说的是this one

在我的项目中设置 Firebase Analytics 后,该错误就出现了。

我的 build.gradle (Module: app) 文件是这样的:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.3'
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId 'com.geoactio.montferri'
        minSdkVersion 14
        targetSdkVersion 26
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    dependencies {
         implementation 'com.android.support:multidex:1.0.3'
         implementation 'com.android.support:appcompat-v7:26.1.0'
//        compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'
        implementation 'com.google.android.gms:play-services:12.0.1'
        //implementation 'com.google.android.gms:play-services-maps:15.0.1'
        //implementation 'com.google.android.gms:play-services-location:15.0.1'
        implementation "com.google.android.gms:play-services-base:15.0.1"
        implementation 'com.navercorp.pulltorefresh:library:3.2.3@aar'

    }
    productFlavors {
    }
    lintOptions {
        disable 'MissingTranslation'
    }

    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
}
repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'

    implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
    transitive = true;
    }
}

apply plugin: 'com.google.gms.google-services'

我的 build.gradle (Project: myPorojectName) 文件是这样的:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

点击错误会导致我here,就在new MarkerOptions()之后:

mapView.addMarker(new MarkerOptions().position(new LatLng(puntomarker.getLatitud(), puntomarker.getLongitud()))
                    .zIndex(0.5f)
                    .anchor(0.5f, 0.5f)
                    .title(puntomarker.getId() + "")
                    .snippet(puntomarker.getNombre())
                    .icon(BitmapDescriptorFactory.fromBitmap(((BitmapDrawable) marker).getBitmap())));

(作为 ma​​pView 一个 GoogleMap 实例)。

我希望有人能看到错误并解决这个问题,非常感谢你。 如果您需要更多信息来解决此问题,请告诉我。

【问题讨论】:

  • 尝试参考这个so answer
  • 我认为您在 build.gradle(根级别)中缺少 google() 依赖项
  • 不要导入完整的播放服务。只添加你想要的依赖项。 Play services 是一个巨大的图书馆
  • 我只更改并添加了地图、位置和分析,它正在工作!谢谢你的帮助@VivekMishra
  • 谢谢,但 Vivek 的回答确实有效! @RobertoManfreda

标签: android firebase firebase-analytics


【解决方案1】:

Google API Release Notes 表示对组合 play-services 库的支持已于 2018 年 4 月结束:

从 15.0.0 开始,将不再有一个 play-services 别名目标来拉入所有 Google Play 服务组件。一段时间以来一直建议不要这样做。

您不能再像这样对组合的 Google Play 服务目标指定单个依赖项:

implementation 'com.google.android.gms:play-services:12.0.1'.

当以前的版本支持此功能时,它会以比您需要的方式更多地引入 ALL Google Play 库。请参阅Setup Guide 的表 1 中的 API 列表,并仅包括您的应用使用的特定 API。

检查Google Maven Repository 确认版本 12.0.1 是组合播放服务目标的最后一个版本。

所以请删除上面的实现,只用:

implementation "com.google.android.gms:play-services-base:15.0.1"

如果您还使用其他播放服务,请将它们添加为单独的依赖项。

【讨论】:

    【解决方案2】:

    我认为您出错的主要原因是您使用 2 个不同版本的播放服务库

            implementation 'com.google.android.gms:play-services:12.0.1'
    

    这里是12.0.1

            implementation "com.google.android.gms:play-services-base:15.0.1"
    

    虽然这里是 15.0.1。

    尝试在任何地方使用相同版本的相关库。

    【讨论】:

    • 如果我升级版本,我会遇到另一个错误,但正如他们告诉我的那样,我更改了它,我只使用了我需要的库,而不是整个谷歌服务。谢谢!
    • 也是我建议你的
    • 对不起,我在发表评论之前没有注意到
    • OP 收到该错误的原因不是因为他使用“2 个不同的版本”,而是因为这个 implementation 'com.google.android.gms:play-services:12.0.1' 不再存在。
    • @AlexMamo 可能你错了,我刚刚尝试过我能够成功同步我的项目。它只是发出警告,避免使用捆绑包
    【解决方案3】:

    你只需要改变一个依赖,因为 12.0.1 已经不存在了

    implementation 'com.google.android.gms:play-services:12.0.1'
    

    implementation 'com.google.android.gms:play-services-base:15.0.1'
    

    然后按同步 Gradle

    希望对你有帮助

    【讨论】:

    • 这与@VivekMishra 在下方发布的解决方案相同,正如我所说,我在执行此操作时遇到了错误。正确的解决方案写在对原始帖子的评论中(也由同一用户)。无论如何感谢您的帮助
    【解决方案4】:

    更新所有依赖项的版本。 通常,如果您使用多个新旧依赖项,则会发生此错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 2017-09-07
      • 2021-01-22
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多