OLD | NEW |
1 # Android Studio | 1 # Android Studio |
2 | 2 |
3 [TOC] | 3 [TOC] |
4 | 4 |
5 ## Usage | 5 ## Usage |
6 | 6 |
7 ```shell | 7 ```shell |
8 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --target
//chrome/android:chrome_public_test_apk | 8 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --target
//chrome/android:chrome_public_test_apk |
9 ``` | 9 ``` |
10 | 10 |
11 This creates a project at `out-gn/Debug/gradle`. To create elsewhere: `--project
-dir foo` | 11 This creates a project at `out-gn/Debug/gradle`. To create elsewhere: `--project
-dir foo` |
12 | 12 |
13 For first-time Android Studio users: | 13 For first-time Android Studio users: |
14 | 14 |
15 * Avoid running the setup wizard. | 15 * Avoid running the setup wizard. |
16 * The wizard will force you to download unwanted SDK componentns to `//third
_party/android_tools`. | 16 * The wizard will force you to download unwanted SDK components to `//third_
party/android_tools`. |
17 * To skip it. Select "Cancel" when it comes up. | 17 * To skip it, select "Cancel" when it comes up. |
18 | 18 |
19 To import the project: | 19 To import the project: |
20 | 20 |
21 * Use "Import Project", and select the directory containing the generated proje
ct. | 21 * Use "Import Project", and select the directory containing the generated proje
ct. |
22 | 22 |
23 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. | 23 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. |
24 | 24 |
25 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't
, use: | 25 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't
, use: |
26 * Help->Find Action->Sync Project with Gradle Files | 26 * Help -> Find Action -> Sync Project with Gradle Files |
27 | 27 |
28 | 28 |
29 ## How it Works | 29 ## How it Works |
30 | 30 |
31 Android Studio integration works by generating `build.gradle` files based on GN | 31 Android Studio integration works by generating `build.gradle` files based on GN |
32 targets. Each `android_apk` and `android_library` target produces a separate | 32 targets. Each `android_apk` and `android_library` target produces a separate |
33 Gradle sub-project. | 33 Gradle sub-project. |
34 | 34 |
35 ### Symlinks and .srcjars | 35 ### Symlinks and .srcjars |
36 | 36 |
(...skipping 10 matching lines...) Loading... |
47 | 47 |
48 Most generated .java files in GN are stored as `.srcjars`. Android Studio does | 48 Most generated .java files in GN are stored as `.srcjars`. Android Studio does |
49 not have support for them, and so the generator script builds and extracts them | 49 not have support for them, and so the generator script builds and extracts them |
50 all to `extracted-srcjars/` subdirectories for each target that contains them. | 50 all to `extracted-srcjars/` subdirectories for each target that contains them. |
51 | 51 |
52 *** note | 52 *** note |
53 ** TLDR:** Always re-generate project files when `.srcjars` change (this | 53 ** TLDR:** Always re-generate project files when `.srcjars` change (this |
54 includes `R.java`). | 54 includes `R.java`). |
55 *** | 55 *** |
56 | 56 |
57 ### Building with Gradle | 57 ## Android Studio Tips |
| 58 |
| 59 * Configuration instructions can be found [here](http://tools.android.com/tech-
docs/configuration). One suggestions: |
| 60 * Launch it with more RAM: `STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-
stable/bin/studio-launcher.sh` |
| 61 * If you ever need to reset it: `rm -r ~/.AndroidStudio*/` |
| 62 * Import Android style settings: |
| 63 * Help -> Find Action -> Code Style -> Java -> Manage -> Impo
rt |
| 64 * Select `third_party/android_platform/development/ide/intellij/codestyle
s/AndroidStyle.xml` |
| 65 |
| 66 ### Useful Shortcuts |
| 67 |
| 68 * `Shift - Shift`: Search to open file or perform IDE action |
| 69 * `Ctrl + N`: Jump to class |
| 70 * `Ctrl + Shift + T`: Jump to test |
| 71 * `Ctrl + Shift + N`: Jump to file |
| 72 * `Ctrl + F12`: Jump to method |
| 73 * `Ctrl + G`: Jump to line |
| 74 * `Shift + F6`: Rename variable |
| 75 * `Ctrl + Alt + O`: Organize imports |
| 76 * `Alt + Enter`: Quick Fix (use on underlined errors) |
| 77 |
| 78 ### Building from the Command Line |
58 | 79 |
59 Gradle builds can be done from the command-line after importing the project into | 80 Gradle builds can be done from the command-line after importing the project into |
60 Android Studio (importing into the IDE causes the Gradle wrapper to be added). | 81 Android Studio (importing into the IDE causes the Gradle wrapper to be added). |
61 | 82 |
62 cd $GRADLE_PROJECT_DIR && bash gradlew | 83 cd $GRADLE_PROJECT_DIR && bash gradlew |
63 | 84 |
64 The resulting artifacts are not terribly useful. They are missing assets, | 85 The resulting artifacts are not terribly useful. They are missing assets, |
65 resources, native libraries, etc. | 86 resources, native libraries, etc. |
66 | 87 |
67 ## Status (as of Sept 21, 2016) | 88 ## Status (as of Sept 21, 2016) |
68 | 89 |
69 ### What currently works | 90 ### What works |
70 | 91 |
71 * Tested with Android Studio v2.2. | 92 * Tested with Android Studio v2.2. |
72 * Basic Java editing and compiling works. | 93 * Basic Java editing and compiling works. |
73 | 94 |
74 ### Roadmap / what's not yet implemented ([crbug](https://bugs.chromium.org/p/ch
romium/issues/detail?id=620034)) | 95 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues
/detail?id=620034)) |
75 | 96 |
76 * JUnit Test targets | 97 * JUnit Test targets |
77 * Better support for instrumtation tests (they are treated as non-test .apks ri
ght now) | 98 * Better support for instrumtation tests (they are treated as non-test .apks ri
ght now) |
78 * Make gradle aware of resources and assets | 99 * Make gradle aware of resources and assets |
79 * Make gradle aware of native code via pointing it at the location of our .so | 100 * 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` | 101 * Add a mode in which gradle is responsible for generating `R.java` |
81 * Add support for native code editing | 102 * Add support for native code editing |
82 * Make the "Make Project" button work correctly | 103 * Make the "Make Project" button work correctly |
83 | |
84 ## Android Studio Tips | |
85 | |
86 * 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) | |
101 | |
OLD | NEW |