AOSP and IntelliJ IDEA

匿名 (未验证) 提交于 2019-12-03 02:05:01

问题:

Has anyone tried to work with AOSP using IntelliJ IDEA? I see in Android sources a specific folder (development/ide/intellij) but I cannot find any information how to use it in case of Android development (for Eclipse the information can be found here: http://source.android.com/source/using-eclipse.html) Can anyone provide similar instructions how to start developing Android in IDEA?

回答1:

Also a good reading here: https://shuhaowu.com/blog/setting_up_intellij_with_aosp_development.html

If you get

Couldn't find idegen.jar. Please run make first.

You'll need to generate it first:

source build/envsetup.sh cd development/tools/idegen mm croot development/tools/idegen/idegen.sh 

Be prepared that AOSP files indexing in IJ takes long time (more than 1 hour on my notebook with an SSD on board), a reason to use Eclipse, as I believe it doesn't need to build indexes so loads AOSP code much faster.

It's worth reducing android.iml file with removing AOSP parts you are not interested in. You can add them to development/tools/excluded-paths via a regular expression pattern, see README file there.

I added following lines to excluded-paths:

^cts ^developers ^development ^external .*/tests/.* ^sdk 

so my android.iml got quite moderate size and loads in about 1-2 minutes instead.

idegen has also intellij-gen.sh which can generate IJ project for given module.

As mentioned in the article above, you can tweak IJ to work faster (add more RAM, etc). Here goes my idea64.vmoptions just in case:

-server -Xms2048m -Xmx4096m -XX:MaxPermSize=1024M -XX:ReservedCodeCacheSize=1024M -XX:+UseCodeCacheFlushing -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=8 -XX:+AggressiveOpts -XX:+CMSClassUnloadingEnabled -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:-TraceClassUnloading -XX:+TieredCompilation -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djsse.enableSNIExtension=false 

You can google idea.vmoptions optimization, there are some posts about it (and where I took my IJ config from)



回答2:

From AOSP root folder,

1) First build your target. That will generate whatever java files that need to be generated during aosp build. 2) Create a shadow dir of aosp dir using lndir. Assuming your aosp dir is ~john/work/aosp/ics. Then create ~/john/work/aosp/icsshadow

Cd to icsshadow and invoke "lndir ../ics". That will create symlinks to everything under ics.

3) Now you use icsshadow for all the stuff your IDE needs/generates. If you use ics folder, the aosp build some times fails if the IDE generates any build artifacts.

4) cd to icsshadow directory. Invoke development/tools/idegen/idegen.sh

Wait until it is done.

5) If you want to use IntelliJ, open android.ipr from icsshadow folder. If you want to use Eclipse, Please check Using Eclipse to edit/browse AOSP code.



回答3:

Official instructions can be found by going to development/tools/idegen path and checking the README file. It's a good idea to read it yourself. This is the content for IntelliJ:

If you're using IntelliJ...

If this is your first time using IDEGen...

  IDEA needs a lot of memory. Add "-Xms748m -Xmx748m" to your VM options   in "IDEA_HOME/bin/idea.vmoptions" on Linux or   "IntelliJ IDEA.app/Contents/Info.plist" on OS X.    Create a JDK configuration named "1.6 (No Libraries)" by adding a new   JDK like you normally would and then removing all of the jar entries   under the "Classpath" tab. This will ensure that you only get access to   Android's core libraries and not those from your desktop VM. 

From the project's root directory...

   Repeat these steps after each sync...    1) make (to produce generated .java source)   2) development/tools/idegen/idegen.sh   3) Open android.ipr in IntelliJ. If you already have the project open,      hit the sync button in IntelliJ, and it will automatically detect the      updated configuration.    If you get unexpected compilation errors from IntelliJ, try running   "Build -> Rebuild Project". Sometimes IntelliJ gets confused after the   project changes significantly. 

The following error message might pop up when following the instructions.

Couldn't find idegen.jar. Please run make first.

You can fix the error message by reading here: https://www.protechtraining.com/blog/post/860?ncr=1



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!