Доброе утро, я создал новый проект и написал пример кода для использования браузера, и он сработал.Но теперь, когда я пытаюсь скопировать его в мой основной проект, у меня ничего не получается.Ошибка выглядит следующим образом:
E / AndroidRuntime: ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основной Процесс: com.apparcago.pacea.firebase2login, PID: 5743 java.lang.NoSuchFieldError: нет статического поля навигацииПросмотр типа I вкласс Lcom / mapbox / services / android / навигация / ui / v5 / R $ id;или его суперклассы (объявление 'com.mapbox.services.android.navigation.ui.v5.R $ id' появляется в /data/app/com.apparcago.pacea.firebase2login-LSC0SaLMEkd-LbroOrauqg==/split_lib_slice_4_apk.k)в com.mapbox.services.android.navigation.ui.v5.MapboxNavigationActivity.onCreate (MapboxNavigationActivity.java:32) в android.app.Activity.performCreate (Activity.java:7098) в android.app.Activity.performCreate (Activity.java: 7089) в android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1215) в android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2768) в android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2893)на android.app.ActivityThread.-wrap11 (неизвестный источник: 0) на android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1616) на android.os.Handler.dispatchMessage (Handler.java:106) на android.os.Looper.loop (Looper.java:164) в android.app.ActivityThread.main (ActivityThread.java:6650) в java.lang.reflect.Method.invoke (собственный метод)в com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit.java:547) в com.android.internal.os.ZygoteInit.main (ZygoteInit.java:818)
Iпоказать код проекта, который не работает:
Манифест
<activity
android:name=".NavigationActivity"
android:label="@string/title_activity_navigation">
</activity>
Build.gradle (Модуль)
android {
buildToolsVersion "27.0.3"
compileSdkVersion 27
defaultConfig {
applicationId "com.apparcago.pacea.firebase2login"
minSdkVersion 24
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
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.3'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
//Facebook
implementation 'com.facebook.android:facebook-login:4.38.1'
// Para botones chulos (Fancybuttons)
implementation 'com.github.medyo:fancybuttons:1.9.0'
//Material design para Dialogs chulos
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
//ultima version me da errores
implementation 'com.google.android.gms:play-services-maps:16.0.0'
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'
// Material design de editText (Para hacer edit Text bonitos)
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
//Diseño 27
implementation 'com.android.support:design:27.1.1'
//Cardview
implementation 'com.android.support:cardview-v7:27.1.1'
//FAB
implementation 'com.nightonke:boommenu:2.1.1'
//Mapbox
//implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.0.0-alpha.2'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.23.0'
}
//Firebase
apply plugin: 'com.google.gms.google-services'
Build.gradle (проект)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()//Para mapbox
maven { url 'https://mapbox.bintray.com/mapbox' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Макет
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigationActivity">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView_mapbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="37.7749"
mapbox:mapbox_cameraTargetLng="-122.4194"
mapbox:mapbox_cameraZoom="12"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" />
<Button
android:id="@+id/startButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:enabled="false"
android:text="asd"
android:textColor="@color/colorPrimary"
mapbox:layout_constraintBottom_toBottomOf="@+id/mapView_mapbox"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
NavigationActivity
package com.apparcago.pacea.firebase2login;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class NavigationActivity extends AppCompatActivity implements OnMapReadyCallback, MapboxMap.OnMapClickListener, PermissionsListener {
private MapView mapView;
// variables for adding location layer
private MapboxMap mapboxMap;
private PermissionsManager permissionsManager;
private Location originLocation;
// variables for adding a marker
private Marker destinationMarker;
private LatLng originCoord;
private LatLng destinationCoord;
// variables for calculating and drawing a route
private Point originPosition;
private Point destinationPosition;
private DirectionsRoute currentRoute;
private static final String TAG = "DirectionsActivity";
private NavigationMapRoute navigationMapRoute;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token_mapbox));
setContentView(R.layout.activity_navigation);
mapView = findViewById(R.id.mapView_mapbox);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
enableLocationComponent();
originCoord = new LatLng(originLocation.getLatitude(), originLocation.getLongitude());
mapboxMap.addOnMapClickListener(this);
button = findViewById(R.id.startButton);
button.setOnClickListener(v -> {
boolean simulateRoute = true;
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.build();
// Call this method with Context from within an Activity
NavigationLauncher.startNavigation(NavigationActivity.this, options);
});
}
@Override
public void onMapClick(@NonNull LatLng point) {
if (destinationMarker != null) {
mapboxMap.removeMarker(destinationMarker);
}
destinationCoord = point;
destinationMarker = mapboxMap.addMarker(new MarkerOptions()
.position(destinationCoord)
);
destinationPosition = Point.fromLngLat(destinationCoord.getLongitude(), destinationCoord.getLatitude());
originPosition = Point.fromLngLat(originCoord.getLongitude(), originCoord.getLatitude());
getRoute(originPosition, destinationPosition);
button.setEnabled(true);
button.setBackgroundResource(R.color.mapboxBlue);
}
private void getRoute(Point origin, Point destination) {
NavigationRoute.builder(this)
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination)
.build()
.getRoute(new Callback<DirectionsResponse>() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
// You can get the generic HTTP info about the response
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().routes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
currentRoute = response.body().routes().get(0);
// Draw the route on the map
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, R.style.NavigationMapRoute);
}
navigationMapRoute.addRoute(currentRoute);
}
@Override
public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
Log.e(TAG, "Error: " + throwable.getMessage());
}
});
}
@SuppressWarnings( {"MissingPermission"})
private void enableLocationComponent() {
// Check if permissions are enabled and if not request
if (PermissionsManager.areLocationPermissionsGranted(this)) {
// Activate the MapboxMap LocationComponent to show user location
// Adding in LocationComponentOptions is also an optional parameter
LocationComponent locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this);
locationComponent.setLocationComponentEnabled(true);
// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING);
Location lastLocation = locationComponent.getLastKnownLocation();
originLocation = locationComponent.getLastKnownLocation();
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
Toast.makeText(this, "PRUEBA1", Toast.LENGTH_LONG).show();
}
@Override
public void onPermissionResult(boolean granted) {
if (granted) {
enableLocationComponent();
} else {
Toast.makeText(this, "PERMISOS NO ACEPTADOS", Toast.LENGTH_LONG).show();
finish();
}
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
Единственное отличие в проекте, который работает, заключается в том, что в нем меньшезависимости, так как это проект, созданный только для изучения mapbox.
Я не найду ошибку, но я думаю, что это может быть связано с gradle, какие-либо предложения?
Извините за тираду иза мой английский и заранее спасибо.