Search code examples
androidjarandroid-libraryaar

Some questions regarding libraries in Android


I am writing an SDK to be used in other applications, to enable them to use our service. Obviously, I am writing a library for that.

Note that user here means user of SDK.

The questions:

  • I need to have an activity in my library. Do users have to declare my activity in their application to use it? Can I have activity defined in the manifest of my library, export library as aar? Does this work?
  • My library needs some permissions, like to check if internet is available or not. Like the above issue, can I have my permissions defined in manifest of my library?
  • aar or jar? What is the difference, beside the things mentioned in Google docs. Any support issues with aar, idk like lower API versions not supporting it or other IDEs (Eclipse? Still used?) not supporting it? I mean some practical issues with aar, if there is any.

I'm also open to any documentation or any link to help me.

I have developed for Android in the past, last time was when Android Studio was just released in alpha. It seems like a new world now :)


Solution

  • I need to have an activity in my library. Do users have to declare my activity in their application to use it? Can I have activity defined in the manifest of my library, export library as aar? Does this work?

    Users don't need to declare library activities in app manifest. It will work. But don't forget to declare theme inside your library style file and apply on your activities(Activities which are in library).

    My library needs some permissions, like to check if internet is available or not. Like the above issue, can I have my permissions defined in manifest of my library?

    All permissions which you need inside library module you can mention it inside library manifest. But you have to take care of asking risky permissions. Let say if your library need WRITE_EXTERNAL_STORAGE permission so whenever you are going to call library activity you need to ask such permission at run time. You will get more here

    aar or jar? If you are going for pure android then go for aar. You will get more discussion on here