How to convert apklib to aar

As Gradle does not support apklib dependencies how can one migrate from apklib dependencies to aar dependencies? Is it possible to either manually or automatically convert apklib dependency to aar? If yes – how, if no – why not?

In this question I assume that I don’t have original project for apklib, but rather the file itself.

  • ImageButton does not display a particular drawable
  • Exception java.lang.NoClassDefFoundError:$styleable
  • Add button like “New Mail” button of Gmail app
  • How can I print/log entire body contents of MultiPartEntity that is being used by HTTPRequest?
  • Eclipse: won't let me use Android SDK, wrongly claims my ADT is out of date
  • regular notification wont show X close button in android
  • Related posts:

    Handle all mouse events in Android
    Android studio error This support library should not use a lower version (19)
    What does checking the “is Library” checkbox do “Under the Cover&r...
    How to play radio live stream .asx video/x-ms-asf?
    Android build error in Crosswalk
    How to turn on/off all sounds from accessibility settings programmatically in android?
  • how can define shortcuts to specific actions in the app?
  • Floating action button's shadow clipping at view margins
  • Animation when changing textview
  • Android map marker color?
  • Android Unit Testing of Categories
  • Application does not show up in Android Market for Motorola XOOM tablet
  • 2 Solutions collect form web for “How to convert apklib to aar”

    apklib doesn’t contain object files, only source files, so the only way it can be included in any project is by recompiling it. According to some docs you can read at:

    Android dependencies : apklib vs aar files and

    The apklib format was invented as a way to share Android code+resources. It’s essentially a zipped up Android library project, which was already the status quo for code+resource sharing.

    And you can see in Chris Broadfoot’s post that the task that generates the apklib just zips up the AndroidManifest.xml file and the src and res directories:

    task apklib(type: Zip) {
        appendix = extension = 'apklib'
        from 'AndroidManifest.xml'
        into('res') {
            from 'res'
        into('src') {
            from 'src'

    Note that his post is about creating an apklib from Gradle, which is a slightly weird thing to want to do, but it provides a pretty clear idea of how one of these things is structured.

    The good news is that this is “standard” Android project structure as of when Eclipse was the primary IDE, and Android Studio knows how to import modules that look like this. So follow these steps:

    1. Unpack your apklib into a temporary directory. It’s in zip format, so something like unzip library.apklib should work.

    2. Look at what’s unpacked. You should see a directory containing AndroidManifest.xml, src, and res folders.

    3. In Android Studio, inside an existing project, choose File > Import Module and point it at the directory from step 2.

    4. Android Studio should manage the import by copying the files into your project in a new module, arranging them in its preferred directory structure, and will add a build.gradle file for the module.

    5. At this point you’re up and running. If you actually want the .aar file, then check to see if your new module is set up as a library module or an application module. In its build.gradle, if you’ve got apply plugin: '' then it’s a library module, and Gradle will generate an .aar as part of the build: it will be in the build/outputs/aar directory after a successful build.

    6. If your module imported as an app module and not a library (apply plugin: '', then change that apply plugin statement, and you may also need to remove the applicationId statement from the build file. Now it should compile as a library and generate a .aar.

    7. Happy coding!

    You cannot convert the apklib to aar. You have to update the dependencies manually to point to an aar file. The aar is compiled and contain lint and proguard rules which the apklib can’t necessarily determine automatically.

    You can read a bit more on the differences here:

    Android dependencies : apklib vs aar files

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.