How to convert apklib to aar

As Gradle does not support apklib dependencies, how can I go from apklib dependencies to aar dependencies? Is it possible to manually or automatically convert apklib dependency to aar ? If so, how, if not, why not?

In this question, I assume that I do not have the original project for apklib , but the file itself.

+7
android android gradle
source share
2 answers

apklib does not contain object files, only source files, so the only way to include it in any project is to recompile it. According to some docs you can read:

Android dependencies: apklib vs aar files and https://plus.google.com/+ChristopherBroadfoot/posts/7uyipf8DTau p>

The apklib format was invented as a way to share Android + resources. This is essentially an encrypted Android library project that already had the status quo for sharing code + resources.

And you can see in the Chris Broadfoot message that the task that apklib generates simply 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' } } 

Please note that his post is about creating apklib from Gradle, which is a bit strange to do, but it gives a pretty clear idea of ​​how one of these things is structured.

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

  • Unzip your appklib into a temporary directory. This is in zip format, so something like unzip library.apklib should work.

  • Look what is unpacked. You should see a directory containing the AndroidManifest.xml , src and res folders.

  • In Android Studio, inside an existing project, choose File> Import Module and specify it in the directory from step 2.

  • Android Studio should manage the import by copying files to the project in a new module, organizing them in their preferred directory structure and adding the build.gradle file to it.

  • At this point you are working. If you really want the .aar file, then check if your new module is installed as a library module or application module. In build.gradle , if you have apply plugin: 'com.android.library' , then this is a library module, and Gradle will generate .aar as part of the assembly: it will be in the build/outputs/aar after a successful build.

  • If your module is imported as an application module and not a library ( apply plugin: 'com.android.application' ), modify this apply plugin statement and you may also need to remove the applicationId statement from the assembly file. should compile as a library and generate .aar .

  • Happy coding!

+11
source share

You cannot convert apklib to aar. You must manually update the dependencies to point to the aar file. Aar is compiled and contains lint and proguard rules, which the appclib cannot automatically detect automatically.

You can read a little more about the differences here:

Android dependencies: apklib vs aar files

0
source share

All Articles