Intro
Curious about the IntelliJ IDE works? Pablo Baxter and I wrote this guide to help you better understand the IDE internals and enable you to ask more insightful questions especially when filing bug reports. Follow the Quickstart below to get started.
Want to help improve this doc? Please submit a pull request or contact us directly.
Quickstart
The quickest way to get started is to use the open source versions of the Android plugin and IntelliJ Community Edition maintained by JetBrains.
Step 1: Grab the IntelliJ source code
-
Clone the IntelliJ repository.
git clone https://github.com/JetBrains/intellij-community pushd intellij-community
-
Match the version used in Android Studio (see https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html):
For instance, to checkout the Giraffe version, you would use this command:
git checkout idea/223.8836.35
-
To get the Android plugin, clone from this repo.
git clone git://git.jetbrains.org/idea/android.git android pushd android # Make sure to match the same IDEA version for the Android plugin git checkout idea/223.8836.35
NOTE: the JetBrains Android plugin is maintained separately from Google’s version. See the section below on how to use the Android plugin from Google.
Step 2: Setup Android Studio
Because Android Studio is a Java process, you can setup config options to be to attach to it.
-
Start Android Studio and go to
Help
->Edit Custom VM Options...
. -
Add
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006
to the end of thestudio.vmoptions
file:- Note the 5006 address can be any value. Because Gradle uses 5005 by default, we choose 5006 to avoid conflicts.
- If you want to wait for Gradle to start, set
suspend=y
. This may be useful in case you want to put breakpoints against the Gradle source code to see what’s happening.
-
Quit and restart Android Studio to load the new
studio.vmoptions
set.
Step 3: Attach debugger
You’ll first need to decide whether you need to attach a debugger to Android Studio, or the Gradle daemon. For more information, see how the sync process works.
You’ll want to install a copy of IntelliJ to be able to attach to Android Studio. You may need to upgrade to the latest IntelliJ version.
-
Startup IntelliJ.
-
Load the
intellij-community
project. -
If you see this notification warning, it means you may need to download a newer IntelliJ version:
-
Go to
Run
->Edit Configurations...
-
Click on the
+
icon andAdd New Configuration
. SelectRemote JVM Debug
. -
Specify the port number that you specified earlier (e.g.
5006
). -
Select the Run Configuration and Attach to the port!
Attaching to the Gradle Daemon
-
Modify your
~/.gradle/gradle.properties
and add the following:org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
If you want the Gradle daemon to wait until a debugger is attached, use
suspend=y
. For large Gradle subprojects with long configuration times, you might not need to set this option. -
./gradlew --stop
-
./gradlew help
to restart the daemon
Using the Android plugin from Google (optional)
You can also download the Android plugin maintained by Google, which is a separate fork and requires a few more advanced steps that includes downloading multiple repos and invoking Bazel to build a build of the protobuf dependencies. See this link for instructions about how to get this plugin working in IntelliJ.
Attaching sources to the IntelliJ requires download the corresponding Android Studio. For instance, for Giraffe, we can download the .ZIP file:
https://github.com/JetBrains/intellij-community/releases/tag/idea%2F223.8836.35
And then use the attach sources
to use the files.