udenfox
udenfox

Reputation: 1604

Is it possible to have AccountAuthenticator and account management in .aar library?

What I'm trying to do - is to separate all the account management routines in a separate .aar library to use it in all of my project. The point is to share same account between different apps. For example: I've logged in to the app A. App A saved some auth data to the Account manager. Then I install app B that has same AAR with account management. App B automatically use credentials created in app A.

For the first simple try I assembled all "kind-of-CRUD" methods for AccountManager in my AAR. I've also added AuthenticatorService and Authenticator classes in that AAR and added my service with authenticator.xml inside AAR's manifest.

The problem is that app, which is using my AAR to authenticate, can't create Account. I've keep getting the "uid XXX cannot explicitly add accounts of type: com.example.acc_type" exception.

I've double-checked, and account types are same in authenticator.xml and in my code.

What is more: if I will move the AuthenticatorService, Authenticator classes, authenticator.xml and the Service description from the AAR to the app - everything is working fine!

So I believe that there is some mistake. Is it really possible to have AuthenticatorService and Authenticator in aar library?

Upvotes: 1

Views: 181

Answers (1)

Karan Dhillon
Karan Dhillon

Reputation: 1234

Technically speaking, keeping your AuthenticatorService and the Authenticator classes in a separate Android-Library module for the purpose of reusability should not cause any issues while using it in an android application. What your issue is sharing data between two applications and not multi-modularity. For that you can create a shared local database either using 3rd party libraries or flat files (Whatever suit your needs).

Android provides some useful API that allows IPC for android applications:

If the size of data is small then you can use the SharedPreferences API for that, however it puts a CAP on how much data an app can contribute. As SharedPreferences is Global in nature, i would not suggest storing sensitive data there.

If you want an app to expose some data, then look into how android architecture allows an "Export" directory inside every app where you can store any data and other apps can simply read it in a safe manner. Deleting an application will clear all of the data present in this "Export" directory.

Upvotes: 0

Related Questions