0

I am trying to import caldav4j library (caldav4j-0.7.jar) into my android studio project. I have the following two lines in my build.gradle file.

compile 'org.mnode.ical4j:ical4j:1.0.6'
compile files('libs/caldav4j-0.7.jar')

I am seeing multiple dex files defined error due to ical4j library because caldav4j-0.7.jar also has ical4j library defined as a maven dependency.

<dependency>
  <groupId>net.fortuna.ical4j</groupId>
  <artifactId>ical4j</artifactId>
  <!--version>1.0-rc1-SNAPSHOT</version--><!-- patched on localhost-->
  <version>1.0</version>
</dependency>

If I try to not to import ical4j separately by removing the first line,

compile 'org.mnode.ical4j:ical4j:1.0.6'

then I don't have access to ical4j package at all.. What I want to achieve is being able to import any classes from ical4j package. Is it normal for a maven project to not expose its dependencies' packages? Then how am I supposed to use ical4j inside my project? All import statements for ical4j library fails if I remove that line from build.gradle.

import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.ComponentList;
import net.fortuna.ical4j.model.component.VEvent;

In short:

I want to import ical4j library but,

  1. It gives me multiple dex files defined error if I separately add a line to build.gradle because of the conflicts with the internal dependency defined in caldav4j.jar.

  2. If I remove that line, I don't have access to ical4j library at all because caldav4j.jar does not expose its dependencies..

Thanks for your help in advance :)

CoderSpinoza
  • 2,145
  • 23
  • 28

2 Answers2

1

It should be a comment, because I am not sure about it, but it is too long. I will remove it if it is wrong.

First of all, you should be able to import the caldav4j library using a gradle dependency.

Add the caldav4j repo to your build.gradle

repositories {
    mavenCentral()
    maven { url "https://caldav4j.googlecode.com/svn/maven" }    
}

Then you can use

compile('org.osaf:caldav4j:0.7') {
        exclude group: 'net.fortuna.ical4j', module: 'ical4j'
    }

However I am not sure that it can work because I don't know if 1.0.6 is full compatible with 1.0 in the pom file:

<dependency>
      <groupId>net.fortuna.ical4j</groupId>
      <artifactId>ical4j</artifactId>
      <!--version>1.0-rc1-SNAPSHOT</version--><!-- patched on localhost-->
      <version>1.0</version>
    </dependency>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • I already tried this but have encountered a different error which says: trouble processing "javax/xml/parsers/DocumentBuilder.class": Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library. – CoderSpinoza May 26 '15 at 16:07
1

Have a look at this answer, it pretty much tells you how to list out what's conflicting,

Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

Run gradle -q dependencies (or gradle -q :projectName:dependencies) to generate a dependency report. You should see where r7 is coming from, such as:

compile - Classpath for compiling the main sources.
+--- com.commonsware.cwac:camera-v9:0.5.4
|    +--- com.actionbarsherlock:actionbarsherlock:4.4.0
|    |    \--- com.google.android:support-v4:r7
|    +--- com.commonsware.cwac:camera:0.5.4
|    \--- com.android.support:support-v4:18.0.+ -> 18.0.0
\--- com.android.support:support-v4:18.0.+ -> 18.0.0

Then, use the exclude directive to block that dependency.

dependencies {
    compile('com.commonsware.cwac:camera-v9:0.5.4') {
      exclude module: 'support-v4'
    }

    compile 'com.android.support:support-v4:18.0.+'
}

(where the second compile statement indicates what version you actually want)

Community
  • 1
  • 1
Hades
  • 3,916
  • 3
  • 34
  • 74