Skip to content

Commit 13f011c

Browse files
author
Eric
committed
Add setup guide
主要记录下android-sdk的安装方法与位置
1 parent 8925599 commit 13f011c

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

DevelopmentSetupAndroid.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
id: android-setup
3+
title: Android Setup
4+
layout: docs
5+
category: Quick Start
6+
permalink: docs/android-setup.html
7+
next: linux-windows-support
8+
---
9+
10+
This guide describes basic steps of the Android development environment setup that are required to run React Native android apps on an android emulator. We don't discuss developer tool configuration such as IDEs here.
11+
12+
### Install Git
13+
14+
- **On Mac**, if you have installed [XCode](https://developer.apple.com/xcode/), Git is already installed, otherwise run the following:
15+
16+
brew install git
17+
18+
- **On Linux**, install Git [via your package manager](https://git-scm.com/download/linux).
19+
20+
- **On Windows**, download and install [Git for Windows](https://git-for-windows.github.io/). During the setup process, choose "Run Git from Windows Command Prompt", which will add Git to your `PATH` environment variable.
21+
22+
### Install the Android SDK (unless you have it)
23+
24+
1. [Install the latest JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
25+
2. Install the Android SDK:
26+
- **On Mac**: `brew install android-sdk`
27+
- **On Linux and Windows**: [Download from the Android website](https://developer.android.com/sdk/installing/index.html)
28+
29+
### Define the ANDROID_HOME environment variable
30+
31+
__IMPORTANT__: Make sure the `ANDROID_HOME` environment variable points to your existing Android SDK:
32+
33+
- **On Mac**, add this to your `~/.bashrc`, `~/.bash_profile` or whatever your shell uses:
34+
35+
# If you installed the SDK via Homebrew, otherwise ~/Library/Android/sdk
36+
export ANDROID_HOME=/usr/local/opt/android-sdk
37+
- **On Linux**, add this to your `~/.bashrc`, `~/.bash_profile` or whatever your shell uses:
38+
39+
export ANDROID_HOME=<path_where_you_unpacked_android_sdk>
40+
41+
- **On Windows**, go to `Control Panel` -> `System and Security` -> `System` -> `Change settings` -> `Advanced` -> `Environment variables` -> `New`
42+
43+
__NOTE__: You need to restart the Command Prompt (Windows) / Terminal Emulator (Mac OS X, Linux) to apply the new Environment variables.
44+
45+
46+
### Use gradle daemon
47+
48+
React Native Android use [gradle](https://docs.gradle.org) as a build system. We recommend to enable gradle daemon functionality which may result in up to 50% improvement in incremental build times for changes in java code. Learn [here](https://docs.gradle.org/2.9/userguide/gradle_daemon.html) how to enable it for your platform.
49+
50+
### Configure your SDK
51+
52+
1. Open the Android SDK Manager (**on Mac** start a new shell and run `android`); in the window that appears make sure you check:
53+
* Android SDK Build-tools version 23.0.1
54+
* Android 6.0 (API 23)
55+
* Android Support Repository
56+
2. Click "Install Packages"
57+
58+
![SDK Manager window](http://reactnativeguide.github.io/RNGuideiOS/img/AndroidSDK1.png) ![SDK Manager window](http://reactnativeguide.github.io/RNGuideiOS/img/AndroidSDK2.png)
59+
60+
### Install Genymotion
61+
62+
Genymotion is much easier to set up than stock Google emulators. However, it's only free for personal use. If you want to use the stock Google emulator, see below.
63+
64+
1. Download and install [Genymotion](https://www.genymotion.com/).
65+
2. Open Genymotion. It might ask you to install VirtualBox unless you already have it.
66+
3. Create a new emulator and start it.
67+
4. To bring up the developer menu press ⌘+M
68+
69+
### Alternative: Create a stock Google emulator
70+
71+
1. Start a new shell and run `android`; in the window that appears make sure you check:
72+
* Intel x86 Atom System Image (for Android 5.1.1 - API 22)
73+
* Intel x86 Emulator Accelerator (HAXM installer)
74+
2. Click "Install Packages".
75+
3. [Configure hardware acceleration (HAXM)](http://developer.android.com/tools/devices/emulator.html#vm-mac), otherwise the emulator is going to be slow.
76+
4. Create an Android Virtual Device (AVD):
77+
1. Run `android avd` and click on **Create...**
78+
![Create AVD dialog](http://reactnativeguide.github.io/RNGuideiOS/img/CreateAVD.png)
79+
2. With the new AVD selected, click `Start...`
80+
5. To bring up the developer menu press F2 (or install [Frappé](http://getfrappe.com))
81+
82+
### Windows Hyper-V Alternative
83+
84+
The [Visual Studio Emulator for Android](https://www.visualstudio.com/en-us/features/msft-android-emulator-vs.aspx) is a free android emulator that is hardware accelerated via Hyper-V. It doesn't require you to install Visual Studio at all.
85+
86+
To use it with react-native you just have to add a key and value to your registry:
87+
88+
1. Open the Run Command (Windows+R)
89+
2. Enter `regedit.exe`
90+
3. In the Registry Editor navigate to `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools`
91+
4. Right Click on `Android SDK Tools` and choose `New > String Value`
92+
5. Set the name to `Path`
93+
6. Double Click the new `Path` Key and set the value to `C:\Program Files\Android\sdk`. The path value might be different on your machine.
94+
95+
You will also need to run the command `adb reverse tcp:8081 tcp:8081` with this emulator.
96+
97+
Then restart the emulator and when it runs you can just do `react-native run-android` as usual.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# RNGuideAndroid
22
React Native 入门指南及原理解析 Android
3+
4+
使用[DevelopmentSetupAndroid](https://github.com/ReactNativeGuide/RNGuideAndroid/blob/master/DevelopmentSetupAndroid.md)的方式安装了android-sdk.

0 commit comments

Comments
 (0)