Although the fact that AOSP already provides IDE-level developing support, the configuration process may still confuse us. In this article, I’ll give a detailed description on how to do this. Note that we need to build the Android source beforehand.
We need to configure the IDEA JVM options and platform properties before importing the source code. For specific os platform, please refer to the official article .
For example, on macOS, the JVM options configuration file is
~/Library/Preferences/IntelliJIdea2016.2/idea.vmoptions, increase the min and max memory like this (for speed up code parsing) :
# custom IntelliJ IDEA VM options -Xms1024m -Xmx4096m -XX:ReservedCodeCacheSize=240m -XX:+UseCompressedOops
For IDEA properties, open (or create) the file
~/Library/Preferences/IntelliJIdea2016.2/idea.properties and increase the filesize like (otherwise IDEA won’t parse the big R.java required):
# custom IntelliJ IDEA properties idea.max.intellisense.filesize=15000 idea.case.sensitive.fs=true
AndroidManifest Configuration (optional)
If we want to debug the framework as app, we need to create an
AndroidManifest.xml under the source code root directory and write the content:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-sdk android:minSdkVersion="23" /> </manifest>
Now open IDEA and configure the platform settings for AOSP project.
Configure jdk1.7 without library(remove all jars in Classpath) — name as jdk7_nolib
Add Android SDK Build target as Android 6.0 — name as Android_23_jdk7_nolib (select above pre configured no lib jdk1.7 as Java SDK)
- select above configured Android SDK (Android_23_jdk7_nolib)
- Project language level -> 7 - Diamonds…
Prepare Source Code
- Under AOSP source root dir, execute command
mmm development/tools/idegen, this will generate necessary IDE files.
- (Optional) Open file
development/tools/idegen/excluded-pathsto configure which sub projects you want to import, eg. if I only want to develop framework base, I will exclude any other projects by appending these lines:
## Only not exclude frameworks art bionic bootable bootstrap.bash build cts dalvik developers development device docs external hardware kernel libcore libnativehelper ndk packages pdk platform_testing prebuilts sdk system toolchain tools
- After that, type
development/tools/idegen/idegen.sh, this will generate Android.iml and Android.ipr files in the source root dir.
- Now you can open the Android.ipr through IDEA. After the indexing finishes, we need to configure the rest parts. Open Project Structure:
Under Modules Tab, add Android framework (or just confirm when IDEA pops up a configure Android framework hint).
In Source Tab, mark out/target/common/R as sources folder
In Dependencies Tab, remove all module dependencies except two
Project SDK (Android_23_jdk7_nolib)
(Optional but recommended) For Unregistered VCS root detected info: Go Preferences->Version Control->add root and apply
Update: in fact we can remove the Android API Platform after the source is imported and maybe it’s necessary since we only need to no-lib JDK and android compiled dependencies.
Another tip is that if we find errors indicating the classes missing, we’ll need to mark the some folders as source appropriately just as what we do in step 5.
Sometimes even we update the source folder, there are still errors. In that case, it’s not our fault, we need to change the package name if necessary or just ignore that. For example, when I looked at the
ActivityThread.java, the class
TrustedCertificateStore is wrongly packaged, we need to change it
org.conscrypt temporarily (or you can manually correct which is a lot of effort). Actually the problem is that the person did not use IDE to write those Java codes, and this kind of package name things are later corrected through jarjar-rules (as can be seen both in Android.mk and jarjar-rules.txt files).
Now enjoy developing the Android source code!
https://android.googlesource.com/platform/development/+/master/tools/idegen/README https://github.com/android/platform_development/blob/master/tools/idegen/excluded-paths https://shuhaowu.com/blog/setting_up_intellij_with_aosp_development.html https://www.jetbrains.com/idea/help/increasing-memory-heap.html http://stackoverflow.com/questions/27690431/configure-intellij-idea-such-that-source-detected-in-git-but-unregistered-vcs-ro/29358524#29358524