Failed to get service from broker. Unknown calling package name 'com.google.android.gms'
Asked Answered
A

1

8

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@[email protected]:180) at m.cpk.run(:com.google.android.gms.policy_maps_core_dynamite@[email protected]: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

Alvira answered 4/2 at 10:7 Comment(6)
Same problem... did you solve it? BTW you forgot to delete your API key from the posted code...Coniine
thx i deleted my api but i couldnt find a solution...Alvira
Do you find a solution to this error?Searching
Probably here is the solution #77947261Checkrow
Yeah this issue is driving me insane, I still dont understand what is causing it, any ideas guys?Vendor
I've been getting this the past week or so. Also happening with old versions built years ago, so nothing to do with the APK itself. Perhaps a Google Services update on the device. BTW, I'm testing from India, so could that be the issue?Creaturely
O
0
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.

Oldie answered 23/2 at 20:46 Comment(2)
I edited in the names of the property files.Acidfast
this is my secret.properties ` MAPS_API_KEY=correct value ` this i my local.properties ` ## This file must NOT be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. #Wed Jan 24 13:42:18 IST 2024 sdk.dir=C\:\\Users\\jonat\\AppData\\Local\\Android\\Sdk `Alvira

© 2022 - 2024 — McMap. All rights reserved.