0

I have an Android library project in Eclipse that I am trying to build with Android Studio so I can generate an .aar file for my users.

The project seems to have been imported cleanly into Android Studio using the "Import Project" option in the welcome screen.

How do I now build the module? The instructions on the dev site say that I need to change:

apply plugin: 'android'

to

apply plugin: 'android-studio'

However my build.gradle file doesn't have that line (I would have assumed that the importer would have added it(?)).

If I insert the line apply plugin: 'android-library', and try to 'Sync Project with Gradle Files', I get the error:

Gradle 'MyProject' project refresh failed
    Error:C:\Users\Fred\AndroidStudioProjects\MyProject\src\main\AndroidManifest.xml
    (The system cannot find the path specified)

The same happens if I try to make the project anyway.

Here's what my build.gradle looks like:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

apply plugin: 'android-library'

My searches to find a solution have failed. Anyone know what is going on? I'm using the latest Android Studio (0.5.8)

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181

2 Answers2

1

Don't put the apply plugin: 'android-library' statement in the top-level build file. You should find an apply plugin statement in your module-level build file, and you can modify it there as necessary.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • Thanks. That was useful info. I tried cleaning out and reimporting the project. I am not getting any errors this time, but Build doesn't seem to do anything other than generating an .iml file. If I follow the instructions and select assembleRelease from the Gradle Tasks window, nothing much happens. Where is the aar I am supposed to get? – Paul LeBeau May 19 '14 at 18:42
  • I wrote up the full solution as an answer and accepted that so others can easily find it. Hope you don't mind just getting the 10 rep from an upvote. Thanks for taking the time to answer. – Paul LeBeau May 19 '14 at 21:12
0

Okay. After some head scratching and more searching, I resolved all my problems I think. For the record:

I think my first import broke somehow. Partly because of the problem highlighted by Scott Barta and possibly because my project directory had spaces in it? Not totally sure.

A later import went more smoothly and I was able to sync and build without errors. However, apart from the build output in the Gradle Console, there was no evidence anything had actually happned. The artifact (ie. the .aar file) doesn't show up in the UI.

After finding this question: How to export library to Jar in Android Studio? I realised that the aar file is in fact built. It is just hidden from you. You have to root around in the file system to find the .aar. It is in:

<Library module>/build/libs/

Something that the docs don't tell you anywhere. Sigh.

Hope this helps someone else..

Community
  • 1
  • 1
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181