--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
模块中使用 Gson
和 Volley
api,而无需再次添加库作为依赖项,但我不能。当我在 MyProject
build.gradle
中添加 Gson
或 Volley
时,会导致错误:
multiple dex files define
如何重用已添加到 MyLib
模块中的依赖项?如果这不可能,我如何避免此 multiple dex files define
错误?我试过了 Android Studio Gradle Error: Multiple dex files define
dexOptions {
preDexLibraries = false
}
但这并没有帮助。
提前致谢。
最佳答案
如果您希望在每个模块中使用 Volley
和 Gson
库,您需要将这两个库作为依赖项添加到both 你的 build.gradle
文件(MyProject
和 MyLib
)。
至于 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;
祝你好运!
关于android studio如何使用库模块中已经添加的库依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31970790/