5
respostas

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

Não consigo compilar o projeto, sempre que tento compilar ocorre o erro: error: cannot access zzbgl class file for com.google.android.gms.internal.zzbgl not found

Toda vez que eu faço click duplo no erro eu sou jogado para a linha onde está o código:

request.setSmallestDisplacement(50);

Segue abaixo o codigo da classe Localizador:

package br.com.alura.agenda;

import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;

public class Localizador implements GoogleApiClient.ConnectionCallbacks, LocationListener {

    private final GoogleApiClient client;
    private final GoogleMap mapa;

    public Localizador(Context context, GoogleMap mapa) {
        client = new GoogleApiClient.Builder(context)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .build();

        client.connect();

        this.mapa = mapa;
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        LocationRequest request = new LocationRequest();
        request.setSmallestDisplacement(50);
        request.setInterval(1000);
        request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

        LocationServices.FusedLocationApi.requestLocationUpdates(client, request, this);
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onLocationChanged(Location location) {
        LatLng coordenada = new LatLng(location.getLatitude(), location.getLongitude());
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(coordenada);
        mapa.moveCamera(cameraUpdate);
    }
}
5 respostas

mostra pra gente como tá seu build.gradle que fica dentro da pasta do projeto, por gentileza

Eu to com o mesmo problema do Ivan.

Segue o gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "br.com.alura.agenda"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.android.gms:play-services-maps:15.0.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.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.google.android.gms:play-services:12.0.1'
}

O meu esta bem parecido com o do Marcio:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "br.com.alura.agenda"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:28.0.0-alpha3'
    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.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
}

Boa Tarde

Matheus eu fiz sua implementação ABAIXO. Ok. deu certo só aviso que retirei a seguinte dependência

Retirei

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

E coloquei

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

Deixando o meu build.grade final dessa forma

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "br.com.alura.agenda"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    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'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.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.android.support:cardview-v7:27.1.1'

}

Mas agora para "camera" acompanhar a movimentação do usuário enquanto ele se "move" (e claro trocando os parâmetros de Longitude e Latitude no simulador ) não consegui implementar.

Na classe GPS que vc exibiu não tem esse método

   @Override
    public void onLocationChanged(Location location) {
        LatLng coordenada = new LatLng(location.getLatitude(), location.getLongitude());
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(coordenada);
        mapa.moveCamera(cameraUpdate);
    }

Não sei se isso tem haver.

desde já Obrigado.

Acabei de fazer uns testes aqui e consegui fazer isso tudo funcionar, bom minhas dependencias estão assim :

dependencies {
// as demais 

    implementation 'com.google.android.gms:play-services-maps:15.0.1' // para mapas
    implementation 'com.google.android.gms:play-services-location:15.0.1' // para gps

}

Ai minha classe de acesso ao gps foi feita dessa forma :

public class GPS extends LocationCallback {

    private FusedLocationProviderClient client;
    private GPSDelegate delegate;

    public GPS(GPSDelegate delegate) {
        this.delegate = delegate;
        this.client = LocationServices.getFusedLocationProviderClient(delegate.getContext());
    }

    public void fazBusca() {
        LocationRequest req = new LocationRequest();

        req.setInterval(1000);
        req.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        req.setSmallestDisplacement(10);

        client.requestLocationUpdates(req, this, null);
    }


    @Override
    public void onLocationResult(LocationResult locationResult) {
        super.onLocationResult(locationResult);

        delegate.lidaCom(locationResult.getLastLocation());

    }


    public void cancelaBusca() {
        client.removeLocationUpdates(this);
    }
}

Ai tem essa dependencia na classe, chamada GPSDelegate:

public interface GPSDelegate {
    Context getContext();

    void lidaCom(Location lastLocation);
}

E por fim a implementação do mapa usando o gps :

public class MapaFragment extends SupportMapFragment implements OnMapReadyCallback, GPSDelegate {


    private GoogleMap map;
    private GPS gps;

    @SuppressLint("MissingPermission")
    @Override
    public void onResume() {
        super.onResume();
        getMapAsync(this);
        gps = new GPS(this);
        gps.fazBusca();

    }

    @Override
    public void onPause() {
        super.onPause();
        gps.cancelaBusca();
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        map = googleMap;
    }

    @Override
    public void lidaCom(Location lastLocation) {
        MarkerOptions marker = new MarkerOptions();

        LatLng latlng = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
        marker.position(latlng);

        map.addMarker(marker);
    }
}