0

What does this error mean and how do I fix it?

"Cannot fit requested classes in a single dex file (# methods: 86421 > 65536)" and

Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete

I am trying to connect a database to my app and I am getting this error in my console and I do not know what to do. also I am using firebase as my database.

This is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.tastebuds"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        //multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-firestore:21.3.0'
    implementation 'com.google.firebase:firebase-storage:19.1.0'
    implementation 'com.google.firebase:firebase-database:19.2.0'
    //implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'

This is the my CreateProfile

package com.example.tastebuds;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

public class CreateProfile extends AppCompatActivity {

EditText CPFname, CPLname, DOB, CPstate, CPcity, CPzip, CPbio;
ImageButton savebtn, cambtn;
ImageView pic;

FirebaseDatabase database;
DatabaseReference ref;
User user;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_profile);

    CPFname = (EditText) findViewById(R.id.CPFname);
    CPLname = (EditText) findViewById(R.id.CPLname);
    DOB = (EditText) findViewById(R.id.DOB);
    CPstate = (EditText) findViewById(R.id.CPstate);
    CPcity = (EditText) findViewById(R.id.CPcity);
    CPzip = (EditText) findViewById(R.id.CPzipcode);
    CPbio = (EditText) findViewById(R.id.CPbio);
    savebtn = (ImageButton) findViewById(R.id.CPsavebtn);
    cambtn = (ImageButton) findViewById(R.id.CPcamera);
    pic = (ImageView) findViewById(R.id.CPprofilepic);

    database = FirebaseDatabase.getInstance();
    ref = database.getReference("users");
    user = new User();
}

private void getValues()
{
    user.setFirstName(CPFname.getText().toString());
    user.setLastName(CPLname.getText().toString());
    user.setDOB(DOB.getText().toString());
    user.setcity(CPcity.getText().toString());
    user.setstate(CPstate.getText().toString());
    user.setzip(CPzip.getText().toString());
    user.setbio(CPbio.getText().toString());
}

public void savebtn(View view)
{
    ref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        ref.child("users03").setValue(user);
        getValues();
        Toast.makeText(CreateProfile.this, "Data is inserted....",
        Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}

//    savebtn.setOnClickListener(new View.OnClickListener)
//    Intent intoHomeFeed = new Intent(CreateProfile.this, HomeFeed.class);
//    startActivity(intoHomeFeed);
}
Shiladitya
  • 12,003
  • 15
  • 25
  • 38
Jtigg
  • 97
  • 1
  • 1
  • 5
  • Possible duplicate of [Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536](https://stackoverflow.com/q/48249633/5221149) – Andreas Nov 29 '19 at 02:12
  • Possible duplicate of [Android gives error “Cannot fit requested classes in a single dex file”](https://stackoverflow.com/q/51341627/5221149) – Andreas Nov 29 '19 at 02:12
  • Some of your Firebase dependencies are rather old. Update them to the latest versions. https://firebase.google.com/support/release-notes/android – Doug Stevenson Nov 29 '19 at 02:51
  • 1
    Enable multiDex – vizsatiz Nov 29 '19 at 06:16

0 Answers0