import { ExpoConfig } from '@expo/config-types' ; import { createAndroidManifestPlugin } from '../plugins/android-plugins' ; import { addMetaDataItemToMainApplication , addUsesLibraryItemToMainApplication , AndroidManifest , getMainApplicationOrThrow , removeMetaDataItemFromMainApplication , removeUsesLibraryItemFromMainApplication , } from './Manifest' ; const META_API_KEY = 'com.google.android.geo.API_KEY' ; const LIB_HTTP = 'org.apache.http.legacy' ; export const withGoogleMapsApiKey = createAndroidManifestPlugin ( setGoogleMapsApiKey , 'withGoogleMapsApiKey' ) ; export function getGoogleMapsApiKey ( config ) { return config . android ?. config ?. googleMaps ?. apiKey ?? null ; } export function setGoogleMapsApiKey ( config , androidManifest ) { const apiKey = getGoogleMapsApiKey ( config ) ; const mainApplication = getMainApplicationOrThrow ( androidManifest ) ; if ( apiKey ) { addMetaDataItemToMainApplication ( mainApplication , META_API_KEY , apiKey ) ; addUsesLibraryItemToMainApplication ( mainApplication , { name : LIB_HTTP , required : false } ) ; } else { removeMetaDataItemFromMainApplication ( mainApplication , META_API_KEY ) ; removeUsesLibraryItemFromMainApplication ( mainApplication , LIB_HTTP ) ; } return androidManifest ; }