0
votes

so I've just starting playing around with Android Studio and working on an App, pretty basic stuff so far and I'm trying to parse data from a HTML file to my app, I ran across some issues and been googling around for the past few hours and couldn't fix it after all.

Here's the error log:

Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error:  at             com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define     Lorg/jsoup/nodes/Entities$CoreCharset;
Error:  at     java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error:com.android.dex.DexException: Multiple dex files define Lorg/jsoup/nodes/Entities$CoreCharset;
Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error:  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error:  at     java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lorg/jsoup/nodes/Entities$CoreCharset;

Here's my app gradle:

apply plugin: 'com.android.application'

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 26
    defaultConfig {
        applicationId "app.diviwire.transportes"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner     "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/README.md'
        exclude 'META-INF/CHANGES'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:support-compat:26.1.0'
    compile 'com.android.volley:volley:1.0.0'
    // jsoup HTML parser library @ https://jsoup.org/
    compile 'org.jsoup:jsoup:1.11.2'
    compile 'com.android.support:multidex:1.0.1'
}

Tell my if there's something else missing, not sure what to add more since I'm just starting. Thanks in advance guys!

EDIT: So I've followed @IntelliJ Amiya suggestion and apparently it's still not working, I've probably done something wrong but here's my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.diviwire.transportes">

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:name="android.support.multidex.MultiDexApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainMenuActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".BoatMenuActivity" />
    <activity android:name=".HorarioBarcoBarreiroActivity" />
</application>

And I also added the following to my Activity:

@Override
protected void attachBaseContext(Context base){
    super.attachBaseContext(base);
    MultiDex.install(this);
}

It's still giving me the same error.

2
well , have tried clean project ?duggu
@duggu yea I have tried all that, Cleaning, Rebuilding, Restarting the IDE...Wireless
@IntelliJAmiya I've added the multiDexEnabled true statement and the compile but I had some issues with the rest since I'm just starting but will look into it more deeplyWireless
@IntelliJAmiya alright, you've helped enough already :D ThanksWireless

2 Answers

0
votes

You reached maximum memory allocation pool for a Java Virtual Machine (JVM) for dex operation so you have to increase the size of pool memory.

Just you have added below code in an android project, build.gradle file.

dexOptions{
javaMaxHeapSize "4g"
}

it is just an option to specify the maximum memory allocation pool for a Java Virtual Machine (JVM) for dex operation.

4g is 4 Gigabytes and this is a maximum heap size for dex operation.

0
votes

In the build Gradle under dependencies add classpath 'com.android.tools:r8:1.6.84' It worked for me.