Coder Social home page Coder Social logo

Comments (7)

tafelnl avatar tafelnl commented on May 27, 2024

I ended up with the following configuration (androidx targeted):

android\app\build.gradle:

apply plugin: 'com.android.application'

android {
    defaultConfig {
        // ...
+       multiDexEnabled true
        // ...
+       resValue "string", "applink_host", "example.app.link"
+       resValue "string", "applink_host_alternate", "example-alternate.app.link"
+       resValue "string", "deeplink_scheme", "example"
+       resValue "string", "branch_api_key", "key_live_example"
+       resValue "string", "branch_test_mode", "false"
        // ...
    }
}

dependencies {
+    implementation 'com.android.support:multidex:1.0.3'

+    // Branch: required for all Android apps
+    implementation 'io.branch.sdk.android:library:5.0.3'

+    // Branch: required if your app is in the Google Play Store (tip: avoid using bundled play services libs)
+    implementation 'com.google.firebase:firebase-appindexing:19.1.0' // App indexing
+    implementation 'com.google.android.gms:play-services-ads:19.4.0' // GAID matching

+    // Branch: optional
+    implementation 'androidx.browser:browser:1.2.0' // Chrome Tab matching (enables 100% guaranteed matching based on cookies)
}

android\app\src\main\AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <application
+       android:name=".CustomApplicationClass"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!-- ... -->

+       <meta-data
+           android:name="com.google.android.gms.ads.AD_MANAGER_APP"
+           android:value="true"/>

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="com.example.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask">

+           <intent-filter>
+               <action android:name="android.intent.action.MAIN" />
+               <category android:name="android.intent.category.LAUNCHER" />
+           </intent-filter>

+           <!-- BEGIN BRANCH -->
+           <intent-filter android:autoVerify="true">
+               <action android:name="android.intent.action.VIEW" />
+               <category android:name="android.intent.category.DEFAULT" />
+               <category android:name="android.intent.category.BROWSABLE" />
+               <data
+                   android:scheme="http"
+                   android:host="@string/applink_host" />
+               <data
+                   android:scheme="https"
+                   android:host="@string/applink_host" />
+               <data
+                   android:scheme="http"
+                   android:host="@string/applink_host_alternate" />
+               <data
+                   android:scheme="https"
+                   android:host="@string/applink_host_alternate" />
+           </intent-filter>
+
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
-               <data android:scheme="@string/custom_url_scheme"/>
+               <data android:scheme="@string/deeplink_scheme"/>
            </intent-filter>
+           <!-- END BRANCH -->

        </activity>

+       <!-- BEGIN BRANCH -->
+       <!-- Branch init -->
+       <meta-data android:name="io.branch.sdk.BranchKey" android:value="@string/branch_api_key" />
+       <meta-data android:name="io.branch.sdk.TestMode" android:value="@string/branch_test_mode" />
+       <!-- END BRANCH -->
+
        <!-- ... -->

    </application>

    <!-- ... -->

</manifest>

android\app\src\main\java\com\example\CustomApplicationClass.java:

+package com.example;
+
+import android.content.Context;
+import androidx.multidex.MultiDex;
+import androidx.multidex.MultiDexApplication;
+import io.branch.referral.Branch;
+
+public class CustomApplicationClass extends MultiDexApplication {
+
+  @Override
+  public void onCreate() {
+    super.onCreate();
+
+    // Branch logging for debugging
+    Branch.enableLogging();
+
+    // Branch object initialization
+    Branch.getAutoInstance(this);
+  }
+
+  @Override
+  protected void attachBaseContext(Context base) {
+    super.attachBaseContext(base);
+    MultiDex.install(this);
+  }
+}

android\app\src\main\java\com\example\MainActivity.java:

package com.example;

import android.content.Intent;
import android.os.Bundle;
import co.boundstate.BranchDeepLinks;

import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import java.util.ArrayList;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {

          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
+           add(BranchDeepLinks.class);
          }
        }
      );
  }
+
+  @Override
+  protected void onNewIntent(Intent intent) {
+    this.setIntent(intent);
+    super.onNewIntent(intent);
+  }
}

Optionally you can probably safely delete the following:

android\app\src\main\res\values\strings.xml

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <!-- ... _>
-   <string name="custom_url_scheme">com.example</string>
</resources>

Some clarifications

To me this configuration looks more up to date than the one in the readme. It might be that I have done some redundant configuration. But it works 100% now. So better safe than sorry.

androidx + multidex

I have made the choice to target AndroidX and support multidex. You can read more about multidex here: https://stackoverflow.com/questions/33588459/what-is-android-multidex It depends on your use case, but if you have a lot of dependencies installed like GM Services, Branch and Facebook for example, it seems like the right choice.

default custom_url_scheme by capacitor

Also, Capacitor has deeplink url schemes configured by default within Android (hence the custom_url_scheme variable (which defaults to your package name) in strings.xml. I think it does not make sense to keep this in your project when you use Branch, but that is up to you to decide. In the config above it is dropped however by simply removing the lines:

- <data android:scheme="@string/custom_url_scheme"/>
- <string name="custom_url_scheme">com.example</string>

Basically the only thing this does is removing the scheme com.example:// (ergo: your package name) from the supported schemes. Not very important, just some cleaning up.

from capacitor-branch-deep-links.

rahulMypcot avatar rahulMypcot commented on May 27, 2024

getting this error " error: failed processing manifest."

from capacitor-branch-deep-links.

raosaddam avatar raosaddam commented on May 27, 2024

I'm getting error in MainActivity.java

2021-05-26

package co.boundstate does not exist
cannot find symbol class BranchDeepLinks

from capacitor-branch-deep-links.

tafelnl avatar tafelnl commented on May 27, 2024

@raosaddam You can try the following:

In Android Studio click File > Sync Project with Gradle Files and try to build again.

from capacitor-branch-deep-links.

raosaddam avatar raosaddam commented on May 27, 2024

@tafelnl Thank you for replying.
That didn't work either. Still same error

from capacitor-branch-deep-links.

tafelnl avatar tafelnl commented on May 27, 2024

Ah I see, the docs are missing the following steps:

  • run npm i capacitor-branch-deep-links
  • run npx cap sync
  • In Android Studio click File > Sync Project with Gradle Files and try to build again

from capacitor-branch-deep-links.

raosaddam avatar raosaddam commented on May 27, 2024

That worked. Thank you so much

from capacitor-branch-deep-links.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.