在安卓中集成谷歌放置SDK时出错,"Error: Type com.google.android.libraries.places.internal.nx "



我正在将谷歌将 sdk 集成到 android 中,它在编译代码时给了我错误:

错误:键入 com.google.android.libraries.places.internal.nx 引用为com.google.android.libraries.places.internal.jx$a中的interface

build.gradle

implementation 'com.google.android.libraries.places:places:1.1.0'
implementation 'com.google.android.libraries.places:places-compat:1.1.0'

MainActivity

@Override
public void onCreate() {
    super.onCreate();
    Places.initialize(this, getResources().getString(R.string.google_free_api_key));
    InternetAvailabilityChecker.init(this);
    StateSaver.setEnabledForAllActivitiesAndSupportFragments(this, true);
    appExecutors = new AppExecutors();
}
private void searchPlaces(final String query){
    // Create a new token for the autocomplete session. Pass this to FindAutocompletePredictionsRequest,
    // and once again when the user makes a selection (for example when calling fetchPlace()).
    AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
    // Create a RectangularBounds object.
    RectangularBounds bounds = RectangularBounds.newInstance(
            new LatLng(0.703579, -82.689471),
            new LatLng(-18.360459, -68.571046));
    // Use the builder to create a FindAutocompletePredictionsRequest.
    FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder()
            // Call either setLocationBias() OR setLocationRestriction().
            .setLocationBias(bounds)
            //.setLocationRestriction(bounds)
            .setCountry("pe")
            .setTypeFilter(TypeFilter.ADDRESS)
            .setSessionToken(token)
            .setQuery(query)
            .build();
    placesClient.findAutocompletePredictions(request).addOnSuccessListener((response) -> {
        List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG);
        viewModel.getDirections().clear();
        for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
            Log.i(LOG_TAG, prediction.getPlaceId());
            Log.i(LOG_TAG, prediction.getPrimaryText(null).toString());
            FetchPlaceRequest fetchPlaceRequest = FetchPlaceRequest.builder(prediction.getPlaceId(), placeFields)
                    .build();
            placesClient.fetchPlace(fetchPlaceRequest).addOnSuccessListener((responseFechaPlace) -> {
                Place place = responseFechaPlace.getPlace();
                Log.i(LOG_TAG, "Place found: " + place.getName());
                viewModel.getDirections()
                        .add(new GeoPunto(prediction.getPrimaryText(null).toString(), "", place.getLatLng().latitude, place.getLatLng().longitude));

            }).addOnFailureListener((exception) -> {
                if (exception instanceof ApiException) {
                    ApiException apiException = (ApiException) exception;
                    int statusCode = apiException.getStatusCode();
                    // Handle error with given status code.
                    Log.e(LOG_TAG, "Place not found: " + exception.getMessage());
                }
            });
        }
        directionsAdapter.notifyDataSetChanged();
    }).addOnFailureListener((exception) -> {
        if (exception instanceof ApiException) {
            ApiException apiException = (ApiException) exception;
            Log.e(LOG_TAG, "Place not found: " + apiException.getStatusCode());
        }
    });
}

这两个依赖项可能相互冲突:

// implementation "com.google.android.libraries.places:places-compat:1.1.0"
implementation "com.google.android.libraries.places:places:1.1.0"

地方兼容包装器是普通的,不是必需的 - 最好将代码重构到新库中。

相关内容

最新更新