[英]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. 我正在创建一个
aar
库,我需要获得aar
packagename
以获得aar
文件的aar
。
i'm trying below code, but getPackageName()
method didn't return aar
packagename
我正在尝试下面的代码,但
getPackageName()
方法没有返回aar
packagename
Signature[] sigs = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs){
Log.i("MyApp", "Signature hashcode : " + sig.hashCode());
}
The AAR library is only read during compilation time. AAR库仅在编译期间读取。 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.
当您构建使用该库的应用程序时,AAR被“包含”并与应用程序代码合并,因此运行时的PackageName是应用程序中的一个,而不是您的库中的一个。 Signin an AAR file is used to make developers sure about the source of that file, and nothing else.
登录AAR文件用于使开发人员确定该文件的来源,而不是其他任何内容。 In runtime that signature is lost after the build procedure.
在运行时,签名在构建过程后丢失。
You can simply get the package name by accessing a class from the .aar library. 您可以通过访问.aar库中的类来获取包名称。 Suppose you have a class in the library named
Sample.java
, then you can get the package name like this: 假设您在库中有一个名为
Sample.java
的类,那么您可以获得如下所示的包名:
String packageName = Sample.class.getPackage().getName();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.