1-. Use case.
I’m using the google_maps_flutter package, in a Flutter and Dart project. Version is google_maps_flutter: ^2.4.0
When I call to the GoogleMaps widget in Flutter:
the following SecurityException is thrown:
E/GoogleApiManager( 5028): Failed to get service from broker.
E/GoogleApiManager( 5028): java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'.
E/GoogleApiManager( 5028): at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
E/GoogleApiManager( 5028): at android.os.Parcel.createException(Parcel.java:2995)
E/GoogleApiManager( 5028): at android.os.Parcel.readException(Parcel.java:2978)
E/GoogleApiManager( 5028): at android.os.Parcel.readException(Parcel.java:2920)
E/GoogleApiManager( 5028): at m.cpc.q(:com.google.android.gms.policy_maps_core_dynamite@[email protected]:180)
E/GoogleApiManager( 5028): at m.cno.run(:com.google.android.gms.policy_maps_core_dynamite@[email protected]:54)
E/GoogleApiManager( 5028): at android.os.Handler.handleCallback(Handler.java:942)
E/GoogleApiManager( 5028): at android.os.Handler.dispatchMessage(Handler.java:99)
E/GoogleApiManager( 5028): at android.os.Looper.loopOnce(Looper.java:201)
E/GoogleApiManager( 5028): at android.os.Looper.loop(Looper.java:288)
E/GoogleApiManager( 5028): at android.os.HandlerThread.run(HandlerThread.java:67)
D/EGL_emulation( 5028): eglCreateContext: 0x7281d4cf23d0: maj 3 min 0 rcv 3
W/MobStoreFlagStore( 5028): Unable to update local snapshot for com.google.android.gms.maps#com.google.android.gms, may result in stale flags.
W/MobStoreFlagStore( 5028): java.util.concurrent.ExecutionException: m.fdz: 17: 17: API: Phenotype.API is not available on this device. Connection failed with: ckg{statusCode=DEVELOPER_ERROR, resolution=null, message=null}
W/MobStoreFlagStore( 5028): at m.gso.s(:com.google.android.gms.policy_maps_core_dynamite@[email protected]:21)
2-. Implemented API key
I followed the guide described in the google_maps_flutter package (https://pub.dev/packages/google_maps_flutter), the guide for installing Google Maps SDK in Flutter (https://developers.google.com/maps/flutter-package/config?authuser=0#step_1_install_the_required_software), and the ‘Maps SDK for Android Quickstart’ documentation (https://developers.google.com/maps/documentation/android-sdk/start) ->
i) GMP API key generated The api key related to Maps API is the fourth one ->
… with the following api key ->
… and restrictions ->
ii) the android manifest.xml is ->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:label="appname"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}"/>
</application>
</manifest>
iii) the settings.graddle is ->
iv) the secrets.properties is ->
V) the local.defaults.properties is ->
vi) the android/build.gradle is ->
vii) the app/build.gradle is ->
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-services"
id "com.google.android.libraries.mapsplatform.secrets-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "com.byroomnumber.brnapp"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.appName"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
targetSdkVersion 34
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
buildFeatures{
buildConfig true
}
}
flutter {
source '../..'
}
dependencies {
implementation platform("com.google.firebase:firebase-bom:30.7.1")
implementation("androidx.multidex:multidex:2.0.1")
implementation "com.google.firebase:firebase-analytics"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21"
implementation 'com.google.android.gms:play-services-maps:18.2.0'
}
secrets {
// Optionally specify a different file name containing your secrets.
// The plugin defaults to "local.properties"
propertiesFileName = "secrets.properties"
// A properties file containing default secret values. This file can be
// checked in version control.
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.*"
}
The map is correctly rendered in a device connected via usb, although the exception is thrown. If an apk is generated and installed on the device, the map is not rendered, and the exception is thrown.
Yes. I verified this process in a SMA426B and and a MiT11
Contacting with Google Maps Support, the problem is on their side: it is a bug.
https://issuetracker.google.com/issues/228091313
I have been informed that in next releases, the issue will be solved.