| OLD | NEW |
| 1 # Android Studio | 1 # Android Studio |
| 2 | 2 |
| 3 [TOC] | 3 [TOC] |
| 4 | 4 |
| 5 ## Usage | 5 ## Usage |
| 6 | 6 |
| 7 Make sure you have followed [android build instructions](android_build_instructi
ons.md) already. | 7 Make sure you have followed [android build instructions](android_build_instructi
ons.md) already. |
| 8 | 8 |
| 9 ```shell | 9 ```shell |
| 10 build/android/gradle/generate_gradle.py | 10 build/android/gradle/generate_gradle.py |
| 11 ``` | 11 ``` |
| 12 | 12 |
| 13 This creates a project at `out/Debug/gradle`. To create elsewhere: | 13 This creates a project at `out/Debug/gradle`. To create elsewhere: |
| 14 | 14 |
| 15 ```shell | 15 ```shell |
| 16 build/android/gradle/generate_gradle.py --output-directory out/My-Out-Dir --proj
ect-dir my-project | 16 build/android/gradle/generate_gradle.py --output-directory out/My-Out-Dir --proj
ect-dir my-project |
| 17 ``` | 17 ``` |
| 18 | 18 |
| 19 By default, only common targets are generated. To customize the list of targets | 19 By default, only common targets are generated. To customize the list of targets |
| 20 to generate projects for: | 20 to generate projects for: |
| 21 | 21 |
| 22 ```shell | 22 ```shell |
| 23 build/android/gradle/generate_gradle.py --target //some:target_apk --target //so
me/other:target_apk | 23 build/android/gradle/generate_gradle.py --target //chrome/android:chrome_public_
apk --target //android_webview/test:android_webview_apk |
| 24 ``` | 24 ``` |
| 25 | 25 |
| 26 For first-time Android Studio users: | 26 For first-time Android Studio users: |
| 27 | 27 |
| 28 * Avoid running the setup wizard. | 28 * Avoid running the setup wizard. |
| 29 * The wizard will force you to download unwanted SDK components to `//third_
party/android_tools`. | 29 * The wizard will force you to download unwanted SDK components to `//third_
party/android_tools`. |
| 30 * To skip it, select "Cancel" when it comes up. | 30 * To skip it, select "Cancel" when it comes up. |
| 31 | 31 |
| 32 To import the project: | 32 To import the project: |
| 33 | 33 |
| 34 * Use "Import Project", and select the directory containing the generated projec
t, by default `out-gn/Debug/gradle`. | 34 * Use "Import Project", and select the directory containing the generated projec
t, by default `out/Debug/gradle`. |
| 35 | 35 |
| 36 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. | 36 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. |
| 37 | 37 |
| 38 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't,
use: | 38 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't,
use: |
| 39 * Button with two arrows on the right side of the top strip. |
| 39 * Help -> Find Action -> "Sync Project with Gradle Files" | 40 * Help -> Find Action -> "Sync Project with Gradle Files" |
| 40 | 41 * After `gn clean` you may need to restart Android Studio. |
| 41 | 42 |
| 42 ## How it Works | 43 ## How it Works |
| 43 | 44 |
| 44 Android Studio integration works by generating `build.gradle` files based on GN | 45 Android Studio integration works by generating `build.gradle` files based on GN |
| 45 targets. Each `android_apk` and `android_library` target produces a separate | 46 targets. Each `android_apk` and `android_library` target produces a separate |
| 46 Gradle sub-project. | 47 Gradle sub-project. |
| 47 | 48 |
| 48 ### Symlinks and .srcjars | 49 ### Symlinks and .srcjars |
| 49 | 50 |
| 50 Gradle supports source directories but not source files. However, some | 51 Gradle supports source directories but not source files. However, some |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 This wrapper can also be used to invoke gradle commands. | 103 This wrapper can also be used to invoke gradle commands. |
| 103 | 104 |
| 104 cd $GRADLE_PROJECT_DIR && bash gradlew | 105 cd $GRADLE_PROJECT_DIR && bash gradlew |
| 105 | 106 |
| 106 The resulting artifacts are not terribly useful. They are missing assets, | 107 The resulting artifacts are not terribly useful. They are missing assets, |
| 107 resources, native libraries, etc. | 108 resources, native libraries, etc. |
| 108 | 109 |
| 109 * Use a [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.h
tml) to speed up builds: | 110 * Use a [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.h
tml) to speed up builds: |
| 110 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, cr
eating it if necessary. | 111 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, cr
eating it if necessary. |
| 111 | 112 |
| 112 ## Status (as of Jan 19, 2017) | 113 ## Status (as of Feb 7th, 2017) |
| 113 | 114 |
| 114 ### What works | 115 ### What works |
| 115 | 116 |
| 116 * Tested with Android Studio v2.2. | 117 * Tested with Android Studio v2.2. |
| 117 * Java editing and gradle compile works. | 118 * Java editing and gradle compile works. |
| 118 * Instrumentation tests included as androidTest. | 119 * Instrumentation tests included as androidTest. |
| 119 * Symlinks to existing .so files in jniLibs (doesn't generate them). | 120 * Symlinks to existing .so files in jniLibs (doesn't generate them). |
| 121 * Editing resource xml files. |
| 120 | 122 |
| 121 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues
/detail?id=620034)) | 123 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues
/detail?id=620034)) |
| 122 | 124 |
| 123 * Make gradle aware of resources and assets | 125 * Make gradle aware of assets |
| 126 * Layout editor |
| 124 * Add a mode in which gradle is responsible for generating `R.java` | 127 * Add a mode in which gradle is responsible for generating `R.java` |
| 125 * Add support for native code editing | 128 * Add support for native code editing |
| 126 * Make the "Make Project" button work correctly | 129 * Make the "Make Project" button work correctly |
| OLD | NEW |