OLD | NEW |
---|---|
1 # Android Studio | 1 # Android Studio |
2 | 2 |
3 [TOC] | 3 [TOC] |
4 | 4 |
5 ## Usage | 5 ## Usage |
6 | 6 |
7 **Note: currently only Android Studio 2.2 is supported** | |
8 | |
9 Make sure you have followed | 7 Make sure you have followed |
10 [android build instructions](android_build_instructions.md) already. | 8 [android build instructions](android_build_instructions.md) already. |
11 | 9 |
12 ```shell | 10 ```shell |
13 build/android/gradle/generate_gradle.py | 11 build/android/gradle/generate_gradle.py |
14 ``` | 12 ``` |
15 | 13 |
16 This creates a project at `out/Debug/gradle`. To create elsewhere: | 14 This creates a project at `out/Debug/gradle`. To create elsewhere: |
17 | 15 |
18 ```shell | 16 ```shell |
19 build/android/gradle/generate_gradle.py --output-directory out/My-Out-Dir --proj ect-dir my-project | 17 build/android/gradle/generate_gradle.py --output-directory out/My-Out-Dir --proj ect-dir my-project |
20 ``` | 18 ``` |
21 | 19 |
22 By default, only common targets are generated. To customize the list of targets | 20 By default, only common targets are generated. To customize the list of targets |
23 to generate projects for: | 21 to generate projects for: |
24 | 22 |
25 ```shell | 23 ```shell |
26 build/android/gradle/generate_gradle.py --target //chrome/android:chrome_public_ apk --target //android_webview/test:android_webview_apk | 24 build/android/gradle/generate_gradle.py --target //chrome/android:chrome_public_ apk --target //android_webview/test:android_webview_apk |
27 ``` | 25 ``` |
28 | 26 |
27 For those upgrading from Android Studio 2.2 to 2.3: | |
28 | |
29 * Regenerate with `generate_gradle.py`. | |
30 * Clean up in `//third_party/android_tools` with `git clean -ffd`. | |
estevenson
2017/04/04 23:29:44
What does the double f do here?
Peter Wen
2017/04/05 13:09:37
"Remove untracked directories in addition to untra
| |
31 * Restart Android Studio with File -> "Invalidate Caches / Restart". | |
32 | |
29 For first-time Android Studio users: | 33 For first-time Android Studio users: |
30 | 34 |
31 * Avoid running the setup wizard. | 35 * Avoid running the setup wizard. |
32 * The wizard will force you to download unwanted SDK components to | 36 * The wizard will force you to download unwanted SDK components to |
33 `//third_party/android_tools`. | 37 `//third_party/android_tools`. |
34 * To skip it, select "Cancel" when it comes up. | 38 * To skip it, select "Cancel" when it comes up. |
35 | 39 |
36 To import the project: | 40 To import the project: |
37 | 41 |
38 * Use "Import Project", and select the directory containing the generated | 42 * Use "Import Project", and select the directory containing the generated |
(...skipping 11 matching lines...) Expand all Loading... | |
50 | 54 |
51 Android Studio integration works by generating `build.gradle` files based on GN | 55 Android Studio integration works by generating `build.gradle` files based on GN |
52 targets. Each `android_apk` and `android_library` target produces a separate | 56 targets. Each `android_apk` and `android_library` target produces a separate |
53 Gradle sub-project. | 57 Gradle sub-project. |
54 | 58 |
55 ### Excluded files and .srcjars | 59 ### Excluded files and .srcjars |
56 | 60 |
57 Gradle supports source directories but not source files. However, some | 61 Gradle supports source directories but not source files. However, some |
58 directories in Chromium are split amonst multiple GN targets. To accommodate | 62 directories in Chromium are split amonst multiple GN targets. To accommodate |
59 this, the script detects such targets and creates exclude patterns to exclude | 63 this, the script detects such targets and creates exclude patterns to exclude |
60 files not in the current target. You may still see them when editing, but they | 64 files not in the current target. You still see them when editing, but they are |
61 are excluded in gradle tasks. | 65 excluded in gradle tasks. |
62 *** | 66 *** |
63 | 67 |
64 Most generated .java files in GN are stored as `.srcjars`. Android Studio does | 68 Most generated .java files in GN are stored as `.srcjars`. Android Studio does |
65 not have support for them, and so the generator script builds and extracts them | 69 not have support for them, and so the generator script builds and extracts them |
66 all to `extracted-srcjars/` subdirectories for each target that contains them. | 70 all to `extracted-srcjars/` subdirectories for each target that contains them. |
67 | 71 |
68 *** note | 72 *** note |
69 ** TLDR:** Always re-generate project files when `.srcjars` change (this | 73 ** TLDR:** Always re-generate project files when `.srcjars` change (this |
70 includes `R.java`). | 74 includes `R.java`). |
71 *** | 75 *** |
(...skipping 21 matching lines...) Expand all Loading... | |
93 | 97 |
94 * `Shift - Shift`: Search to open file or perform IDE action | 98 * `Shift - Shift`: Search to open file or perform IDE action |
95 * `Ctrl + N`: Jump to class | 99 * `Ctrl + N`: Jump to class |
96 * `Ctrl + Shift + T`: Jump to test | 100 * `Ctrl + Shift + T`: Jump to test |
97 * `Ctrl + Shift + N`: Jump to file | 101 * `Ctrl + Shift + N`: Jump to file |
98 * `Ctrl + F12`: Jump to method | 102 * `Ctrl + F12`: Jump to method |
99 * `Ctrl + G`: Jump to line | 103 * `Ctrl + G`: Jump to line |
100 * `Shift + F6`: Rename variable | 104 * `Shift + F6`: Rename variable |
101 * `Ctrl + Alt + O`: Organize imports | 105 * `Ctrl + Alt + O`: Organize imports |
102 * `Alt + Enter`: Quick Fix (use on underlined errors) | 106 * `Alt + Enter`: Quick Fix (use on underlined errors) |
107 * `F2`: Find next error | |
103 | 108 |
104 ### Building from the Command Line | 109 ### Building from the Command Line |
105 | 110 |
106 Gradle builds can be done from the command-line after importing the project | 111 Gradle builds can be done from the command-line after importing the project |
107 into Android Studio (importing into the IDE causes the Gradle wrapper to be | 112 into Android Studio (importing into the IDE causes the Gradle wrapper to be |
108 added). This wrapper can also be used to invoke gradle commands. | 113 added). This wrapper can also be used to invoke gradle commands. |
109 | 114 |
110 cd $GRADLE_PROJECT_DIR && bash gradlew | 115 cd $GRADLE_PROJECT_DIR && bash gradlew |
111 | 116 |
112 The resulting artifacts are not terribly useful. They are missing assets, | 117 The resulting artifacts are not terribly useful. They are missing assets, |
113 resources, native libraries, etc. | 118 resources, native libraries, etc. |
114 | 119 |
115 * Use a | 120 * Use a |
116 [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html) | 121 [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html) |
117 to speed up builds using the gradlew script: | 122 to speed up builds using the gradlew script: |
118 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, | 123 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, |
119 creating it if necessary. | 124 creating it if necessary. |
120 | 125 |
121 ## Status (as of Feb 7th, 2017) | 126 ## Status (as of April 4th, 2017) |
122 | 127 |
123 ### What works | 128 ### What works |
124 | 129 |
125 * Tested with Android Studio v2.2. | 130 * Tested with Android Studio v2.3. |
126 * Java editing and gradle compile works. | 131 * Java editing and gradle compile works. |
127 * Instrumentation tests included as androidTest. | 132 * Instrumentation tests included as androidTest. |
128 * Symlinks to existing .so files in jniLibs (doesn't generate them). | 133 * Symlinks to existing .so files in jniLibs (doesn't generate them). |
129 * Editing resource xml files. | 134 * Editing resource xml files. |
130 * Java debugging (see | 135 * Java debugging (see |
131 [here](/docs/android_debugging_instructions.md#Android-Studio)) | 136 [here](/docs/android_debugging_instructions.md#Android-Studio)). |
132 | 137 |
133 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues /detail?id=620034)) | 138 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues /detail?id=620034)) |
134 | 139 |
135 * Make gradle aware of assets | 140 * Proper file resolution and imports for overlapping modules. |
136 * Layout editor | 141 * Make gradle aware of assets. |
137 * Add a mode in which gradle is responsible for generating `R.java` | 142 * Layout editor. |
138 * Add support for native code editing | 143 * Add a mode in which gradle is responsible for generating `R.java`. |
139 * Make the "Make Project" button work correctly | 144 * Add support for native code editing. |
145 * Make the "Make Project" button work correctly. | |
OLD | NEW |