13

I'm trying to setup a development environment to do some custom modifications on the AOSP source code, and would like to use Android Studio as my IDE. After doing the necessary steps, however, Android Studio seems to not be able to recognize some of the classes and methods. Did I do something wrong? Here's a rundown of what I did:

I did the necessary preparations (dependencies, etc.) for cloning and building AOSP according to the official documentation. After that, I cloned the AOSP 7.1.1-r11 branch with repo, and then ran the following commands:

$ source build/envsetup.sh
$ lunch aosp_arm-eng
$ make
$ mmm development/tools/idegen/
$ development/tools/idegen/idegen.sh

The make took me about an hour, running the idegen.sh took me around 5 seconds.

The idegen.sh generated an android.ipr file which I successfully imported in Android Studio. When prompted with an SDK selection, I selected openjdk 1.8.0_121 and removed all the libraries in the classpath, as indicated in the idegen readme file.

After letting Android Studio run the initial import actions, I went ahead and opened the PhoneFactory.java from the telephony framework where I want to do my modifications. Here is where I have my problem: several dozen methods are in red (cannot be resolved).

I am sure there is no problem with how I cloned AOSP, as the make passes correctly. Any ideas?

Alexis Sorokine
  • 143
  • 1
  • 1
  • 8
  • +1 that's a problem I also fight with since I use AOSP with android-studio (and never found a solution). – IIIIIIIIIIIIIIIIIIIIII Feb 08 '17 at 12:15
  • I do not see where there are Android Studio instructions on https://source.android.com. My assumption would be that this is not yet supported. That being said, I do not do full firmware builds, let alone using an IDE. – CommonsWare Feb 09 '17 at 12:35
  • 1
    I have followed the readme included with the idegen tool: [link](https://android.googlesource.com/platform/development/+/master/tools/idegen/README) – Alexis Sorokine Feb 10 '17 at 11:05
  • @AlexisSorokine have you tried to do the same with eclipse? I am afraid this is not yet supported for android-studio. – IIIIIIIIIIIIIIIIIIIIII Feb 13 '17 at 07:54
  • I tried doing the same in Eclipse, and am still getting a bunch of errors. – Alexis Sorokine Feb 13 '17 at 12:34
  • I configured as it is recommended and I do not see any error. Here is my screenshot: http://pasteboard.co/A6kCe5jhD.png Do you see something different? – Yury Feb 19 '17 at 05:52
  • @Yury maybe on that one class you show but whats with "AcitivityMangerService" for example ? – IIIIIIIIIIIIIIIIIIIIII Feb 19 '17 at 17:09
  • There are some errors that are related to wrong imports. – Yury Feb 20 '17 at 08:12
  • This is the kind of errors that I'm getting : http://pasteboard.co/3F5iyMwF9.png , and when I try to access TelephonyManager through the link (ctrl + click) I'm directed to the decompiled class file instead. – Alexis Sorokine Feb 20 '17 at 13:41
  • This is very strange. I do not have such behavior in my case. I checked exactly on the same line. In my case, the method is resolved and when I click on it I am redirected into the right place. – Yury Feb 21 '17 at 11:26

1 Answers1

9

I always use these steps without any problem at all:

https://shuhaowu.com/blog/setting_up_intellij_with_aosp_development.html

The most important parts for your problem are:

  • Set the SDK with no libraries
  • In the Project Structure -> Module -> Remove all of the dependencies that ends with a .jar
  • As a bonus: go to the Sources tab and browse to out/target/common/R. Right click on it and click Source

In the link you can see screenshots that can make the steps easier to follow.

Olaia
  • 2,172
  • 25
  • 27
  • 1
    +Olaia these steps dont work any more for AS 3.1 see https://stackoverflow.com/questions/50415724/developing-aosp-with-android-studio-3-1-cannot-set-sdk-without-libraries – likejudo May 18 '18 at 16:59
  • @likejiujitsu, I have never used AS to build modules that are part of AOSP, always from terminal in order to do the source build/envsetup and the lunch. I am still using these steps in order to open AOSP source code and navigate through it. – Olaia Jul 19 '18 at 09:48