在我们的(Android/IOS)应用程序中,我们使用各种第三方库,例如 GSON(适用于 Android)。在 IOS 中,可以从 POD 读取数据(例如许可信息)并将其显示在应用程序中。
有没有办法在 Android/Gradle 中做类似的事情?
澄清一下,我使用 Gradle 编译了以下依赖项:
compile 'com.koushikdutta.ion:ion:2.1.+'
compile 'com.google.code.gson:gson:2.6.+'
我想在我的应用程序中有一个显示许可证文件的屏幕
https://github.com/google/gson/blob/master/LICENSE https://github.com/koush/ion/blob/master/LICENSE
许可证检索不需要在应用程序的 Java 代码中发生,它可以在编译时完成,在 Gradle 中使用这种逻辑:
对于每个依赖包 检查许可证文件 将 LICENSE 文件连接到 res/licenses.txt 结束
在应用程序中,有一些代码来显示 licenses.txt(或 licenses.xml,如果需要的话)
最佳答案
我会回复旧帖。最近添加了一个用于执行此操作的库。 https://developers.google.com/android/guides/opensource
这些包括 Gradle 插件“com.google.gms.oss.licenses.plugin”,用于从依赖库的 pom 获取许可信息, 它由库“play-services-oss-licenses”组成,它提供 Activity 来显示许可证。
将其添加到dependencies中并构建,会在app/src/main/res/raw目录下生成一个文件,其中列出了项目所依赖的库的license信息。
之后,您可以通过调用 Activity 来显示许可证列表屏幕,如下所示。
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
val intent = Intent(this, OssLicensesMenuActivity::class.java)
intent.putExtra("title", "Open source license")
startActivity(intent)
关于java - Android 以编程方式从 jar 中检索许可证信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38128826/