build/android/gradle/generate_gradle.py --output-directory out-gn/Debug
This creates a project at
out-gn/Debug/gradle. To create elsewhere:
build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --project-dir my-project
By default, only common targets are generated. To customize the list of targets to generate projects for:
build/android/gradle/generate_gradle.py --output-directory out-gn/Debug --target //some:target_apk --target //some/other:target_apk
For first-time Android Studio users:
To import the project:
You need to re-run
BUILD.gn files change.
Android Studio integration works by generating
build.gradle files based on GN targets. Each
android_library target produces a separate Gradle sub-project.
Gradle supports source directories but not source files. However, some
java/src/ directories in Chromium are split amonst multiple GN targets. To accomodate this, the script detects such targets and creates a
symlinked-java/ directory to point gradle at. Be warned that creating new files from Android Studio within these symlink-based projects will cause new files to be created in the generated
symlinked-java/ rather than the source tree where you want it.
Most generated .java files in GN are stored as
.srcjars. Android Studio does not have support for them, and so the generator script builds and extracts them all to
extracted-srcjars/ subdirectories for each target that contains them.
.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)
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.