ducksim
ducksim

Reputation: 5

I need help TT firebase use error

I am a private studying code in Korea. Member management coding using firebase is in progress. Failed to resolve error in connection with RegisterActivity post profile.TT We use this video as a reference. here > https://www.youtube.com/watch?v=YfoTdnI3IKs

this is code ↓↓↓↓

RegisterActivity.java

private EditText reg_email_field;
private EditText reg_pass_field;
private EditText reg_confirm_pass_field;
private Button reg_btn;
private Button reg_login_btn;
private ProgressBar reg_progress;

private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    mAuth = FirebaseAuth.getInstance();


    reg_email_field = (EditText) findViewById(R.id.reg_email);
    reg_pass_field = (EditText) findViewById(R.id.reg_pass);
    reg_confirm_pass_field = (EditText) findViewById(R.id.reg_confirm_pass);
    reg_btn = (Button) findViewById(R.id.reg_btn);
    reg_login_btn = (Button) findViewById(R.id.reg_login_btn);
    reg_progress = (ProgressBar) findViewById(R.id.reg_progress);

    reg_login_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            finish();
        }
    });


    reg_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String email = reg_email_field.getText().toString().trim();
            String pass = reg_pass_field.getText().toString().trim();
            String confirm_pass = reg_confirm_pass_field.getText().toString().trim();

            //이메일 공란일 때
            if (TextUtils.isEmpty(email)) {
                Toast.makeText(getApplicationContext(), "이메일을 설정해주세요:)", Toast.LENGTH_LONG).show();
                return;
            }

            //비밀번호 공란일 때
            if (TextUtils.isEmpty(pass)) {
                Toast.makeText(getApplicationContext(), "비밀번호를 설정해주세요:)", Toast.LENGTH_LONG).show();
                return;
            }

            //비밀번호 자릿수가 6자리 미만일 때
            if (pass.length() < 6) {
                Toast.makeText(getApplicationContext(), "비밀번호는 6자 이상만 가능합니다!", Toast.LENGTH_LONG).show();
                return;
            }

            //이메일이 , 패스워드, 확인창이 채워져 있는 경우

            if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass) & !TextUtils.isEmpty(confirm_pass)){

                if(pass.equals(confirm_pass)){

                    reg_progress.setVisibility(View.VISIBLE);

                    mAuth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {

                            if(task.isSuccessful()){

                                Intent setupIntent = new Intent(RegisterActivity.this, SetupActivity.class);
                                startActivity(setupIntent);
                                finish();

                            } else {

                                String errorMessage = task.getException().getMessage();
                                Toast.makeText(RegisterActivity.this, "Error : " + errorMessage, Toast.LENGTH_LONG).show();

                            }

                            reg_progress.setVisibility(View.INVISIBLE);

                        }
                    });

                } else {

                    Toast.makeText(RegisterActivity.this, "비밀번호가 일치하지않습니다.", Toast.LENGTH_LONG).show();

                }

            }

        }
    });


}

@Override
protected void onStart() {
    super.onStart();

    FirebaseUser currentUser = mAuth.getCurrentUser();
    if(currentUser != null){

        sendToMain();

    }

}

private void sendToMain() {

    Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
    startActivity(mainIntent);
    finish();

}

}

SetupActivity.java

