Android plugin get android facet returns null


I am trying to add some new functionality to my plugin which should work on IntellijIDEA and AndroidStudio. Now I want to get the manifest file of an Android project and make some updates after that.. the problem is that I can't get the AndroidFacet object of the main module as it allways returned as null. Below is my code:

Module[] modules = ModuleManager.getInstance(ProjectManager.getInstance().getOpenProjects()[0]).getSortedModules(); // get all the opened modules sorted by dependency
Module module = modules[modules.length-1];  // get the first module that is not used by other modules or is used by less than the others..
AndroidFacet facet = AndroidFacet.getInstance(module); // and here the facet object is allways null :(

Does anyone know what I am doing wrong? Why the

method returns allways null? 

The opened android project has 4 modules, one is the main and the rest are lib modules. Using the above code I can get the proper module for my case as I could see it's name in debug mode. Also the project's modules are all Android facets..

Any help is much appreciated,
Comment actions Permalink

Please make sure that you've added the Android plugin jars to the classpath of your IntelliJ IDEA SDK and not as a separate library dependency.

Comment actions Permalink

That was it :), thank you very much for your help.

Comment actions Permalink

Hello All,

I'm new in Intellij as a user and as plugin developer. Currently I'm trying to write any (~HelloWorld) plugin for AndroidStudio and I stucked at the begining on the same problem as Catalin. AndroidFacet instance is always null. What I've done is:
1. Adding "...plugin/android" directory from Intellij to classpath of platform SDK (Project structure)
2. Adding "plugins/android/libs" as jar directory in Libraries (Project Structure) - without that such packages like


were not visible.

What I'm doing wrong or what is lacking ? I'll be really appreciate for the answer.

Thank You.

Comment actions Permalink

Please note that the instructions that you're replying to explicitly tell you not to add the jars of the Android plugin as a library dependency. What you need to add to the SDK classpath is the jars from the "plugins/android/lib" subdirectory, not the "plugins/android" directory.

Comment actions Permalink

Right. I was adding whole directory "plugins/android/lib" to classpath instead of jar by jar. My fail. Now, it's working. Thanks.


Please sign in to leave a comment.