Skip to content

Firebase Dynamic Link crashes. setResultOrApiException(Unknown Source:12) #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
richardliveraise opened this issue Oct 10, 2018 · 6 comments

Comments

@richardliveraise
Copy link

richardliveraise commented Oct 10, 2018

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 3.1.2
  • Firebase Component: Firebase Dynamic Links
  • Component version: 16.0.1

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I've been getting this error log after I added Firebase Dynamic Link Invite. I still couldn't reproduce it though.

Fatal Exception: com.google.android.gms.f.f: com.google.android.gms.common.api.b: 8: 
       at com.google.android.gms.tasks.zzu.getResult(Unknown Source:17)
       at com.ordinaryman.android.referral.ReferralManager.init(Unknown Source:18)
       at com.ordinaryman.android.referral.ReferralManager$$Lambda$2.onComplete(Unknown Source:11)
       at com.google.android.gms.tasks.zzj.run(Unknown Source:23)
       at android.os.Handler.handleCallback(Handler.java:789)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6938)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Caused by com.google.android.gms.common.api.b: 8: 
       at com.google.android.gms.common.api.internal.TaskUtil.setResultOrApiException(Unknown Source:12)
       at com.google.android.gms.internal.measurement.zzyn.zza(Unknown Source:2)
       at com.google.android.gms.internal.measurement.zzys.dispatchTransaction(Unknown Source:21)
       at com.google.android.gms.internal.measurement.zzo.onTransact(Unknown Source:22)
       at android.os.Binder.execTransact(Binder.java:682)

Relevant Code:

try {

            generateShortenedDeepLink(context, code, refId, src, imageUrl).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (onDoneLoading != null) {
                        onDoneLoading.run();
                    }

                    log.error("Error generating deeplink", e);

                    if (context instanceof BaseActivity) {
                        ((BaseActivity) context).showToastWarn("Error generating code. ");
                    }

                    return;
                }
            }).addOnCompleteListener(task -> {

                BaseActivity act;
                act = (BaseActivity) context;

                String defaultMessage = "Hi, come join me on this app ";
                String linkUrl = task.getResult().getShortLink().toString();
                String textMessage = defaultMessage + " " + linkUrl;

                if (StringUtils.isEmpty(imageUrl)) {
                    shareHandler(act, textMessage, null);
                    if (onDoneLoading != null) {
                        onDoneLoading.run();
                    }
                    return;
                }

                String filename = imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
                File cachePath = new File(context.getCacheDir(), "images");
                cachePath.mkdirs(); // don't forget to make the directory
                File imageFile = new File(cachePath, filename);

                Runnable continuation = () -> {
                    Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName(), imageFile);
                    shareHandler(act, textMessage, contentUri);
                    if (onDoneLoading != null) {
                        app.getMainHandler().postDelayed(onDoneLoading, 3000);
                    }
                };

                if (imageFile.exists()) {
                    continuation.run();
                    return;
                }

                if (act.isNoMoUIChanges()) return;

                Glide.with(context)
                        .asBitmap()
                        .load(imageUrl)
                        .into(new SimpleTarget<Bitmap>() {

                            @Override
                            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {

                                try (FileOutputStream stream = new FileOutputStream(imageFile)) {
                                    resource.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                                } catch (IOException e) {
                                    log.error("Error generating share", e);
                                    if (onDoneLoading != null) {
                                        onDoneLoading.run();
                                    }
                                    return;
                                }
                                continuation.run();
                            }
                        });
            });

        } catch (Exception e) {
            if (context instanceof BaseActivity) {
                ((BaseActivity) context).showToastWarn("Error generating code. Please try again later");
            }
        }

private void shareHandler(BaseActivity context, String smsMsg, Uri contentUri) {

        if(context.isNoMoUIChanges()) return;

        Resources resources = context.getResources();

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
        sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
        sendIntent.putExtra(Intent.EXTRA_TEXT, smsMsg);
        sendIntent.setType(context.getContentResolver().getType(contentUri));

        Intent openInChooser = Intent.createChooser(sendIntent, resources.getString(R.string.share_intent_chooser_title));
        context.startActivity(openInChooser);
    }
@ashwinraghav
Copy link
Contributor

@richardliveraise Thanks for reaching out! We do anticipate that this would be fixed in the upcoming release schedule a couple of weeks down the line.
Thanks for working with us on this.

@richardliveraise
Copy link
Author

@ashwinraghav can you clarify what root cause of this issue? any workaround I can do in the meantime? Thanks!

@richardliveraise
Copy link
Author

richardliveraise commented Oct 23, 2018

@ashwinraghav I figured the issue was generating the short link. The workaround I did was generate a long link, then get the short link.

 //Generate long link
 Uri dynamicLinkUri = dynamicLink.getUri();
 return FirebaseDynamicLinks.getInstance().createDynamicLink()
        .setLongLink(dynamicLinkUri)
        .buildShortDynamicLink(); 

Reference:
https://stackoverflow.com/questions/52152116/short-dynamic-link-error-com-google-android-gms-common-api-apiexception-8/52157428#52157428

Note that prior doing the workaround, I updated the SDK to the latest one, then it'd work for newer OS (7.0, 8.0) but it wouldn't work for older OS (5.0, 6.0). If you could explain what the cause of this, I'd really appreciate it. Thanks!

@aguatno
Copy link

aguatno commented Dec 12, 2019

Hi @richardliveraise sorry for my late response here. It looks like the error log didn't persist in the latest version. I was wondering if you're still having this issue? If so, could you provide the following so that I can investigate the issue further:

  • Minimal repro of your code that I can run locally
  • Firebase SDK version you're using
  • Any other relevant information

@google-oss-bot
Copy link
Contributor

Hey @richardliveraise. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@richardliveraise if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants