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

android studio how to use library dependencies already added in library module

--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 build error - Multiple dex files define Landroid/support/v4/
  • Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;

祝你好运!