android studio如何使用库模块中已经添加的库依赖项

标签 android android-studio build.gradle

--MyProject (module)
    --build.gradle
        dependencies {
            compile fileTree(include: ['*.jar'], dir: 'libs')
            compile 'com.android.support:appcompat-v7:22.2.1'
            compile project ':MyLib'
        }
--MyLib (module)
    --build.gradle
        dependencies {
            compile 'com.mcxiaoke.volley:library:1.0.16'
            compile 'com.google.code.gson:gson:2.3.1'
        }

在我名为 MyLib 的库模块中,我添加了(例如)Gson 和 Volley 作为库。

我希望在 MyProject 模块中使用 GsonVolley api,而无需再次添加库作为依赖项,但我不能。当我在 MyProject build.gradle 中添加 GsonVolley 时,会导致错误:

multiple dex files define

如何重用已添加到 MyLib 模块中的依赖项?如果这不可能,我如何避免此 multiple dex files define 错误?我试过了 Android Studio Gradle Error: Multiple dex files define

dexOptions {
    preDexLibraries = false
}

但这并没有帮助。

提前致谢。

最佳答案

如果您希望在每个模块中使用 VolleyGson 库,您需要将这两个库作为依赖项添加到both 你的 build.gradle 文件(MyProjectMyLib)。

至于 multiple dex files define 错误,我会尝试看看这些可能的解决方案:

祝你好运!

关于android studio如何使用库模块中已经添加的库依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31970790/

相关文章:

android - 主进程死后静态变量仍然有效?

android - 需要在新 Activity 中显示结果

Android Studio 没有显示任何与 Android 相关的选项

Android Studio 更新 0.4.0 找不到 buildConfig()

gradle 找不到其他 gradle 脚本

android - Eclipse 在 Android Studio 中导出项目并在 build.gradle 中添加远程依赖

Android Studio - 无法找到请求目标的有效认证路径

java - java中的多个异步请求处理

java - 无法将 android.support.v4.view.MenuItemCompat 转换到 android.widget.ShareActionProvider

android - Gradle 无法通过 Nexus 解决依赖关系,但会在浏览器中下载 Artifact