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.
If you‘re asked to use Studio’s Android SDK: No.
If you‘re asked to use Studio’s Gradle wrapper: Yes.
You need to re-run generate_gradle.py
whenever BUILD.gn
files change.
Pass --canary
or --beta
to avoid the “A newer version of gradle is available” notification.
gn clean
you may need to restart Android Studio.If building the Gradle files in Android Studio prints an error like this:
Failed to find Platform SDK with path: platforms;android-31
Then it means the SDK is being updated to the new release. A workaround is to ask for an older SDK version in args.gn
:
android_sdk_version = 30
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.
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. This can be very slow when used with --all
by default.
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 the _all
pseudo module is added which includes directories from all targets. This allows imports and refactoring to be across all targets.
Most generated .java files in GN are stored as .srcjars
. Android Studio does not support them. The generator script builds and extracts them to extracted-srcjars/
subdirectories for each target that contains generated files. This is the reason that the _all
pseudo module may contain multiple copies of generated files. It can be slow to build all these generated files, so if --fast
is passed then the generator script skips building and extracting them.
R.java
).A new experimental option is now available to enable editing native C/C++ files with Android Studio. Pass in any number of --native-target [target name]
flags in order to try it out. The target must be the full path and name of a valid gn target (no shorthands). 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 ~/.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 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.
org.gradle.daemon=true
to ~/.gradle/gradle.properties
, creating it if necessary.main
sourceset.androidTest
sourceset.