为什么 Android 应用程序项目必须包含库使用的包
Why does an Android app project have to include a package used by a library
一个 Android 应用程序使用了一个使用 "com.google.gson.Gson" 的库(aar 模块)。该库的 build.gradle 中包含以下内容:
compile 'com.google.code.gson:gson:2.6.2'
该应用构建良好,但在启动时生成以下错误:
Failed resolution of: Lcom/google/gson/Gson;
解决它的唯一方法是将相同的编译行添加到应用程序的 build.gradle:
compile 'com.google.code.gson:gson:2.6.2'
有人能解释一下吗?
[编辑]
库中添加了 the standard procedure,它在名为 "androidLibrary-release" 的应用程序下创建了一个文件夹。以下行已添加到应用程序的 build.gradle:
compile project(':androidLibrary-release')
库不包含它们的依赖项。开发人员可以根据需要将它们包含在实现它们的应用程序模块中。但是,如果此库来自 Maven 存储库,则可以包含有关该库使用哪些依赖项的信息,这些信息将在您的项目构建时获取。
一个 Android 应用程序使用了一个使用 "com.google.gson.Gson" 的库(aar 模块)。该库的 build.gradle 中包含以下内容:
compile 'com.google.code.gson:gson:2.6.2'
该应用构建良好,但在启动时生成以下错误:
Failed resolution of: Lcom/google/gson/Gson;
解决它的唯一方法是将相同的编译行添加到应用程序的 build.gradle:
compile 'com.google.code.gson:gson:2.6.2'
有人能解释一下吗?
[编辑]
库中添加了 the standard procedure,它在名为 "androidLibrary-release" 的应用程序下创建了一个文件夹。以下行已添加到应用程序的 build.gradle:
compile project(':androidLibrary-release')
库不包含它们的依赖项。开发人员可以根据需要将它们包含在实现它们的应用程序模块中。但是,如果此库来自 Maven 存储库,则可以包含有关该库使用哪些依赖项的信息,这些信息将在您的项目构建时获取。