| 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 | 8 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug |
| 9 ``` | 9 ``` |
| 10 | 10 |
| 11 This creates a project at `out-gn/Debug/gradle`. To create elsewhere: | 11 This creates a project at `out-gn/Debug/gradle`. To create elsewhere: |
| 12 | 12 |
| 13 ```shell | 13 ```shell |
| 14 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --projec
t-dir my-project | 14 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --projec
t-dir my-project |
| 15 ``` | 15 ``` |
| 16 | 16 |
| 17 By default, only common targets are generated. To customize the list of targets | 17 By default, only common targets are generated. To customize the list of targets |
| 18 to generate projects for: | 18 to generate projects for: |
| 19 | 19 |
| 20 ```shell | 20 ```shell |
| 21 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --target
//some:target_apk --target //some/other:target_apk | 21 build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --target
//some:target_apk --target //some/other:target_apk |
| 22 ``` | 22 ``` |
| 23 | 23 |
| 24 For first-time Android Studio users: | 24 For first-time Android Studio users: |
| 25 | 25 |
| 26 * Avoid running the setup wizard. | 26 * Avoid running the setup wizard. |
| 27 * The wizard will force you to download unwanted SDK components to `//third_
party/android_tools`. | 27 * The wizard will force you to download unwanted SDK components to `//third_
party/android_tools`. |
| 28 * To skip it, select "Cancel" when it comes up. | 28 * To skip it, select "Cancel" when it comes up. |
| 29 | 29 |
| 30 To import the project: | 30 To import the project: |
| 31 | 31 |
| 32 * Use "Import Project", and select the directory containing the generated proje
ct. | 32 * Use "Import Project", and select the directory containing the generated projec
t. |
| 33 | 33 |
| 34 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. | 34 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. |
| 35 | 35 |
| 36 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't
, use: | 36 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't,
use: |
| 37 * Help -> Find Action -> Sync Project with Gradle Files | 37 * Help -> Find Action -> "Sync Project with Gradle Files" |
| 38 | 38 |
| 39 | 39 |
| 40 ## How it Works | 40 ## How it Works |
| 41 | 41 |
| 42 Android Studio integration works by generating `build.gradle` files based on GN | 42 Android Studio integration works by generating `build.gradle` files based on GN |
| 43 targets. Each `android_apk` and `android_library` target produces a separate | 43 targets. Each `android_apk` and `android_library` target produces a separate |
| 44 Gradle sub-project. | 44 Gradle sub-project. |
| 45 | 45 |
| 46 ### Symlinks and .srcjars | 46 ### Symlinks and .srcjars |
| 47 | 47 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 not have support for them, and so the generator script builds and extracts them | 60 not have support for them, and so the generator script builds and extracts them |
| 61 all to `extracted-srcjars/` subdirectories for each target that contains them. | 61 all to `extracted-srcjars/` subdirectories for each target that contains them. |
| 62 | 62 |
| 63 *** note | 63 *** note |
| 64 ** TLDR:** Always re-generate project files when `.srcjars` change (this | 64 ** TLDR:** Always re-generate project files when `.srcjars` change (this |
| 65 includes `R.java`). | 65 includes `R.java`). |
| 66 *** | 66 *** |
| 67 | 67 |
| 68 ## Android Studio Tips | 68 ## Android Studio Tips |
| 69 | 69 |
| 70 * Configuration instructions can be found [here](http://tools.android.com/tech-
docs/configuration). One suggestions: | 70 * Configuration instructions can be found [here](http://tools.android.com/tech-d
ocs/configuration). One suggestions: |
| 71 * Launch it with more RAM: `STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-
stable/bin/studio-launcher.sh` | 71 * Launch it with more RAM: `STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-
stable/bin/studio-launcher.sh` |
| 72 * If you ever need to reset it: `rm -r ~/.AndroidStudio*/` | 72 * If you ever need to reset it: `rm -r ~/.AndroidStudio*/` |
| 73 * Import Android style settings: | 73 * Import Android style settings: |
| 74 * Help -> Find Action -> Code Style -> Java -> Manage -> Impo
rt | 74 * Help -> Find Action -> "Code Style" (settings) -> Java -> Mana
ge -> Import |
| 75 * Select `third_party/android_platform/development/ide/intellij/codestyle
s/AndroidStyle.xml` | 75 * Select `third_party/android_platform/development/ide/intellij/codestyl
es/AndroidStyle.xml` |
| 76 * Turn on automatic import: |
| 77 * Help -> Find Action -> "Auto Import" |
| 78 * Tick all the boxes under "Java" and change the dropdown to "All". |
| 76 | 79 |
| 77 ### Useful Shortcuts | 80 ### Useful Shortcuts |
| 78 | 81 |
| 79 * `Shift - Shift`: Search to open file or perform IDE action | 82 * `Shift - Shift`: Search to open file or perform IDE action |
| 80 * `Ctrl + N`: Jump to class | 83 * `Ctrl + N`: Jump to class |
| 81 * `Ctrl + Shift + T`: Jump to test | 84 * `Ctrl + Shift + T`: Jump to test |
| 82 * `Ctrl + Shift + N`: Jump to file | 85 * `Ctrl + Shift + N`: Jump to file |
| 83 * `Ctrl + F12`: Jump to method | 86 * `Ctrl + F12`: Jump to method |
| 84 * `Ctrl + G`: Jump to line | 87 * `Ctrl + G`: Jump to line |
| 85 * `Shift + F6`: Rename variable | 88 * `Shift + F6`: Rename variable |
| 86 * `Ctrl + Alt + O`: Organize imports | 89 * `Ctrl + Alt + O`: Organize imports |
| 87 * `Alt + Enter`: Quick Fix (use on underlined errors) | 90 * `Alt + Enter`: Quick Fix (use on underlined errors) |
| 88 | 91 |
| 89 ### Building from the Command Line | 92 ### Building from the Command Line |
| 90 | 93 |
| 91 Gradle builds can be done from the command-line after importing the project into | 94 Gradle builds can be done from the command-line after importing the project into |
| 92 Android Studio (importing into the IDE causes the Gradle wrapper to be added). | 95 Android Studio (importing into the IDE causes the Gradle wrapper to be added). |
| 93 This wrapper can also be used to invoke gradle commands. | 96 This wrapper can also be used to invoke gradle commands. |
| 94 | 97 |
| 95 cd $GRADLE_PROJECT_DIR && bash gradlew | 98 cd $GRADLE_PROJECT_DIR && bash gradlew |
| 96 | 99 |
| 97 The resulting artifacts are not terribly useful. They are missing assets, | 100 The resulting artifacts are not terribly useful. They are missing assets, |
| 98 resources, native libraries, etc. | 101 resources, native libraries, etc. |
| 99 | 102 |
| 100 * Use a [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.
html) to speed up builds: | 103 * Use a [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.h
tml) to speed up builds: |
| 101 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, cr
eating it if necessary. | 104 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, cr
eating it if necessary. |
| 102 | 105 |
| 103 ## Status (as of Sept 21, 2016) | 106 ## Status (as of Sept 21, 2016) |
| 104 | 107 |
| 105 ### What works | 108 ### What works |
| 106 | 109 |
| 107 * Tested with Android Studio v2.2. | 110 * Tested with Android Studio v2.2. |
| 108 * Basic Java editing and compiling works. | 111 * Basic Java editing and compiling works. |
| 109 | 112 |
| 110 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues
/detail?id=620034)) | 113 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues
/detail?id=620034)) |
| 111 | 114 |
| 112 * Better support for instrumentation tests (they are treated as non-test .apks
right now) | 115 * Better support for instrumentation tests (they are treated as non-test .apks r
ight now) |
| 113 * Make gradle aware of resources and assets | 116 * Make gradle aware of resources and assets |
| 114 * Make gradle aware of native code via pointing it at the location of our .so | 117 * Make gradle aware of native code via pointing it at the location of our .so |
| 115 * Add a mode in which gradle is responsible for generating `R.java` | 118 * Add a mode in which gradle is responsible for generating `R.java` |
| 116 * Add support for native code editing | 119 * Add support for native code editing |
| 117 * Make the "Make Project" button work correctly | 120 * Make the "Make Project" button work correctly |
| OLD | NEW |