Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having different dependencies in grade builds?

I have a debug build and a release build of an android application however I need different dependencies for each, is this possible in Android Studio?

I have the section:

buildTypes {
        debug {
            minifyEnabled false
        }
        release {
            minifyEnabled true
        }
}

and a section for the dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'joda-time:joda-time:2.7'
    compile 'org.joda:joda-convert:1.4'
}

I want to remove the joda-convert dependancy if I am using the debug build as it results in "duplicate files in packaging of APK" error.

Any help greatly appreciated?

like image 336
Apqu Avatar asked Sep 30 '15 10:09

Apqu


People also ask

Are Gradle dependencies stored in builds?

The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. The dependencies can be located on your machine or in a remote repository, and any transitive dependencies they declare are automatically included as well.

Can you have multiple build Gradle files?

gradle for one project? Yes. You can have multiple build files in one project.

Does Gradle dependencies order matter?

This isn't necessary. The order inside the dependencies { } block is preserved. You are kind of right. Dependency ordering is preserved, but for example all compile dependencies will be before testCompile dependencies no matter of how you order them.

Why are there multiple build Gradle files?

By default, the project-level Gradle file uses buildscript to define the Gradle repositories and dependencies. This allows different projects to use different Gradle versions.


Video Answer


2 Answers

From the Android gradle documentation:

The compile configuration is used to compile the main application. Everything in it is added to the compilation classpath and also packaged in the final APK. There are other possible configurations to add dependencies to:

  • compile: main application
  • androidTestCompile: test application
  • debugCompile: debug Build Type
  • releaseCompile: release Build Type.
like image 45
xiaomi Avatar answered Sep 27 '22 17:09

xiaomi


you can use

releaseCompile 'org.joda:joda-convert:1.4'

then joda-convert is only used for release

like image 177
ligi Avatar answered Sep 27 '22 18:09

ligi