I see that I can specify gradle dependencies like this:
dependencies {
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.8.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.1'
}
but also like this:
dependencies {
compile(
'com.fasterxml.jackson.core:jackson-annotations:2.8.1',
'com.fasterxml.jackson.core:jackson-core:2.8.1',
'com.fasterxml.jackson.core:jackson-databind:2.8.1'
)
}
This means that the compile configuration applies to a single element but also to a list of elements. Where do I find more details about the compile semantics? I'm referring also to details like the exclude module clause:
dependencies {
compile('org.simpleframework:simple-xml:2.7.1') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
}
I've seen this page, but it doesn't contain this kind of details. Does Android Studio offer some kind of help to learn Gradle semantics?
Here is the DependencyHandler DSL documentation.
You can access Gradle API documentation from Android Studio like javadocs for Android framework APIs eg. using Quick Documentation shortcut (in default keymap Ctrl+Q or F1 on OS X).
You have to use Gradle all distribution. Eg. if you are using gradle wrapper it can be set in gradle/wrapper/gradle-wrapper.properties like that:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Related
So I'm using the mapbox-sdk for android in my project to display the map with a particular customer's location. However, simply adding mapbox has made my app extremely bulky, and I want to reduce its size by somehow excluding some of the groups/modules from mapbox in the gradle. But I don't know which ones to exclude since I don't know how to get a list of them.
Is there any way to get a list of groups/modules that are automatically integrated with the integration of the mapbox sdk? Which ones should I specifically exclude?
This is the sdk that I'm using:
implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:5.2.1') {
transitive = true
}
Use latest mapbox.
repositories {
mavenCentral()
}
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.0'
}
you can use exclude group like below, to remove certain dependencies:
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.0'){
exclude group: 'group_name', module: 'module_name'
}
Run 'gradlew :app:dependencies' in your command line will print a list of dependencies.
It will show list of modules in mapbox. try excluding one or more modules as
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.0') {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-sdk-turf'
}
ReRun 'gradlew :app:dependencies' in your command line will print a list of dependencies, you will see that excluded library is not in list.
Note: also use 'transitive = false' if you don't want transitive dependency to be considered for dependency resolution.
I got this error message when trying to add RxPresso(https://github.com/novoda/rxpresso/) to my project:
Warning:Conflict with dependency 'io.reactivex:rxjava'. Resolved versions for app (1.1.9) and test app (1.0.14) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I'm currently using rxjava 1.1.9. How can I add RxPresso in my project?
Thx a lot
To avoid any problems with RxJava and Android Support Libraries version, go to your app/build.gradle file and in dependencies section paste:
androidTestCompile ('com.novoda:rxpresso:0.2.0') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'io.reactivex'
}
You can explicitly tell Gradle which version to use, by adding into your build.gradle next snippet
configurations.all {
// check dependency tree with gradlew :app:dependencies
// avoid wildcard '+' dependencies used at 3rd libraries forcing them to exact version
resolutionStrategy.force "io.reactivex:rxjava:1.1.9"
}
I am trying to remove the transitive dependencies from my Android project and for some reason exclude is not working when i try to remove a dependency from my particular dependency.
For example i want to remove support-annotations from my project
if i use
configurations {
all*.exclude group: 'com.android.support', module:'support-annotations'
}
The dependency gets excluded and from the dependency tree. i can see the dependency tree by using ./gradlew app:dependencies
But if i use
compile('com.android.support:support-v4:23.4.0')
{
exclude group: 'com.android.support', module:'support-annotations'
}
Then i still see the dependency in the dependency tree.
So my question is that why is it not working when i try to remove the dependency from a particular dependency ?
Update 1:
Also can anyone tell me what does the star (*) symbol next to dependency in the tree represent ?
Update 2
I am also using Fresco I tried the same thing with Fresco and exclude rule seems to work for it
Dependency Tree of Fresco
Dependency Tree when i exclude imagepipeline-base in Fresco
compile("com.facebook.fresco:fresco:0.9.0")
{
exclude group: 'com.facebook.fresco', module: 'imagepipeline-base'
}
As you can see the imagepipeline-base dependency gets excluded. So i don't know why this doesn't work for Android Support Annotations transitive dependency
So i have figured this out with the help of one of my friends. The reason why i was not able to remove support-annotation was because most of the other dependencies were using support-v4 as transitive dependency and those support-v4 also had their own copy of support-annotation.
Now there are 2 solutions to this
Solution 1:
exclude support-annotation from all the dependencies that containsupport-v4 as transitive dependency.
Solution 2:
exclude support-annotation only from my support-v4 dependency and remove support-v4 dependency from all other dependencies that have support-v4 as transitive dependency.
Note: Using one of the above approaches i was able to solve my problem and figure out how we can remove transitive dependencies when they are referenced from multiple dependencies.
And regarding the ( * ) symbol it means that the dependency tree is for that dependency is already shown. Instead of showing the whole tree for those dependencies again gradle shows ( * ) symbol with them.
Sample build.gradle file is available here
There is more graceful solution: you can use configueation.all block in your build.gradle file like in example below:
configurations.all {
exclude group: 'com.android.support', module: 'support-annotations'
}
It should exclude all transitive dependencies from all inner modules in your application.
In my Android project, I use a library that comes as a jar.
I include it in the dependencies section like so:
dependencies {
...
compile files('libs/thethirdpartylibrary.jar')
...
}
I also want to use the okhttp library, which I include like this:
compile ('com.squareup.okhttp:okhttp:2.7.5')
(This particular version of okhttp depends on okio 1.6.0.)
The problem is that the thirdparty jar library depends on okio v0.9.0 and what's worse, bundles it.
As a result, I get a dex conflict error at build time.
I was able to resolve this by manually removing okio from the jar file and this seems to work. But I'm wondering if there's a way to do this in gradle.
My question: Can I remove bundled, transitive ( <- I hope I'm using this word the right way) dependencies from an included jar during build-time with gradle?
Exclude the Group in the dependencies by using the below lines.
1.
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
2.
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile ("com.xxx:xxx-commons:1.+") {
exclude group: 'junit', module: 'junit'
}
}
3.
configurations {
runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}
Try this one.
For more detail
According to this discussion here https://groups.google.com/forum/#!topic/adt-dev/g1AiJM7PeVs, what you want to do is not possible.
The syntax suggested in the other answers is for "normal" Maven dependencies.
I am trying to solve the problem,
I have some dependencies declared in build.gradle file for my android app, but the problem is that a lot of these dependencies use the same compat library, in my case appcompat-v7.
It is possible to exclude this library for each dependency
compile ('com.github......'){
exclude group: 'com.android.support', module: 'appcompat-v7'
}
But I need to do this in for each dependency
Another way is to use such expression
configurations {
compile.exclude module: 'appcompat-v7'
}
This works, but even If declare this library explicitly it is ignored compile 'com.android.support:appcompat-v7:+'
All what I need it is to include this library only once for the whole app, because if compile without exclude it will show a lot of errors like has been already defined.
Maybe there is an easier way to get this working. I would be grateful for any help, thanks.
We use a provided configuration in gradle (so that when we gradle:eclipse, the packages are included, but are not included when compiled into a jar, as these jars are expected to be provided at runtime). This configuration looks like the following:
configurations {
provided {
dependencies.all {dep ->
configurations.default.exclude group: dep.group, module:dep.name
}
}
compile.extendsFrom provided
}
This allows us to include dependencies as follows:
dependencies {
compile("org.scala-lang:scala-library:2.11.7")
compile("org.scala-lang:scala-compiler:2.11.7")
provided("org.apache.spark:spark-core_2_11:2.0.0")
}
Try creating a configuration which contains all dependencies where you want to exclude appcompat-v7, and then extend compile from this new configuration.