androidandroid-libraryaarpackage-name

How to get packagename of aar file?


I'm creating an aar library and i need to get aar packagename for having sign of aar file.

i'm trying below code, but getPackageName() method didn't return aar packagename

Signature[] sigs = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs){
    Log.i("MyApp", "Signature hashcode : " + sig.hashCode());
}

Solution

  • The AAR library is only read during compilation time. When you build an App that uses that library the AAR is "included" and merged with the App code, so the PackageName in runtime is the one of the App and not the one of your library. Signin an AAR file is used to make developers sure about the source of that file, and nothing else. In runtime that signature is lost after the build procedure.