0

I've created an Android Project with Android Studio, and usually everything just works fine.

However, whenever I try to add a new custom Android Library Module or just a project with an Android Library Module I get the following error:

Android Studio error message

Failed to import Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
A problem occurred configuring project ':MyLibrary'.
A problem occurred configuring project ':MyLibrary'.
Failed to notify project evaluation listener.
Main Manifest missing from C:\Users\cku\AndroidStudioProjects\MyApplicationProject\MyLibrary\src\main\AndroidManifest.xml
Consult IDE log for more details (Help | Show Log): Failed to import Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
A problem occurred configuring project ':MyLibrary'.
A problem occurred configuring project ':MyLibrary'.
Failed to notify project evaluation listener.
Main Manifest missing from C:\Users\cku\AndroidStudioProjects\MyApplicationProject\MyLibrary\src\main\AndroidManifest.xml
Consult IDE log for more details (Help | Show Log)

I've followed this answer and this answer with no luck.

Any help is appreciated, thx!

Community
  • 1
  • 1
Chris
  • 3,192
  • 4
  • 30
  • 43

2 Answers2

1

I believe the build.gradle file of the project you are trying to import do not specify the right paths because it can't find AndroidManifest.xml:

Main Manifest missing from C:\Users\cku\AndroidStudioProjects\MyApplicationProject\MyLibrary\src\main\AndroidManifest.xml

It is trying to locate AndroidManifest.xml inside the default folder structure which should be:

-Project
 - src
   -instrumentText
   -main
     -java
     -res
     AndroidManifest.xml

As you are importing a project I believe it has other folder structure, which you should inform in build.gradle like this:

sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }

And make the necessary changes to reflect the folder structure of the project you want to import.

rafaello
  • 2,385
  • 1
  • 18
  • 16
  • Thanks for the answer, however, it does not completely apply to my set of circumstances. I would not get any useful project structure from the wizard. Actually, the AndroidManifest.xml would not be generated. Likewise the build.file would be all wrong and use the android plugin instead of the android-library plugin. I've upped the answer, because it helped me in manually tinkering with the project until it barely works now. – Chris Jul 02 '13 at 12:52
  • My experiences with android studio in the last weeks show me that the less painful way to import a library project is copying the library folder to the main project folder and edit build.gradle and settings.gradle file accordingly, and then start android studio and make android studio sync with gradle files. Probably will have to make some edits in Android studio project structure. One last thing, build with gradle in command line and use android studio just for programming. – rafaello Jul 02 '13 at 15:01
0

Just recently (Android Studio 0.2.6) I've tried this again in another project, with no success at all. A co-worker has experienced a similar issue. Now the wizard for creating new modules simply appears blank. It seems to be a genuine bug of Android Studio (which in all fairness is still in early development).

The way to go is to create a new project with only a library in it and then copy its single module over to the existing project. Tinker with the gradle scripts until it builds on the command line. Then go ahead, close Android Studio and delete the .idea directory of your project and all .iml files (there should be one at the root of the project and one at the root of each module). Finally, re-open Android Studio and re-import the project using the gradle.build file in the project root.

Edit: Seems to have gotten more reliable with Android Studio 0.2.8

Chris
  • 3,192
  • 4
  • 30
  • 43