gmmo
gmmo

Reputation: 2791

Can I package an entire android app into a library?

Is it possible to make an entire android app a package to be included into another android app?

I am not talking about only plain java code compiled into a .jar file. I am referring as including everything: java code, layouts, etc. Then use intents to communicate to this "library". I don't want to have a separate apk or separate app installed. It is like one entire apk being included another one and make the whole thing a new app. Likely the manifest needs to be handled differently.

I looked at this tutorials but just is list a regular .jar with plain java code.

http://www.vogella.com/tutorials/AndroidLibraryProjects/article.html

any pointers greatly appreciated. thx!

Upvotes: 1

Views: 154

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317427

You can make an .aar archive, yes. A few things to know about this:

  • The aar is built as a library project, with gradle plugin 'com.android.library'
  • You will still need to have a shell application project that declares a dependency on the aar built from the library.
  • The aar will have its own manifest and resources. The manifest and resources will get merged into the shell application's manifest. Do you best to understand the process of manifest merger.
  • The aar will have its own code, of course, and the shell app can't duplicate classes contained in the aar.
  • The shell application needs to declare its own application id in its own build.gradle as well as other required properties that are expected of applications built with the 'com.android.application' plugin.
  • None of the application settings can conflict with the settings from the aar. For example, you can't target a lower API level than the minimum in the aar.
  • The application can not override any of the resources defined in the aar. It's the other way around - libraries override resources defined in the app.

If you are including the aar directly into the file structure of the app, you'll need to declare a dependency on it like this (or similar):

repositories {
    flatDir {
        dirs 'libs'  // place the aar in here
    }
}
dependencies {
    compile(name:'fileNameOfAarWithoutExtension', ext:'aar')
}

But if you distribute the aar as a maven dependency, you can simply use the maven coordinates.

There might be other things to know, but that's what I can think of off the top of my head.

Upvotes: 1

Related Questions