Hesam
Hesam

Reputation: 53610

How to compile Android library?

In my project I am using SlidingUpPanel.

Due to a feature that I needed, I cloned the project to my machine and manipulated the library. I tested my feature on its demo project and everything is okay based on this project.

Now, I want to compile its library module in order to get .aar file and add it to my project. What I did is:

  1. I opened cmd and navigated to root folder of slidingUpPanel project.
  2. Ran this command: ./gradlew :library:build
  3. Library compiled and created .aar under /library/build/outputs/aar/library-debug.aar

I copy/pasted this file into /libs folder of my project and updated build.gradle like this:

dependencies {

    compile ANDROID_SUPPORT
    compile CRASHLYTICS
    compile 'com.facebook.android:facebook-android-sdk:3.20.0'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.0.1'
    compile 'com.android.support:recyclerview-v7:+'

    // Local libs not in Maven Central
    compile files('src/main/libs/httpclientandroidlib-1.2.1.jar')
    compile files('src/main/libs/nineoldandroids-2.4.0.jar')
    compile files('src/main/libs/niftynotification-1.2.jar')
    compile files('src/main/libs/zendesk-1.0.0.1.jar')

    compile files('src/main/libs/library-debug.aar')
}

After I sync gradle file, I'm getting error which is because SlidingUpPanelLayout does not recognise.

Any idea why the library cannot be recognised? Any idea would be appreciated. Thanks.

Upvotes: 1

Views: 472

Answers (1)

Dmitriy Puchkov
Dmitriy Puchkov

Reputation: 1601

So, first, lets add this kind of repository in our build.gradle file.

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

Here, I assume that your aar files will be stored in the libs folder in your project.

You can now add a dependency like

 dependencies {
    compile 'net.my.package:mylib:1.0@aar'
 }

Upvotes: 1

Related Questions