Make sure you have followed android build instructions already.
build/android/gradle/generate_gradle.py --output-directory out/Debug [--canary] # Use --canary for Android Studio 3.1 canary
This creates a project at
out/Debug/gradle. To create elsewhere:
build/android/gradle/generate_gradle.py --output-directory out/Debug --project-dir my-project
If you are planning to use Android emulators use the --sdk=AndroidStudioDefault or the --sdk-path option, since adding emulator images to the project sdk will modify the project sdk, hence causing problems when you next run gclient sync.
See android_test_instructions.md for more information about building and running emulators.
For first-time Android Studio users:
To import the project:
If you‘re asked to use Studio’s Android SDK:
If you‘re asked to use Studio’s Gradle wrapper:
You need to re-run
BUILD.gn files change.
gn cleanyou may need to restart Android Studio.
By default, only a single module is generated. If more than one apk target is specified, then an
_all module is generated. Otherwise a single apk module is generated. Since instrumentation tests are combined with their
apk_under_test target, they count as one module together.
To see more detailed structure of gn targets, the
--split-projects flag can be used. This will generate one module for every gn target in the dependency graph.
Gradle supports source directories but not source files. However, files in Chromium are used amongst multiple targets. To accommodate this, the script detects such targets and creates exclude patterns to exclude files not in the current target. The editor does not respect these exclude patterns, so a
_all pseudo module is added which includes directories from all targets. This allows imports and refactorings to be searched across all targets.
Most generated .java files in GN are stored as
.srcjars. Android Studio does not support them, and so the generator script builds and extracts them all to
extracted-srcjars/ subdirectories for each target that contains them. This is the reason that the
_all pseudo module may contain multiple copies of generated files.
.srcjarschange (this includes
rm -r ~/.AndroidStudio*/
Shift - Shift: Search to open file or perform IDE action
Ctrl + N: Jump to class
Ctrl + Shift + T: Jump to test
Ctrl + Shift + N: Jump to file
Ctrl + F12: Jump to method
Ctrl + G: Jump to line
Shift + F6: Rename variable
Ctrl + Alt + O: Organize imports
Alt + Enter: Quick Fix (use on underlined errors)
F2: Find next error
Gradle builds can be done from the command-line after importing the project into Android Studio (importing into the IDE causes the Gradle wrapper to be added). This wrapper can also be used to invoke gradle commands.
cd $GRADLE_PROJECT_DIR && bash gradlew
The resulting artifacts are not terribly useful. They are missing assets, resources, native libraries, etc.
~/.gradle/gradle.properties, creating it if necessary.