xref: /expo/packages/@expo/config-plugins/src/android/GoogleMapsApiKey.ts (revision e330c216)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { ExpoConfig } from '@expo/config-types';
2
3import { createAndroidManifestPlugin } from '../plugins/android-plugins';
4import {
5  addMetaDataItemToMainApplication,
6  addUsesLibraryItemToMainApplication,
7  AndroidManifest,
8  getMainApplicationOrThrow,
9  removeMetaDataItemFromMainApplication,
10  removeUsesLibraryItemFromMainApplication,
11} from './Manifest';
12
13const META_API_KEY = 'com.google.android.geo.API_KEY';
14const LIB_HTTP = 'org.apache.http.legacy';
15
16export const withGoogleMapsApiKey = createAndroidManifestPlugin(
17  setGoogleMapsApiKey,
18  'withGoogleMapsApiKey'
19);
20
21export function getGoogleMapsApiKey(config: Pick<ExpoConfig, 'android'>) {
22  return config.android?.config?.googleMaps?.apiKey ?? null;
23}
24
25export function setGoogleMapsApiKey(
26  config: Pick<ExpoConfig, 'android'>,
27  androidManifest: AndroidManifest
28) {
29  const apiKey = getGoogleMapsApiKey(config);
30  const mainApplication = getMainApplicationOrThrow(androidManifest);
31
32  if (apiKey) {
33    // If the item exists, add it back
34    addMetaDataItemToMainApplication(mainApplication, META_API_KEY, apiKey);
35    addUsesLibraryItemToMainApplication(mainApplication, {
36      name: LIB_HTTP,
37      required: false,
38    });
39  } else {
40    // Remove any existing item
41    removeMetaDataItemFromMainApplication(mainApplication, META_API_KEY);
42    removeUsesLibraryItemFromMainApplication(mainApplication, LIB_HTTP);
43  }
44
45  return androidManifest;
46}
47

served by {OpenGrok

Last Index Update: Tue Oct 21 18:42:31 GMT 2025