Make sure you have followed android build instructions already.
build/android/gradle/generate_gradle.py --output-directory out/Debug
The above commands create a project dir gradle
under your output directory. Use --project-dir <project-dir>
to change this.
To import the project:
out/Debug/gradle
.See android_test_instructions.md for more information about building and running emulators.
Feel free to accept Android Studio‘s recommended actions. generate_gradle.py
should have already set up a working version of the gradle wrapper and the android gradle plugin, as well as a default Android SDK location at ~/Android/Sdk
. Since the same script needs to support various versions of Android Studio, the defaults may have lower version than the one recommended by your version of Android Studio. After you accept Android Studio’s update actions the generate_gradle.py
script will try to keep the newer versions when it is re-run.
You'll need to re-run generate_gradle.py
whenever new directories containing source files are added.
gn clean
you may need to restart Android Studio.By default, only an _all
module containing all java apk targets is generated. If just one apk target is explicitly specified, then a single apk module is generated.
If you really prefer a more detailed structure of gn targets, the deprecated --split-projects
flag can be used. This will generate one module for every gn target in the dependency graph. This can be very slow and is no longer supported.
Most generated .java files in GN are stored as .srcjars
. Android Studio does not support them. Our build will automatically extract them to a generated_java
directory in the output directory during the build. Thus if a generated file is missing in Android Studio, build it with ninja first and it should show up in Android Studio afterwards.
This option is deprecated and no longer supported since Android Studio is very slow when editing in a code base with a large number of C++ files, and Chromium has a lot of C++ code. It is recommended to use VS Code to edit native files and stick to just editing java files in Android Studio.
If you still want to enable editing native C/C++ files with Android Studio, pass in any number of --native-target [target name]
flags in order to use it. The target must be the full path and name of a valid gn target (no short-forms). This will require you to install cmake
and ndk
when prompted. Accept Android Studio's prompts for these SDK packages.
You need to disable a new gradle option in order to edit native files: File -> Settings -> Experimental -> Gradle and uncheck “Only resolve selected variants”.
This is not necessary, but to avoid “This file is not part of the project...”, you can either add an extra --native-target
flag or simply copy and paste the absolute path to that file into the CMakeLists.txt file alongside the existing file paths. Note that changes to CMakeLists.txt will be overwritten on your next invocation of generate_gradle.py
.
Example:
build/android/gradle/generate_gradle.py --native-target //chrome/android:libchrome
--output-directory
.export CHROMIUM_OUT_DIR=out; export BUILDTYPE=Debug
to your ~/.bashrc
to always default to out/Debug
.STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-stable/bin/studio-launcher.sh
rm -r ~/.config/Google/AndroidStudio*/
tools/android/android_studio/ChromiumStyle.xml
-> OKtools/android/android_studio/ChromiumInspections.xml
-> OKShift - Shift
: Search to open file or perform IDE actionCtrl + N
: Jump to classCtrl + Shift + T
: Jump to testCtrl + Shift + N
: Jump to fileCtrl + F12
: Jump to methodCtrl + G
: Jump to lineShift + F6
: Rename variableCtrl + Alt + O
: Organize importsAlt + Enter
: Quick Fix (use on underlined errors)F2
: Find next errorGradle builds are not supported. Only editing is supported in Android Studio. Use ninja to build as usual.
main
sourceset.androidTest
sourceset.autoninja
to build targets and just use Android Studio for editing java source files.