Reputation: 253
Every time i run my code i get the error:
Failed to get service from broker. java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'. at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at m.cqy.q(:com.google.android.gms.policy_maps_core_dynamite@234210309@234210304072.587101654.587101654:180) at m.cpk.run(:com.google.android.gms.policy_maps_core_dynamite@234210309@234210304072.587101654.587101654:54) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.os.HandlerThread.run(HandlerThread.java:67)
my code:
package il.co.jonathan.monstercatch.ACTIVITIES;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import il.co.jonathan.monstercatch.R;
public class Game_Activity extends FragmentActivity implements OnMapReadyCallback {
private Location currentLocation;
private LocationCallback locationCallback;
private FusedLocationProviderClient fusedClient;
private static final int REQUEST_CODE = 101;
private FrameLayout map;
private ImageView menuIcon;
private void initializeViews() {
map = findViewById(R.id.map);
menuIcon = findViewById(R.id.menuIcon);
}
private void setAdapters() {
}
private void setListeners() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
initializeViews();
setAdapters();
setListeners();
getLocation();
}
private void getLocation() {
if (ActivityCompat.checkSelfPermission(
this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(
this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION},
REQUEST_CODE);
return;
}
fusedClient = LocationServices.getFusedLocationProviderClient(this);
Task<Location> task = fusedClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
currentLocation = location;
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
if (supportMapFragment != null) {
supportMapFragment.getMapAsync(Game_Activity.this);
} else {
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.getUiSettings().setScrollGesturesEnabled(false);
LatLng latLng = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("Player");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
googleMap.addMarker(markerOptions);
}
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getLocation();
}
}
}
}
my gradle:
plugins {
id("com.android.application") version "8.2.2"
id("com.google.gms.google-services") version "4.4.0"
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.0"
}
android {
namespace = "il.co.jonathan.monstercatch"
compileSdk = 34
defaultConfig {
applicationId = "il.co.jonathan.monstercatch"
minSdk = 27
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
secrets {
propertiesFileName = "secrets.properties"
defaultPropertiesFileName = "local.defaults.properties"
// Configure which keys should be ignored by the plugin by providing regular expressions.
// "sdk.dir" is ignored by default.
ignoreList.add("keyToIgnore") // Ignore the key "keyToIgnore"
ignoreList.add("sdk.*") // Ignore all keys matching the regexp "sdk.*"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding = true
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation(project(":VIEWMODEL"))
implementation(project(":MODEL"))
implementation(project(":HELPER"))
implementation("androidx.navigation:navigation-fragment:2.7.6")
implementation("androidx.navigation:navigation-ui:2.7.6")
implementation("com.google.android.gms:play-services-maps:18.2.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("com.google.android.gms:play-services-location:21.1.0")
implementation("com.google.android.gms:play-services-gcm:17.0.0")
}
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="il.co.jonathan.monstercatch">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MonsterCatch"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="my api" />
<activity
android:name=".ACTIVITIES.Game_Activity"
android:exported="false"
android:label="@string/title_activity_game" />
<activity
android:name=".ACTIVITIES.SignUpActivity2"
android:exported="false"
android:label="@string/title_activity_sign_up2"
android:theme="@style/Theme.MonsterCatch" />
<activity
android:name=".ACTIVITIES.LogInActivity2"
android:exported="false" />
<activity
android:name=".ACTIVITIES.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
a solution to my problem
Upvotes: 24
Views: 14747
Reputation: 54
I had the same error and in my case, the solution was install the Google Repository and Google Play Services.
In android studio go to: Tools > SDK Manager > SDK Tools
Select the Google Repository and Google Play Services click apply, wait to install and click ok
Example:
Upvotes: 1
Reputation: 2869
I use a code that ensure that the app uses the latest security protocols (like TLSv1.2) for network communication. It uses ProviderInstaller to dynamically install the latest security provider from Google Play Services if it’s not already present. And this code that generate the error: Failed to get service from broker
So in my case i comment the code and the error is gone.
Upvotes: 0
Reputation: 11
java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'.
It is an API key issue, make sure you added it to Manifest
and secrets.properties
/local.defaults.properties
files. You also need to enable Android SDK and the API KEY in google developer console.
Upvotes: -1