`public class SetupActivity extends AppCompatActivity {

//xml 레이아웃
private CircleImageView setupImage;
private Uri mainImageURI = null;

private String user_id;

private boolean isChanged = false;

private EditText setupName;
private Button setupBtn;
private ProgressBar setupProgress;

private StorageReference mStorageRef;
private FirebaseAuth firebaseAuth;
private FirebaseFirestore firebaseFirestore;

private Bitmap compressedImageFile;

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

    Toolbar setupToolbar = findViewById(R.id.setupToolbar);
    setSupportActionBar(setupToolbar);
    getSupportActionBar().setTitle("계정 설정");

    //파이어베이스 이용 인스턴스

    firebaseAuth = FirebaseAuth.getInstance();


    //firebaseAuth의 사용자를 호출
    user_id = firebaseAuth.getCurrentUser().getUid();

    firebaseFirestore = FirebaseFirestore.getInstance();
    mStorageRef = FirebaseStorage.getInstance().getReference();


    setupImage = findViewById(R.id.setup_image);
    setupName = findViewById(R.id.setup_name);
    setupBtn = findViewById(R.id.setup_btn);
    setupProgress = findViewById(R.id.setup_progress);

    setupProgress.setVisibility(View.VISIBLE);
    setupBtn.setEnabled(false);

    firebaseFirestore.collection("Users").document(user_id).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {

            if (task.isSuccessful()) {

                if (task.getResult().exists()) {

                    String name = task.getResult().getString("name");
                    String image = task.getResult().getString("image");

                    mainImageURI = Uri.parse(image);

                    setupName.setText(name);


                    RequestOptions placeholderRequest = new RequestOptions();
                    placeholderRequest.placeholder(R.drawable.defaulticon);

                    Glide.with(SetupActivity.this).setDefaultRequestOptions(placeholderRequest).load(image).into(setupImage);


                }

            } else {

                String error = task.getException().getMessage();
                Toast.makeText(SetupActivity.this, "(FIRESTORE Retrieve Error) : " + error, Toast.LENGTH_LONG).show();

            }

            setupProgress.setVisibility(View.INVISIBLE);
            setupBtn.setEnabled(true);

        }
    });

    setupBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final String user_name = setupName.getText().toString();

            if (!TextUtils.isEmpty(user_name) && mainImageURI != null) {

                setupProgress.setVisibility(View.VISIBLE);

                if (isChanged) {

                    user_id = firebaseAuth.getCurrentUser().getUid();

                    File newImageFile = new File(mainImageURI.getPath());
                    try {

                        compressedImageFile = new Compressor(SetupActivity.this)
                                .setMaxHeight(125)
                                .setMaxWidth(125)
                                .setQuality(50)
                                .compressToBitmap(newImageFile);

                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    compressedImageFile.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                    byte[] thumbData = baos.toByteArray();

                    UploadTask image_path = mStorageRef.child("profile_images").child(user_id + ".jpg").putBytes(thumbData);

                    image_path.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {

                            if (task.isSuccessful()) {
                                storeFirestore(task, user_name);

                            } else {

                                String error = task.getException().getMessage();
                                Toast.makeText(SetupActivity.this, "(IMAGE Error) : " + error, Toast.LENGTH_LONG).show();

                                setupProgress.setVisibility(View.INVISIBLE);

                            }
                        }
                    });

                } else {

                    storeFirestore(null, user_name);

                }

            }

        }

    });

    // IMAGE

    setupImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

                if (ContextCompat.checkSelfPermission(SetupActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

                    Toast.makeText(SetupActivity.this, "Permission Denied", Toast.LENGTH_LONG).show();
                    ActivityCompat.requestPermissions(SetupActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);

                } else {

                    BringImagePicker();

                }

            } else {

                BringImagePicker();

            }

        }

    });


}

private void storeFirestore(@NonNull Task<UploadTask.TaskSnapshot> task, String user_name) {

    Uri download_uri;

    if (task != null) {

        download_uri = task.getResult().getDownloadUrl();

    } else {

        download_uri = mainImageURI;

    }

    Map<String, String> userMap = new HashMap<>();
    userMap.put("name", user_name);
    userMap.put("image", download_uri.toString());

    firebaseFirestore.collection("Users").document(user_id).set(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {

            if (task.isSuccessful()) {

                Toast.makeText(SetupActivity.this, "The user Settings are updated.", Toast.LENGTH_LONG).show();
                Intent mainIntent = new Intent(SetupActivity.this, MainActivity.class);
                startActivity(mainIntent);
                finish();

            } else {

                String error = task.getException().getMessage();
                Toast.makeText(SetupActivity.this, "(FIRESTORE Error) : " + error, Toast.LENGTH_LONG).show();

            }

            setupProgress.setVisibility(View.INVISIBLE);

        }
    });


}

private void BringImagePicker() {

    CropImage.activity()
            .setGuidelines(CropImageView.Guidelines.ON)
            .setAspectRatio(1, 1)
            .start(SetupActivity.this);

}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK) {

            mainImageURI = result.getUri();
            setupImage.setImageURI(mainImageURI);

            isChanged = true;

        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

            Exception error = result.getError();

        }
    }


}

} `

app build

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'id.zelory:compressor:2.1.0'

}

apply plugin: 'com.google.gms.google-services'

project build `dependencies { classpath 'com.android.tools.build:gradle:3.1.3'

   // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:4.0.1'
}

}`

and test Register ok -> Setup page error memo >

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: cookandroid.com.checkgroupie, PID: 11012
              java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
                  at com.google.firebase.firestore.FirebaseFirestore.zze(Unknown Source:2)
                  at com.google.firebase.firestore.FirebaseFirestore.getInstance(Unknown Source:16)
                  at cookandroid.com.checkgroupie.SetupActivity.onCreate(SetupActivity.java:97)
                  at android.app.Activity.performCreate(Activity.java:7009)
                  at android.app.Activity.performCreate(Activity.java:7000)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                  at android.os.Handler.dispatchMessage(Handler.java:106)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/cookandroid.com.checkgroupie-xcXXHhlV8GVIC3II-Lajbg==/base.apk"],nativeLibraryDirectories=[/data/app/cookandroid.com.checkgroupie-xcXXHhlV8GVIC3II-Lajbg==/lib/x86, /system/lib, /vendor/lib]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                  at com.google.firebase.firestore.FirebaseFirestore.zze(Unknown Source:2) 
                  at com.google.firebase.firestore.FirebaseFirestore.getInstance(Unknown Source:16) 
                  at cookandroid.com.checkgroupie.SetupActivity.onCreate(SetupActivity.java:97) 
                  at android.app.Activity.performCreate(Activity.java:7009) 
                  at android.app.Activity.performCreate(Activity.java:7000) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                  at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                  at android.os.Handler.dispatchMessage(Handler.java:106) 
                  at android.os.Looper.loop(Looper.java:164) 
                  at android.app.ActivityThread.main(ActivityThread.java:6494) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

Application terminated.

Upvotes: 0

Views: 89

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

Update the following:

implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-firestore:11.8.0'

into this:

implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-firestore:17.0.3'

more info here:

https://firebase.google.com/support/release-notes/android

Upvotes: 1

Related Questions