android - 如何从API Docs中找到Android类对应的maven artifact/gradle module?

标签 android maven gradle

如果我想使用来自 Android API 的特定 Android 类,有没有办法找出我必须包含哪个 maven Artifact 或 gradle 模块 文档类?

例如,如果我遇到新的 SelectionTracker 类(在 https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker ), 那么我怎么知道我需要添加以下androidx模块

dependencies {
  implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
}

到我的 gradle 文件?

这个我是看教程网站才知道的,因为Api网页好像只提了java包名。至少我发现 https://developer.android.com/jetpack/androidx/migrate#artifact_mappings 每当一些较旧的教程仅提及较旧的支持库模块名称时,检索相应的 androidx 模块。

最佳答案

对此没有黄金法则。

在 Maven 项目(我使用 IntelliJ)中,我通常在代码中提到类(这会导致编译器错误),然后使用 Alt+Enter 打开快速修复。在那里,IntelliJ 将提供导入类的可能性,如果它在类路径上找到,或者让我“添加 [a] Maven 依赖项”。如果我选择“添加 Maven 依赖项”,将出现一个搜索工具,允许我按类名搜索 Maven Central。但是,我遇到过很多搜索找不到任何东西的情况。我怀疑 Android Studio 具有类似的 gradle 功能(因为 Android Studio 构建在 IntelliJ 之上)。

如果这不起作用,java 包名称应该会提示您有关依赖项的组 ID,因为它们使用相同的命名约定:例如,类 com.github.vatbub.randomusers。生成器 位于com.github.vatbub.randomusers 包中。相应的 Maven Artifact 具有组 ID com.github.vatbub 和 Artifact ID randomusers。同样,情况并非总是如此,但它可以给您一些提示。

如果这也没有帮助,Google(或 Maven Central)是您的 friend ;)

关于android - 如何从API Docs中找到Android类对应的maven artifact/gradle module?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53760393/

相关文章:

android - 将 Unity 应用程序添加到新的结构组织、现有的 firebase 项目

android - 基于Google或其他帐户在自己的网站上注册用户帐户

android - 资源条目 activity_horizo​​ntal_margin 已定义

android - Google Play 服务 Jar 文件 Java 文档和源代码

android - 如何为 ImageView 赋予六边形形状

Jacoco、JMockit 和 JDK14 的 Maven surefire 插件问题

intellij-idea - IntelliJ IDEA中的Xtend无法在src-gen中生成文件

android - 无法实例化应用程序 java.lang.ClassNotFoundException。未在路径 : DexPathList 上找到类 "Application"

maven - 如何在另一个项目中向Spring Boot Jar添加依赖项?

maven - JavaFX maven 程序集警告 : "Cannot include project artifact ... it doesn' t have an associated file or directory"