appcompat dependencies error when add firebase to app

Tudor Stanciulescu :

I develop a simple app that shows me the IMEI of the device and the Latitude and Longitude after pressing a button. Now, I want to save this data (lat, long, IMEI) in FireStore, and I have some understanding problem where and what should I do to save this data into firestore. When I try I add realtime firebase to my app from tools I have some errors

I have tried to change the dependencies version but it's not fixing the problem.

package com.example.locatieimei;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

private FusedLocationProviderClient client;
private TextView imei;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imei = findViewById(R.id.imei);
    loadIMEI();






    client = LocationServices.getFusedLocationProviderClient(this);
    Button button = findViewById(R.id.Chk);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ActivityCompat.checkSelfPermission(MainActivity.this, 
 Manifest.permission.ACCESS_FINE_LOCATION) != 
 PackageManager.PERMISSION_GRANTED && 
 ActivityCompat.checkSelfPermission(MainActivity.this, 
 Manifest.permission.ACCESS_COARSE_LOCATION) != 
 PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then 
overriding
                //   public void onRequestPermissionsResult(int 
requestCode, String[] permissions,
                //                                          int[] 
grantResults)
                 // to handle the case where the user grants the 
permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            client.getLastLocation().addOnSuccessListener(new 
OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    if (location!=null){
                        TextView textView = findViewById(R.id.textView);

                        Double longitude = location.getLongitude();
                        Double latitude = location.getLatitude();

textView.setText(String.valueOf("latitudine"+longitude+ 
"\n"+"longitutine"+latitude));

                    }
                }
            });



        }

    });

}
public void loadIMEI() {
    // Check if the READ_PHONE_STATE permission is already available.
    if (ActivityCompat.checkSelfPermission(this, 
Manifest.permission.READ_PHONE_STATE)
            != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_PHONE_STATE)) {
//                get_imei_data();
        } else {
            ActivityCompat.requestPermissions(this, new String[] 
{Manifest.permission.READ_PHONE_STATE},
                    MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);
        }
    } else {

        TelephonyManager mngr = 
 (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

        IMEI = mngr.getDeviceId();

        imei.setText(mngr.getDeviceId());
        // READ_PHONE_STATE permission is already been granted.


    }
}
private String device_unique_id;
private static String IMEI;
private static final int MY_PERMISSIONS_REQUEST_READ_PHONE_STATE = 0;

}

those are the errors

    ERROR: In project 'app' a resolved Google Play services library dependency 
    depends on another at an exact version (e.g. "[11.0.
    1]", but isn't being resolved to that version. Behavior exhibited by the 
    library will be unknown.

    Dependency failing: com.google.android.gms:play-services-location:11.0.1 - 
    > com.google.android.gms:play-services-tasks@[
    11.0.1], but play-services-tasks version was 16.0.1.

    The following dependencies are project dependencies that are direct or 
    have transitive dependencies that lead to the art
    ifact with the issue.
    -- Project 'app' depends onto com.google.firebase:firebase- 
    database@{strictly 16.0.4}
    -- Project 'app' depends onto com.google.android.gms:play-services- 
    base@{strictly 16.0.1}
    -- Project 'app' depends onto com.google.android.gms:play-services- 
    tasks@{strictly 16.0.1}
    -- Project 'app' depends onto com.google.firebase:[email protected]
    -- Project 'app' depends onto com.google.firebase:firebase- 
    common@{strictly 16.0.3}
    -- Project 'app' depends onto com.google.android.gms:play-services- 
    location@{strictly 11.0.1}
    -- Project 'app' depends onto com.google.android.gms:play-services- 
    [email protected]

    For extended debugging info execute Gradle from the command line with 
    ./gradlew --info :app:assembleDebug to see the dep
    endency paths to the artifact. This error message came from the google- 
    services Gradle plugin, report issues at https://
    github.com/google/play-services-plugins and disable by adding 
    "googleServices { disableVersionCheck = false }" to your b
    uild.gradle file.

 And if i change to 17.0.0 version from 11.0.1 in 'com.google.android.gms:play- 
services-location:17.0.0' the it is showing the following error

    ERROR: Manifest merger failed : Attribute application@appComponentFactory 
    value=(android.support.v4.app.CoreComponentFactory) from 
    [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 
    value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to 
    <application> element at AndroidManifest.xml:10:5-24:19 to override.

sanoJ :

This release is a MAJOR version update and breaking change.

The latest update to Google Play services and Firebase includes the following changes:

Migration from Android Support Libraries to Jetpack (AndroidX) Libraries. Libraries will not work unless you make the following changes in your app:

  • Upgrade com.android.tools.build:gradle to v3.2.1 or later.
  • Upgrade compileSdkVersion to 28 or later.
  • Update your app to use Jetpack

(AndroidX); follow the instructions in Migrating to AndroidX.

Firebase Bill of Materials (BoM)

The problem is the latest firebase and play-services dependencies are migrated to androidx. So one fix is to migrate your project to androidx, see migrate to androidx (which I prefer because all the new upgrades are using androidx). Or else you can downgrade the firebase-core and play services to version before this update.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=162101&siteId=1