我正在开发 taksi 应用程序,当我运行应用程序时,我遇到以下异常
Unable to update local snapshot for com.google.android.libraries.consentverifier#com.example.starttaksi, may result in stale flags.
java.util.concurrent.ExecutionException: java.lang.SecurityException: GoogleCertificatesRslt: not allowed: pkg=com.example.starttaksi, sha256=[f77957bb7143c0754d3c5e22d6c03f0af501037c4a3a8423ada13308aa8eaa05], atk=false, ver=234414038.true (go/gsrlt)
at m.apa.s(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):21)
at m.apa.get(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):5)
at m.aqk.g(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):9)
at m.yy.c(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):1)
at m.zf.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):5)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.SecurityException: GoogleCertificatesRslt: not allowed: pkg=com.example.starttaksi, sha256=[f77957bb7143c0754d3c5e22d6c03f0af501037c4a3a8423ada13308aa8eaa05], atk=false, ver=234414038.true (go/gsrlt)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3023)
at android.os.Parcel.createException(Parcel.java:3007)
at android.os.Parcel.readException(Parcel.java:2990)
at android.os.Parcel.readException(Parcel.java:2932)
at m.fe.c(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):11)
at m.sg.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):39)
at m.jr.e(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):11)
at m.kp.u(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):10)
at m.kp.v(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):22)
at m.kp.e(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):16)
at m.kt.handleMessage(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):774)
在我的 MainFragment 下面,我实现了谷歌地图逻辑
@AndroidEntryPoint
class MainFragment : Fragment(R.layout.fragment_main), OnMapReadyCallback {
private val binding by viewBinding(FragmentMainBinding::bind)
private lateinit var map: GoogleMap
private var locationPermissionGranted: Boolean = false
private var lastKnownLocation: Location? = null
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
companion object {
val REQUEST_CODE_LOCATION = 32
private const val DEFAULT_ZOOM = 15
private const val PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.mapView.onCreate(savedInstanceState)
binding.mapView.getMapAsync(this)
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(requireActivity())
}
override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
if (ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
requireActivity(), arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
REQUEST_CODE_LOCATION
)
return
}
locationPermissionGranted = true
map.isMyLocationEnabled = true
getDeviceLocation()
}
private fun getDeviceLocation() {
try {
if (locationPermissionGranted) {
val locationResult = fusedLocationProviderClient.lastLocation
locationResult.addOnCompleteListener(requireActivity()) { task ->
if (task.isSuccessful) {
lastKnownLocation = task.result
if (lastKnownLocation != null) {
map.moveCamera(
CameraUpdateFactory.newLatLngZoom(
LatLng(
lastKnownLocation!!.latitude,
lastKnownLocation!!.longitude
), DEFAULT_ZOOM.toFloat()
)
)
}
}
}
}
} catch (e: SecurityException) {
}
}
}
我想知道我在哪里犯了错误,我必须做什么才能解决这个问题 我也尝试了所有 StackOverflow 建议和答案,也尝试了所有可能的解决方案
您缺少 API 密钥,或者至少没有在那里注册您的密钥库的 SHA 哈希值。
https://developers.google.com/maps/documentation/android-sdk/get-api-key