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:
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
BUILD.gn files change.
--beta to avoid the “A newer version of gradle is available” notification.
gn cleanyou 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
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.
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
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
build/android/gradle/generate_gradle.py --native-target //chrome/android:libchrome
export CHROMIUM_OUT_DIR=out; export BUILDTYPE=Debugto your
~/.bashrcto always default to
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.