简体   繁体   中英

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'
        }

In my library module called MyLib , I've added (for example) Gson & Volley as library.

I wish to use Gson and Volley api in the MyProject module without adding the libraries again as dependencies but I can't. And when I add Gson or Volley in the MyProject build.gradle , it causes an error:

multiple dex files define

How can I reuse dependencies that already added in the MyLib module? If this is not possible, how do I avoid this multiple dex files define error? I've tried Android Studio Gradle Error: Multiple dex files define

dexOptions {
    preDexLibraries = false
}

but it didn't help.

Thanks in advance.

If you wish to use the Volley and Gson libraries in each of your modules, you will need to add both libraries as dependencies in both of your build.gradle files ( MyProject and MyLib ).

As for the multiple dex files define error, I would try taking a look at these potential solutions:

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM