3

I am trying to build my android project. I could not understand even if the **rt.jar** which contains classes of,

 **javax.sound.*.**
 **java.awt.*.**
 **java.awt.** 

is already there in the jdk1.7/jar folder and also it can be loaded seen under IDE librarie/java but it gives me the error of saying the library classes not found. When i imported the library to the project and build it it says,

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: javax/xml/XMLConstants.class

duplication error of classes. How come this happen?

Any help will be really appreciated to overcome this issue.

Please find the build.gradle file here,

apply plugin: 'com.android.application'

android {

    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "info.androidhive.sleepApp"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0+'
}

This is the gradle error:

 Information:Gradle tasks [:app:assembleDebug]
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
    :app:preReleaseBuild UP-TO-DATE
    :app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
    :app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
    :app:prepareComAndroidSupportRecyclerviewV72220Library UP-TO-DATE
    :app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
    :app:prepareDebugDependencies
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:processDebugManifest UP-TO-DATE
    :app:processDebugResources UP-TO-DATE
    :app:generateDebugSources UP-TO-DATE
    :app:processDebugJavaRes UP-TO-DATE
    :app:compileDebugJava UP-TO-DATE
    :app:compileDebugNdk UP-TO-DATE
    :app:compileDebugSources UP-TO-DATE
    :app:collectDebugMultiDexComponents UP-TO-DATE
    :app:packageAllDebugClassesForMultiDex FAILED
    Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
    > java.util.zip.ZipException: duplicate entry: javax/xml/XMLConstants.class
    Information:BUILD FAILED
    Information:Total time: 6.793 secs
    Information:1 error
    Information:0 warnings
    Information:See complete output in console
AshanD
  • 527
  • 5
  • 22
  • 1
    Remove compile files('libs/rt.jar') from your build.gradle file. – pepan Feb 16 '16 at 15:41
  • 1
    removed it but getting the same error. – AshanD Feb 16 '16 at 15:43
  • 1
    Actually, remove all the compile files('libs/ something') from your build.gradle file – pepan Feb 16 '16 at 15:47
  • tried it as well. getting the same error no changes at all. :( im struggling with this for days. – AshanD Feb 16 '16 at 15:52
  • 2
    It means that you are adding javax/xml/XMLConstants twice. check your dependencies – Gabriele Mariotti Feb 16 '16 at 15:58
  • actually XMLConstants.class is coming default in the jdk(rt.jar) but when i imported it to the project it says class is not found and that is why i put the rt.jar into the library thatz why the duplication happen how to overcome this? – AshanD Feb 16 '16 at 16:02
  • 1
    Ok. Two things: First: Keep the number of dependencies as low as possible. If you are able to compile without any of them, just remove them. Second: clearly you've got 2 libraries both having XMLConstants.class. You need to find them and get rid of one of them. First find which of the dependencies are bringing this class. – pepan Feb 16 '16 at 16:06
  • @pepan actually jdk comes with rt.jar by default but i don't know why my code cannot import them and asking for the classes which is already there in the rt.jar. – AshanD Feb 16 '16 at 16:10
  • I know what rt.jar is. I don't understand much why you are specifying the import in build.gradle; this is IMHO wrong. In none of my gradle projects I was specifying imports from rt.jar. If gradle complains on class not found, then you probably don't have your android SDK or whatever setup properly. – pepan Feb 16 '16 at 16:13
  • @pepan i removed the imports from build.gradle. but it gives me the same errors. :( – AshanD Feb 16 '16 at 16:19
  • I'm a bit lost, can you please update how the build.gradle looks now? – pepan Feb 16 '16 at 16:23
  • sorry for troubling, im struggling with this build for days. :( please check the updated gralde.build thank you – AshanD Feb 16 '16 at 16:26

1 Answers1

1

Check this question u might get and idea about java swing in android platform.

how to import javax.swing in android studio

Community
  • 1
  • 1
nayakPan
  • 98
  • 6