gpt4 book ai didi

java - 将 firebase 添加到应用程序时出现 appcompat 依赖项错误

转载 作者:行者123 更新时间:2023-11-30 12:03:57 26 4
gpt4 key购买 nike

我开发了一个简单的应用程序,在按下按钮后显示设备的 IMEI 以及纬度和经度。现在,我想将此数据(纬度、经度、IMEI)保存在 FireStore 中,我有一些理解问题,我应该在哪里以及如何将这些数据保存到 firestore 中。当我尝试通过工具将实时 firebase 添加到我的应用程序时,我遇到了一些错误

我已尝试更改依赖项版本,但无法解决问题。

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;

}

这些是错误

    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:firebase-database@16.0.4
-- 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-
location@11.0.1

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.

最佳答案

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)

问题是最新的 firebase 和 play-services 依赖被迁移到了 androidx。所以一个修复是将您的项目迁移到 androidx,请参阅 migrate to androidx (我更喜欢,因为所有新升级都使用 androidx)。或者您可以将 firebase-core 和 play 服务降级到此更新之前的版本。

关于java - 将 firebase 添加到应用程序时出现 appcompat 依赖项错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57357568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com