Skip to content

Commit fcd22cb

Browse files
dboydorgilbox
authored andcommitted
- Clarified what happens with "react-native link" command (react-native-maps#904)
- Updated descriptions of getting and using Android API Keys. It works differently than when this was originally written. - Added fix for DexException - Added "import" in map component code
1 parent d9303c6 commit fcd22cb

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

docs/installation.md

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ First, download the library from npm:
66
npm install react-native-maps --save
77
```
88

9-
Then you must install the native dependencies: You can use `rnpm` (now part of `react-native` core) to
9+
Second, install the native dependencies: You can use `rnpm` (now part of `react-native` core via `link`) to
1010
add native dependencies automatically then continue the directions below depending on your target OS.
1111

12-
`$ react-native link`
12+
```
13+
react-native link
14+
```
1315

1416
>This installation should work in physical devices. For Genymotion, be sure to check Android installation about Google Play Services
1517
1618
## iOS
1719

1820
### Option 1: CocoaPods - Same as the included AirMapsExplorer example
1921

20-
1. Setup your `Podfile` like the included [example/ios/Podfile](../example/ios/Podfile) then run `pod install`.
22+
1. Setup your `Podfile` like the included [example/ios/Podfile](../example/ios/Podfile), replace all references to `AirMapExplorer` with your project name, and then run `pod install`.
2123
(If you do not need `GoogleMaps` support for iOS, then you can probably completely skip this step.)
2224
1. Open your project in Xcode workspace
2325
1. Drag the following folder into your project:
@@ -44,6 +46,8 @@ Now if you need `GoogleMaps` support you will also have to add a bunch of other
4446
After your `Podfile` is setup properly, run `pod install`.
4547

4648
### Option 3: Manually
49+
>This was already done for you if you ran "react-native link"
50+
4751
1. Open your project in Xcode, right click on `Libraries` and click `Add
4852
Files to "Your Project Name"` Look under `node_modules/react-native-maps/ios` and add `AIRMaps.xcodeproj`.
4953
1. Add `libAIRMaps.a` to `Build Phases -> Link Binary With Libraries.
@@ -60,6 +64,8 @@ After your `Podfile` is setup properly, run `pod install`.
6064
## Android
6165

6266
1. In your `android/app/build.gradle` add:
67+
>This step is not necessary if you ran "react-native link"
68+
6369
```groovy
6470
...
6571
dependencies {
@@ -69,16 +75,18 @@ After your `Podfile` is setup properly, run `pod install`.
6975
```
7076

7177
1. In your `android/settings.gradle` add:
78+
>This step is not necessary if you ran "react-native link"
79+
7280
```groovy
7381
...
7482
include ':react-native-maps'
7583
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android')
7684
```
7785

7886
1. Specify your Google Maps API Key:
79-
> For development, it is recommended to use a ***Browser Key*** without referrer restrictions. Go to https://console.developers.google.com/apis/credentials to check your credentials.
87+
> For development, you need to get a ***API Key***. Go to https://console.developers.google.com/apis/credentials to check your credentials.
8088
81-
Add your **Browser** API key to your manifest file (`android\app\src\main\AndroidManifest.xml`):
89+
Add your API key to your manifest file (`android\app\src\main\AndroidManifest.xml`):
8290

8391
```xml
8492
<application>
@@ -87,18 +95,6 @@ After your `Podfile` is setup properly, run `pod install`.
8795
android:name="com.google.android.geo.API_KEY"
8896
android:value="Your Google maps API Key Here"/>
8997
</application>
90-
```
91-
> If that doesn't work, try using an ***Android Key*** without referrer restrictions. Go to https://console.developers.google.com/apis/credentials to check your credentials.
92-
93-
Add your **Android** API key to your manifest file:
94-
95-
```xml
96-
<application>
97-
<!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
98-
<meta-data
99-
android:name="com.google.android.maps.v2.API_KEY"
100-
android:value="{{@string/ANDROID_GOOGLE_MAPS_API_KEY}}"/>
101-
</application>
10298
```
10399
> Note: As shown above, com.google.android.geo.API_KEY is the recommended metadata name for the API key. A key with this name can be used to authenticate to multiple Google Maps-based APIs on the Android platform, including the Google Maps Android API. For backwards compatibility, the API also supports the name com.google.android.maps.v2.API_KEY. This legacy name allows authentication to the Android Maps API v2 only. An application can specify only one of the API key metadata names. If both are specified, the API throws an exception.
104100
Source: https://developers.google.com/maps/documentation/android-api/signup
@@ -115,12 +111,14 @@ If you have a blank map issue, ([#118](https://github.com/airbnb/react-native-ma
115111

116112
You have to link dependencies with rnpm and re-run the build:
117113

118-
1. `rnpm link`
114+
1. `react-native link`
119115
1. `react-native run-ios`
120116

121117
### On Android:
122118

123119
1. Be sure to have `new MapsPackage()` in your `MainApplication.java` :
120+
>This step is not necessary if you ran "react-native link"
121+
124122
```
125123
import com.airbnb.android.react.maps.MapsPackage;
126124
...
@@ -135,6 +133,7 @@ You have to link dependencies with rnpm and re-run the build:
135133

136134
1. Set this Stylesheet in your map component
137135
```
136+
import MapView from 'react-native-maps';
138137
...
139138
const styles = StyleSheet.create({
140139
container: {
@@ -171,26 +170,30 @@ You have to link dependencies with rnpm and re-run the build:
171170
}
172171
}
173172
```
174-
1. Run "android" and make sure every packages is updated.
173+
1. Run "android" and make sure all packages are up-to-date.
175174
1. If not installed yet, you have to install the following packages :
176175
- Extras / Google Play services
177176
- Extras / Google Repository
178-
- Android 6.0 (API 23) / Google APIs Intel x86 Atom System Image Rev. 13
179-
1. Check manual installation steps
180-
1. Generate your SHA1 key :
181-
`keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android`
182-
183-
1. Go to [Google API Console](https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend) and select your project, or create one.
184-
In `Overview -> Google Maps API -> Google Maps Android API ` -> Check if it's enabled
185-
Create a new key by clicking on `Create credentials -> API Key -> Android Key`, enter the name of the API key and your SHA1 key, generated before, and create it.
186-
Check installation step 4.
187-
188-
1. Clean the cache :
189-
`watchman watch-del-all`
190-
`npm cache clean`
177+
- Android 6.0 (API 23) / Google APIs Intel x86 Atom System Image Rev. 19
178+
1. Check manual installation steps if you didn't run "react-native link"
179+
1. Go to [Google API Console](https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend) and select your project, or create one.
180+
Then, once enabled, select `Go to credentials`.
181+
Select `Google Maps Android API` and create a new key.
182+
Enter the name of the API key and create it.
183+
184+
1. Clean the cache :
185+
```
186+
watchman watch-del-all
187+
npm cache clean
188+
```
191189

192190
1. When starting emulator, make sure you have enabled `Wipe user data`.
193191

194192
1. Run `react-native run-android`
195193

196-
1. At this step it should work, but if not, go to your [Google API Console](https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&pli=1) and create a `Browser key` instead of a `Android key` and go to step 6.
194+
1. If you encounter `com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim`, then clear build folder.
195+
```
196+
cd android
197+
gradlew clean
198+
cd ..
199+
```

0 commit comments

Comments
 (0)