13

I am trying to get Firebase dynamic links to work in my app.

I have a function with the following

    //long
    String link = "http://www.blessd.mobi";
    DynamicLink m = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse(link))
            .setDynamicLinkDomain("blessd.page.link")
            .setAndroidParameters(
                    new DynamicLink.AndroidParameters.Builder("mobi.blessd")
                            .build())
            .buildDynamicLink();
    Uri t = m.getUri();
    String ll = t.toString();
    Log.d(TAG + " long link:", ll);

    //short
    Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse("http://www.blessd.mobi"))
            .setDynamicLinkDomain("blessd.page.link")
            .setAndroidParameters(
                    new DynamicLink.AndroidParameters.Builder("mobi.blessd")
                            .build())
            .buildShortDynamicLink()
            .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
                @Override
                public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                    if (task.isSuccessful()) {
                        // Short link created
                        Uri shortLink = task.getResult().getShortLink();
                        Uri flowchartLink = task.getResult().getPreviewLink();
                        String sl = shortLink.toString();
                        String fcl = flowchartLink.toString();
                        Log.d(TAG + " short link:", sl);
                        Log.d(TAG + " flow chat link:", fcl);
                    } else {
                        // Error
                        // ...
                        Log.d(TAG + " short links:", "problem");
                        Exception exception = task.getException();
                        Log.e("TAG", "Short Dynamic link error", exception);
                    }
                }
            });

I successfully generate a long link. I have debugged the long link in debug mode in a web browser and there are no errors.

enter image description here

The short link however does not run and I receive the following error:

09-03 16:14:06.816 4551-4551/? E/TAG: Short Dynamic link error com.google.android.gms.common.api.ApiException: 8:

Thanks.

Sagar Zala
  • 4,854
  • 9
  • 34
  • 62
the_big_blackbox
  • 1,056
  • 2
  • 15
  • 35

3 Answers3

16

Firebase team was able to reproduce the issue and has already reported this to their team.

Currently, there are two workarounds for this issue:

  • Use the Dynamic Link version 16.0.1 to be able to generate a short Dynamic Link: implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-dynamic-links:16.0.1'

  • Stick in using version 16.1.1, create a long link first then try to shorten the long Dynamic Link using this guide.

RomanU
  • 176
  • 1
  • 5
  • Hi thanks for the solution. When i use 16.0.1 I receive the following error Failed to notify dependency resolution listener. The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.0,16.0.0], [16.0.2,16.0.2]], but resolves to 16.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies. I then use 16.0.3 for both liabraries and it still gives me the above exception 8 error. – the_big_blackbox Sep 04 '18 at 12:18
  • Do you use other firebase libraries? Maybe, you have to downgrade others. At least, firebase-core and firebase-dynamic-links should both have 16.0.1 in this case. You may use command **./gradlew -q dependencies app:dependencies** to see which part of your app requires that play-services-measurement-base and downgrade it too. – RomanU Sep 04 '18 at 13:36
  • I use in my project these lines: implementation 'com.google.firebase:firebase-core:16.0.1' implementation 'com.google.firebase:firebase-config:16.0.0' implementation 'com.google.firebase:firebase-messaging:17.1.0' implementation 'com.google.firebase:firebase-dynamic-links:16.0.1' – RomanU Sep 04 '18 at 13:44
  • Sorry last thing. Where or how would I use the ./gradlew command if I wanted to know the dependencies. I am using Android studio. – the_big_blackbox Sep 04 '18 at 16:07
  • The executable file **gradlew** should be in the root of your project directory. You can run that command from a shell. – RomanU Sep 04 '18 at 16:25
  • thanks it worked was in the root. thanks again for all the help. – the_big_blackbox Sep 04 '18 at 17:45
  • 1
    Still not working. Can you pls give more information? what version of `com.google.gms:google-services:` are you using in your top-level build.gradle? are you using `com.google.android.gms:play-services-auth` dependency? and in this case which version? Thanks in advance – voghDev Oct 26 '18 at 08:33
  • `implementation 'com.google.android.gms:play-services-base:15.0.1' implementation 'com.google.android.gms:play-services-maps:15.0.1' implementation 'com.google.android.gms:play-services-location:15.0.1'` – RomanU Oct 27 '18 at 09:12
5

Use my solution to build your short link and avoid downgrading firebase.

           String builtLink = new LinkBuilder().setDomain("example.page.link")
           .setLink("your link goes here")
           .setSd(socialTagDesc)
           .setSt(socialTagTitle)
           .setSi("social image link here")
           .setApn("android app pkg")
           .setAmv("android min version")
           .setIbi("ios app pkg")
           .setImv("ios app min version")
           .setIsi("iosid number").build();

    DynamicLink.Builder builder =  FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLongLink(Uri.parse(builtLink));

    builder.buildShortDynamicLink()
            .addOnSuccessListener(listener)
            .addOnFailureListener(failureListener);





 public class LinkBuilder
 {
    private String domain;
    private String link;
    private String apn;
    private String amv;

    private String ibi;
    private String imv;
    private String isi;


    private String st;
    private String sd;
    private String si;

    public String getURLEncode(String input){

        try
        {
            return URLEncoder.encode(input, "UTF-8");
        }
        catch (Exception ex){
            Timber.e(ex);
        }

        return input;
    }


    public LinkBuilder setDomain(String domain) {
        this.domain = domain;
        return this;
    }

    public LinkBuilder setLink(String link) {
        this.link = getURLEncode(link);
        return this;
    }

    public LinkBuilder setApn(String apn) {
        this.apn = apn;
        return this;
    }

    public LinkBuilder setAmv(String amv) {
        this.amv = amv;
        return this;
    }

    public LinkBuilder setIbi(String ibi) {
        this.ibi = ibi;
        return this;
    }

    public LinkBuilder setImv(String imv) {
        this.imv = imv;
        return this;
    }

    public LinkBuilder setIsi(String isi) {
        this.isi = isi;
        return this;
    }

    public LinkBuilder setSt(String st) {
        this.st = getURLEncode(st);
        return this;
    }

    public LinkBuilder setSd(String sd) {
        this.sd = getURLEncode(sd);;
        return this;
    }

    public LinkBuilder setSi(String si) {
        this.si = getURLEncode(si);;
        return this;
    }

    public String build(){
        return String.format("https://%s/?link=%s&apn=%s&amv=%s&ibi=%s&imv=%s&isi=%s&st=%s&sd=%s&si=%s"
                ,domain, link, apn, amv, ibi, imv,isi,st,sd,si);
    }
}
Imran Baig
  • 357
  • 3
  • 4
0

Solution:

step 1 :check update version implementation 'com.google.android.gms:play-services-auth:18.1.0'

Step 2: check link, domainUriPrefix app level and firebase console dynamic link setting

Step 3: check sha1 key

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
R M Vivek
  • 44
  • 3