Search code examples
androidgoogle-mapsnativescriptandroidxnativescript-angular

After upgrading to Nativescript 6 with AndroidX support Google map stopped working in Android


Before the upgrade to Nativescript 6, everything worked perfectly. After that, whithout any changes to configuration, Android started to throw exception while loading MapView:

ERROR Error: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
JS:     com.google.maps.api.android.lib6.drd.p.b(:com.google.android.gms.dynamite_mapsdynamite@18385084@18.3.85 (100700-262677519):22)
JS:     com.google.maps.api.android.lib6.auth.d.a(:com.google.android.gms.dynamite_mapsdynamite@18385084@18.3.85 (100700-262677519):10)
JS:     com.google.maps.api.android.lib6.impl.d.a(:com.google.android.gms.dynamite_mapsdynamite@18385084@18.3.85 (100700-262677519):41)
JS:     com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.dynamite_mapsdynamite@18385084@18.3.85 (100700-262677519):61)
JS:     com.google.android.gms.maps.internal.CreatorImpl.newMapViewDelegate(:com.google.android.gms.dynamite_mapsdynamite@18385084@18.3.85 (100700-262677519):32)
JS:     com.google.android.gms.maps.internal.h.a(:com.google.android.gms.dynamite_mapsdynamite@18385084@18.3.85 (100700...

I have the key in AndroidManifest.xml inside "application" tag as described in manual for "nativescript-google-maps-sdk"

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="200000"
    xmlns:tools="http://schemas.android.com/tools"
    android:versionName="2.0.0">

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <uses-sdk
        android:minSdkVersion="22"
        android:targetSdkVersion="28"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


    <application
        android:name="Blahaha"
        android:launchMode="singleInstance"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        tools:replace="android:supportsRtl">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/nativescript_google_maps_api_key"/>
    </application>
</manifest>

Also tried to write the key directly in to meta-data tag:

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIza**********************"/>

My app.gradle is:

android {  
  defaultConfig {  
    generatedDensities = []
    applicationId = "com.app.app" 
    renderscriptTargetApi 25
    renderscriptSupportModeEnabled true 
  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
} 

project.ext {
    googlePlayServicesVersion = "+"
}

dependencies {
    def googlePlayServicesVersion = project.googlePlayServicesVersion
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
}

And plugin version in package.json:

"nativescript-google-maps-sdk": "^2.7.0"

My poject is Angular based.


Solution

  • After migrating to NativeScript 6, AndroidManifest.xml file remained where it was before - at ./App_Resources/Android/. Moving it to ./App_Resources/Android/src/main/ solved the issue.