user4813855
user4813855

Reputation:

Android _ failed for task ':app:packageAllDebugClassesForMultiDex' _ AbstractDateTime.class?

My Project was working fine, when I have added bellow code in my project get me error, I add :

compile 'joda-time:joda-time:2.7'
compile 'net.danlew:android.joda:2.8.0'

Here is my build.gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "us.app.recyclerview_multiselect"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        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:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'joda-time:joda-time:2.7'
    compile 'net.danlew:android.joda:2.8.0'
}

This is the picture of error :

enter image description here

I am using from joda-time:joda-time:2.7 and net.danlew:android.joda:2.8.0 in this page, The JodaTimeAndroid.init(this); is for compile 'net.danlew:android.joda:2.8.0' :

import android.app.Application;
import android.util.SparseArray;
import net.danlew.android.joda.JodaTimeAndroid;
import org.joda.time.DateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RecyclerViewDemoApp extends Application {

    private static List<DemoModel> demoData;
    private static SparseArray<DemoModel> demoMap;

    @Override
    public void onCreate() {
        super.onCreate();
        JodaTimeAndroid.init(this);
        Random r = new Random();
        demoData = new ArrayList<DemoModel>();
        demoMap = new SparseArray<DemoModel>();
        for (int i = 0; i < 20; i++) {
            DemoModel model = new DemoModel();
            DateTime dateTime = new DateTime();
            dateTime = dateTime.minusDays(r.nextInt(30));
            model.dateTime = dateTime.toDate();
            model.label = "Test Label No. " + i;
            demoData.add(model);
            demoMap.put(model.id, model);
        }
    }

    public static final List<DemoModel> getDemoData() {
        return new ArrayList<DemoModel>(demoData);
    }

    public static final List<DemoModel> addItemToList(DemoModel model, int position) {
        demoData.add(position, model);
        demoMap.put(model.id, model);
        return new ArrayList<DemoModel>(demoData);
    }

    public static final List<DemoModel> removeItemFromList(int position) {
        demoData.remove(position);
        demoMap.remove(demoData.get(position).id);
        return new ArrayList<DemoModel>(demoData);
    }

    public static DemoModel findById(int id) {
        return demoMap.get(id);
    }
}

Upvotes: 2

Views: 165

Answers (1)

Vedran Kopanja
Vedran Kopanja

Reputation: 1299

Why do you have two joda times in your Gradle script? I always used just this one, and it works fine: compile 'joda-time:joda-time:2.8.1'

I'm guessing there's probably a conflict between those two.

Upvotes: 2

Related Questions