Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Side by Side Diff: docs/android_studio.md

Issue 2682183002: Android: Replace symlinks with gradle filters (Closed)
Patch Set: Fix per review Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/gradle/generate_gradle.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
8 [android build instructions](android_build_instructions.md) already.
8 9
9 ```shell 10 ```shell
10 build/android/gradle/generate_gradle.py 11 build/android/gradle/generate_gradle.py
11 ``` 12 ```
12 13
13 This creates a project at `out/Debug/gradle`. To create elsewhere: 14 This creates a project at `out/Debug/gradle`. To create elsewhere:
14 15
15 ```shell 16 ```shell
16 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
17 ``` 18 ```
18 19
19 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
20 to generate projects for: 21 to generate projects for:
21 22
22 ```shell 23 ```shell
23 build/android/gradle/generate_gradle.py --target //some:target_apk --target //so me/other:target_apk 24 build/android/gradle/generate_gradle.py --target //some:target_apk --target //so me/other:target_apk
24 ``` 25 ```
25 26
26 For first-time Android Studio users: 27 For first-time Android Studio users:
27 28
28 * Avoid running the setup wizard. 29 * Avoid running the setup wizard.
29 * The wizard will force you to download unwanted SDK components to `//third_ party/android_tools`. 30 * The wizard will force you to download unwanted SDK components to
31 `//third_party/android_tools`.
30 * To skip it, select "Cancel" when it comes up. 32 * To skip it, select "Cancel" when it comes up.
31 33
32 To import the project: 34 To import the project:
33 35
34 * Use "Import Project", and select the directory containing the generated projec t, by default `out-gn/Debug/gradle`. 36 * Use "Import Project", and select the directory containing the generated
37 project, by default `out-gn/Debug/gradle`.
35 38
36 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change. 39 You need to re-run `generate_gradle.py` whenever `BUILD.gn` files change.
37 40
38 * After regenerating, Android Studio should prompt you to "Sync". If it doesn't, use: 41 * After regenerating, Android Studio should prompt you to "Sync". If it
42 doesn't, use:
39 * Help -> Find Action -> "Sync Project with Gradle Files" 43 * Help -> Find Action -> "Sync Project with Gradle Files"
40 44
41 45
42 ## How it Works 46 ## How it Works
43 47
44 Android Studio integration works by generating `build.gradle` files based on GN 48 Android Studio integration works by generating `build.gradle` files based on GN
45 targets. Each `android_apk` and `android_library` target produces a separate 49 targets. Each `android_apk` and `android_library` target produces a separate
46 Gradle sub-project. 50 Gradle sub-project.
47 51
48 ### Symlinks and .srcjars 52 ### Excluded files and .srcjars
49 53
50 Gradle supports source directories but not source files. However, some 54 Gradle supports source directories but not source files. However, some
51 `java/src/` directories in Chromium are split amonst multiple GN targets. To 55 directories in Chromium are split amonst multiple GN targets. To accommodate
52 accommodate this, the script detects such targets and creates a `symlinked-java/ ` 56 this, the script detects such targets and creates exclude patterns to exclude
53 directory to point gradle at. Be warned that creating new files from Android 57 files not in the current target. You may still see them when editing, but they
54 Studio within these symlink-based projects will cause new files to be created in 58 are excluded in gradle tasks.
55 the generated `symlinked-java/` rather than the source tree where you want it.
56
57 *** note
58 ** TLDR:** Always create new files outside of Android Studio.
59 *** 59 ***
60 60
61 Most generated .java files in GN are stored as `.srcjars`. Android Studio does 61 Most generated .java files in GN are stored as `.srcjars`. Android Studio does
62 not have support for them, and so the generator script builds and extracts them 62 not have support for them, and so the generator script builds and extracts them
63 all to `extracted-srcjars/` subdirectories for each target that contains them. 63 all to `extracted-srcjars/` subdirectories for each target that contains them.
64 64
65 *** note 65 *** note
66 ** TLDR:** Always re-generate project files when `.srcjars` change (this 66 ** TLDR:** Always re-generate project files when `.srcjars` change (this
67 includes `R.java`). 67 includes `R.java`).
68 *** 68 ***
69 69
70 ## Android Studio Tips 70 ## Android Studio Tips
71 71
72 * Configuration instructions can be found [here](http://tools.android.com/tech-d ocs/configuration). One suggestions: 72 * Configuration instructions can be found
73 * Launch it with more RAM: `STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio- stable/bin/studio-launcher.sh` 73 [here](http://tools.android.com/tech-docs/configuration). One suggestions:
74 * Launch it with more RAM:
75 `STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-stable/bin/studio-launche r.sh`
74 * If you ever need to reset it: `rm -r ~/.AndroidStudio*/` 76 * If you ever need to reset it: `rm -r ~/.AndroidStudio*/`
75 * Import Android style settings: 77 * Import Android style settings:
76 * Help -> Find Action -> "Code Style" (settings) -> Java -> Mana ge -> Import 78 * Help -> Find Action -> "Code Style" (settings) -> Java ->
79 Manage -> Import
77 * Select `third_party/android_platform/development/ide/intellij/codestyl es/AndroidStyle.xml` 80 * Select `third_party/android_platform/development/ide/intellij/codestyl es/AndroidStyle.xml`
78 * Turn on automatic import: 81 * Turn on automatic import:
79 * Help -> Find Action -> "Auto Import" 82 * Help -> Find Action -> "Auto Import"
80 * Tick all the boxes under "Java" and change the dropdown to "All". 83 * Tick all the boxes under "Java" and change the dropdown to "All".
81 * Turn on documentation on mouse hover: 84 * Turn on documentation on mouse hover:
82 * Help -> Find Action -> "Show quick documentation on mouse move" 85 * Help -> Find Action -> "Show quick documentation on mouse move"
83 * Turn on line numbers: 86 * Turn on line numbers:
84 * Help -> Find Action -> "Show line numbers" 87 * Help -> Find Action -> "Show line numbers"
85 88
86 ### Useful Shortcuts 89 ### Useful Shortcuts
87 90
88 * `Shift - Shift`: Search to open file or perform IDE action 91 * `Shift - Shift`: Search to open file or perform IDE action
89 * `Ctrl + N`: Jump to class 92 * `Ctrl + N`: Jump to class
90 * `Ctrl + Shift + T`: Jump to test 93 * `Ctrl + Shift + T`: Jump to test
91 * `Ctrl + Shift + N`: Jump to file 94 * `Ctrl + Shift + N`: Jump to file
92 * `Ctrl + F12`: Jump to method 95 * `Ctrl + F12`: Jump to method
93 * `Ctrl + G`: Jump to line 96 * `Ctrl + G`: Jump to line
94 * `Shift + F6`: Rename variable 97 * `Shift + F6`: Rename variable
95 * `Ctrl + Alt + O`: Organize imports 98 * `Ctrl + Alt + O`: Organize imports
96 * `Alt + Enter`: Quick Fix (use on underlined errors) 99 * `Alt + Enter`: Quick Fix (use on underlined errors)
97 100
98 ### Building from the Command Line 101 ### Building from the Command Line
99 102
100 Gradle builds can be done from the command-line after importing the project into 103 Gradle builds can be done from the command-line after importing the project
101 Android Studio (importing into the IDE causes the Gradle wrapper to be added). 104 into Android Studio (importing into the IDE causes the Gradle wrapper to be
102 This wrapper can also be used to invoke gradle commands. 105 added). This wrapper can also be used to invoke gradle commands.
103 106
104 cd $GRADLE_PROJECT_DIR && bash gradlew 107 cd $GRADLE_PROJECT_DIR && bash gradlew
105 108
106 The resulting artifacts are not terribly useful. They are missing assets, 109 The resulting artifacts are not terribly useful. They are missing assets,
107 resources, native libraries, etc. 110 resources, native libraries, etc.
108 111
109 * Use a [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.h tml) to speed up builds: 112 * Use a
110 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`, cr eating it if necessary. 113 [gradle daemon](https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html)
114 to speed up builds using the gradlew script:
115 * Add the line `org.gradle.daemon=true` to `~/.gradle/gradle.properties`,
116 creating it if necessary.
111 117
112 ## Status (as of Jan 19, 2017) 118 ## Status (as of Jan 19, 2017)
113 119
114 ### What works 120 ### What works
115 121
116 * Tested with Android Studio v2.2. 122 * Tested with Android Studio v2.2.
117 * Java editing and gradle compile works. 123 * Java editing and gradle compile works.
118 * Instrumentation tests included as androidTest. 124 * Instrumentation tests included as androidTest.
119 * Symlinks to existing .so files in jniLibs (doesn't generate them). 125 * Symlinks to existing .so files in jniLibs (doesn't generate them).
120 126
121 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues /detail?id=620034)) 127 ### What doesn't work (yet) ([crbug](https://bugs.chromium.org/p/chromium/issues /detail?id=620034))
122 128
123 * Make gradle aware of resources and assets 129 * Make gradle aware of resources and assets
124 * Add a mode in which gradle is responsible for generating `R.java` 130 * Add a mode in which gradle is responsible for generating `R.java`
125 * Add support for native code editing 131 * Add support for native code editing
126 * Make the "Make Project" button work correctly 132 * Make the "Make Project" button work correctly
OLDNEW
« no previous file with comments | « build/android/gradle/generate_gradle.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698