Make sure you have followed android build instructions already.
build/android/gradle/generate_gradle.py
This creates a project at out/Debug/gradle
. To create elsewhere:
build/android/gradle/generate_gradle.py --output-directory out/My-Out-Dir --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 --target //chrome/android:chrome_public_apk --target //android_webview/test:android_webview_apk
For first-time Android Studio users:
//third_party/android_tools
.To import the project:
out/Debug/gradle
.You need to re-run generate_gradle.py
whenever BUILD.gn
files change.
gn clean
you may need to restart Android Studio.Android Studio integration works by generating build.gradle
files based on GN targets. Each android_apk
and android_library
target produces a separate Gradle sub-project.
Gradle supports source directories but not source files. However, some directories in Chromium are split amonst multiple GN targets. To accommodate this, the script detects such targets and creates exclude patterns to exclude files not in the current target. You may still see them when editing, but they are excluded in gradle tasks.
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.
.srcjars
change (this includes R.java
).STUDIO_VM_OPTIONS=-Xmx2048m /opt/android-studio-stable/bin/studio-launcher.sh
rm -r ~/.AndroidStudio*/
tools/android/android_studio/ChromiumStyle.xml
Shift - 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)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.
org.gradle.daemon=true
to ~/.gradle/gradle.properties
, creating it if necessary.R.java