16

This isn't intended to be a question. Rather, an observation which is a common problem found in Android when you use external APIs for development and android.jar isn't duplicated into your project!

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
curlyreggie
  • 1,530
  • 4
  • 21
  • 31

3 Answers3

10

After searching through various forums, Google and stackoverflow, I seem to get a solution by myself and thought of sharing it.

  1. Whenever you are linking external libraries, better link it by creating a /lib folder and dump those .jars there(means to COPY the files and NOT linking them). Link them using Eclipse -> Build Properties -> Configure Build path -> Library tab -> Add external Jars. Add the required .jars saved in /lib folder in this. (Note that, the jar included as a "Referenced Library" in Eclipse will disappear in /lib folder! But, not to worry as proper linking has happened. Another note is to check that the /lib jar that was referenced should NOT be visible in Libraries tab of Build Properties as it will be inherited.)

  2. Another major problem was when Google APIs are being used. Specially the ones, which use some core library functions of java/javax. Be very careful of this. The error is that, the DalvikVM tries to link these but fails as there is a duplication found and is unable to decide which one to refer to. Below is the error.

    Dx trouble processing "javax/xml/namespace/QName.class": 
    Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.
    

In such cases, what I have observed is that, this class is used in xpp3-1.1.4c.jar. If you've copied this into your /lib folder, PLEASE REMOVE IT. Then clean the project, and give a fresh build. And the ship sails smoothly thereafter.

Do this for other referenced .jars if such duplication exists.

Cheers!

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
curlyreggie
  • 1,530
  • 4
  • 21
  • 31
2

This worked for me. I'm using maven, and the xpp3-1.1.4c dependency shows up under "Maven Dependencies"; I had to exclude it using (right click the dependency) Maven-> "Exclude Maven Artifact...". Thanks a bunch -- this was really obscure.

2

This error show only when you trying to generate signed APK. There are 2 ways to fix this.

1. As commented Amira Elsayed Ismail in this post this we should revert to gradle 2.3.3.

To do this you should also download Android Studio 2.3.3 because studio 3.0.1 require gradle plugin 3.0+

This was the first solution. But reverting Android Studio and gradle plugins is a painful solution.

2. Resolve all dependency conflicts.

When i revert gradle, Studio 2.3.3 showed we interested warnings(i do not know why studio 3.0.1 don't show dependency conflict warnings)

Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for debug as it may be conflicting with the internal version provided by Android. Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.3 is ignored for debug as it may be conflicting with the internal version provided by Android.

So these dependencies are ignored for debug but NOT FOR RELEASE. I fixed this by excluding these dependencies.

configurations {
        all*.exclude group: 'xpp3', module: ['xpp3' ,'httpclient']
    }

After this, i successfully generated signed APK using gradle 3.0.1.(without reverting).

Yuri Popiv
  • 519
  • 4
  • 15