How to fix unresolved imports for Mapbox 9.5.0 in AndroidX using Java

Viewed 1830

I am in the process of creating an Android navigation application using the Mapbox SDK (version 9.5.0 currently) and I have successfully been able to initialize a map view as well as track the user's current location. Up until this point I have had no issues with unresolved import statements or any real problems. The feature I am currently working on is to allow the user to select a location point on the map, which will place a map marker on that point and return the coordinates of the marker. To incorporate this feature I have been following the Mapbox Documentation, specifically this tutorial.

Now that I have added this new code to my application I have found a few issues, there are quite a number of objects that I am trying to make use of that can not be resolved, to look into this issue I went to my import statements at the top of my java file and found a few imports that are not working properly, namely:

import com.mapbox.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;

The above imports all have a red line under "api" and give the error: " Cannot resolve symbol 'api' " . Some other erroneous imports are:

import com.mapbox.core.exceptions.ServicesException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import timber.log.Timber;

I am not sure why all of these specific imports are unresolved, as all of my other Mapbox imports haven't given me any issues yet. I suspect it might be a missing dependency or implementation in my Gradle files, but I have followed the documentation guide to be best of my ability so unless I missed something vital I am not sure what the cause might be. Here are the Mapbox dependencies and implementations that I added to my grade files: Project-level build.gradle:

maven {
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                username = 'mapbox'
                password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: "my secret password"
            }
        }

and in my app-level build.gradle:

    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0'

If anyone has an idea of what my issue could be, I would greatly appreciate any help.

2 Answers

Stick with Maps SDK 9.5.0

Not needed because you can just use regular logging (e.g. log.e rather than Timber.e), but Timber can be downloaded via: https://github.com/JakeWharton/timber#download

https://docs.mapbox.com/android/maps/examples/location-picker uses MapboxGeocoding, which is the Mapbox Java SDK's wrapper around the Mapbox Geocoding API. You need to install the services module to use MapboxGeocoding: https://docs.mapbox.com/android/java/overview/#installation & https://docs.mapbox.com/android/java/overview/#available-packages. This should resolve the

import com.mapbox.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;

and

import com.mapbox.core.exceptions.ServicesException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

Heads up that there's also the Places Plugin https://docs.mapbox.com/android/plugins/overview/places/, which has a place picker functionality (https://docs.mapbox.com/android/plugins/examples/place-picker/) that's more polished than https://docs.mapbox.com/android/maps/examples/location-picker

MAPBOX_DOWNLOADS_TOKEN="PASTE_YOUR_SECRET_TOKEN_HERE" instead of MAPBOX_DOWNLOADS_TOKEN=PASTE_YOUR_SECRET_TOKEN_HERE.

Just try this, in my case the quotes was the problem .Just removed quotes and it worked

Related