blob: 125f98061e6981a8480575161f187f3605b53935 [file] [log] [blame] [view]
jbudorick900a8d832016-07-18 18:56:051# Android Studio
2
jbudorick900a8d832016-07-18 18:56:053[TOC]
4
5## Usage
6
7```shell
agrieve0c28e4f2016-09-22 01:05:208build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --target //chrome/android:chrome_public_test_apk
jbudorick900a8d832016-07-18 18:56:059```
10
11This creates a project at `out-gn/Debug/gradle`. To create elsewhere: `--project-dir foo`
12
agrieve0c28e4f2016-09-22 01:05:2013For first-time Android Studio users:
14
15 * Avoid running the setup wizard.
16 * The wizard will force you to download unwanted SDK componentns to `//third_party/android_tools`.
17 * To skip it. Select "Cancel" when it comes up.
18
19To import the project:
20
21 * Use "Import Project", and select the directory containing the generated project.
22
23You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change.
24
25 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't, use:
26 * Help->Find Action->Sync Project with Gradle Files
27
28
29## How it Works
30
31Android Studio integration works by generating `build.gradle` files based on GN
32targets. Each `android_apk` and `android_library` target produces a separate
33Gradle sub-project.
34
35### Symlinks and .srcjars
36
37Gradle supports source directories but not source files. However, some
38`java/src/` directories in Chromium are split amonst multiple GN targets. To
39accomodate this, the script detects such targets and creates a `symlinked-java/`
40directory to point gradle at. Be warned that creating new files from Android
41Studio within these symlink-based projects will cause new files to be created in
42the generated `symlinked-java/` rather than the source tree where you want it.
43
44*** note
45** TLDR:** Always create new files outside of Android Studio.
46***
47
48Most generated .java files in GN are stored as `.srcjars`. Android Studio does
49not have support for them, and so the generator script builds and extracts them
50all to `extracted-srcjars/` subdirectories for each target that contains them.
51
52*** note
53** TLDR:** Always re-generate project files when `.srcjars` change (this
54includes `R.java`).
55***
56
57### Building with Gradle
58
59Gradle builds can be done from the command-line after importing the project into
60Android Studio (importing into the IDE causes the Gradle wrapper to be added).
61
62 cd $GRADLE_PROJECT_DIR && bash gradlew
63
64The resulting artifacts are not terribly useful. They are missing assets,
65resources, native libraries, etc.
66
67## Status (as of Sept 21, 2016)
jbudorick900a8d832016-07-18 18:56:0568
69### What currently works
70
agrieve0c28e4f2016-09-22 01:05:2071 * Tested with Android Studio v2.2.
72 * Basic Java editing and compiling works.
jbudorick900a8d832016-07-18 18:56:0573
74### Roadmap / what's not yet implemented ([crbug](https://bugs.chromium.org/p/chromium/issues/detail?id=620034))
75
agrieve0c28e4f2016-09-22 01:05:2076 * JUnit Test targets
77 * Better support for instrumtation tests (they are treated as non-test .apks right now)
78 * Make gradle aware of resources and assets
79 * Make gradle aware of native code via pointing it at the location of our .so
80 * Add a mode in which gradle is responsible for generating `R.java`
81 * Add support for native code editing
82 * Make the "Make Project" button work correctly
jbudorick900a8d832016-07-18 18:56:0583
84## Android Studio Tips
85
agrieve0c28e4f2016-09-22 01:05:2086 * Configuration instructions can be found [here](http://tools.android.com/tech-docs/configuration). One suggestions:
87 * Launch it with more RAM: `STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-stable/bin/studio-launcher.sh`
88 * If you ever need to reset it: `rm -r ~/.AndroidStudio*/`
89
90### Useful Shortcuts
91
92 * `Shift - Shift`: Search to open file or perform IDE action
93 * `Ctrl + N`: Jump to class
94 * `Ctrl + Shift + T`: Jump to test
95 * `Ctrl + Shift + N`: Jump to file
96 * `Ctrl + F12`: Jump to method
97 * `Ctrl + G`: Jump to line
98 * `Shift + F6`: Rename variable
99 * `Ctrl + Alt + O`: Organize imports
100 * `Alt + Enter`: Quick Fix (use on underlined errors)
jbudorick900a8d832016-07-18 18:56:05101