Android故障排除

使用bnc.lt或自定义链接域名

  • bnc.lt 链接域名
<activity android:name="com.yourapp.your_activity">
    <!-- App Link your activity to Branch links-->
    <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="https" android:host="bnc.lt" />
         <data android:scheme="http" android:host="bnc.lt" />
    </intent-filter>
</activity>
  • 自定义链接域名
<activity android:name="com.yourapp.your_activity">
    <!-- App Link your activity to Branch links-->
    <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="https" android:host="your.app.com" />
         <data android:scheme="http" android:host="your.app.com" />
    </intent-filter>
</activity>

深度链接路由

  • 加载特定的 URI Scheme 路径,例如

    • $deeplink_path="content/123"
    • $android_deeplink_path="content/123"
  • 建议使用导航到内容

<meta-data android:name="io.branch.sdk.auto_link_path" android:value="content/123/, another/path/, another/path/*" />

应用中的深度链接路由

  • 在应用程序中用于WebViewChromeTab 以正常呈现HTML

  • WebView 内的Branch链接将在您的应用程序内部进行路由,而其他内容将继续在您的应用程序内部进行路由

  • 启动Branch深度链接接 Web View

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new BranchWebViewController(YOUR_DOMAIN, MainActivity.class)); //YOUR_DOMAIN example: appname.app.link
    webView.loadUrl(URL_TO_LOAD);
}

public class BranchWebViewController extends WebViewClient {

    private String myDomain_;
    private Class activityToLaunch_;

    BranchWebViewController(@NonNull String myDomain, Class activityToLaunch) {
        myDomain_ = myDomain;
        activityToLaunch_ = activityToLaunch;
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        String url = request.getUrl().toString();

        if (url.contains(myDomain_)) {
            Intent i = new Intent(view.getContext(), activityToLaunch_);
            i.putExtra("branch", url);
            i.putExtra("branch_force_new_session", true);
            startActivity(i);
            //finish(); if launching same activity
        } else {
            view.loadUrl(url);
        }

        return true;
    
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val webView = findViewById(R.id.webView) as WebView
    webView!!.webViewClient = BranchWebViewController("appname.app.link", MainActivity2::class.java)
    webView!!.loadUrl(URL_TO_LOAD)
}

inner class BranchWebViewController internal constructor(private val myDomain_: String, private val activityToLaunch_: Class<*>) : WebViewClient() {

    override fun onLoadResource(view: WebView, url: String) {
        super.onLoadResource(view, url)
    }

    override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
        val url = request.url.toString()

        if (url.contains(myDomain_)) {
            val i = Intent(view.context, activityToLaunch_)
            i.putExtra("branch", url)
            i.putExtra("branch_force_new_session", true)
      //finish(); if launching same activity
            startActivity(i)
        } else {
            view.loadUrl(url)
        }

        return true
    }
}
  • 启动Branch深度链接接 Chrome Tabs
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra("branch", BRANCH_LINK_TO_LOAD);
customTabsIntent.intent.putExtra("branch_force_new_session", true);
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(BRANCH_LINK_TO_LOAD));
//finish(); if launching same activity
val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
customTabsIntent.intent.putExtra("branch", BRANCH_LINK_TO_LOAD)
customTabsIntent.intent.putExtra("branch_force_new_session", true)
customTabsIntent.launchUrl(this@MainActivity2, Uri.parse(BRANCH_LINK_TO_LOAD))
//finish() if launching same activity

深度链接活动完成

  • 在深度链接接活动结束时收到通知
<meta-data android:name="io.branch.sdk.auto_link_request_code" android:value="@integer/AutoDeeplinkRequestCode" />
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Checking if the previous activity is launched on branch Auto deep link.
    if(requestCode == getResources().getInteger(R.integer.AutoDeeplinkRequestCode)){
        //Decide here where  to navigate  when an auto deep linked activity finishes.
        //For e.g. Go to HomeActivity or a  SignUp Activity.
        Intent i = new Intent(getApplicationContext(), CreditHistoryActivity.class);
        startActivity(i);
    }
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    // Checking if the previous activity is launched on branch Auto deep link.
    if (requestCode == resources.getInteger(R.integer.AutoDeeplinkRequestCode)) {
        //Decide here where  to navigate  when an auto deep linked activity finishes.
        //For e.g. Go to HomeActivity or a  SignUp Activity.
        val i = Intent(applicationContext, CreditHistoryActivity::class.java)
        startActivity(i)
    }
}

测试Branch链接的Deeplink路由

?bnc_validate=true 附加到您的任何应用程序'的Branch链接上,然后在移动设备(而不是Simulator!)上单击它以开始测试。

例如,要验证以下链接: "https://<yourapp\>.app.link/NdJ6nFzRbK" 单击: "https://<yourapp\>.app.link/NdJ6nFzRbK?bnc_validate=true"

Android 15 之前版本的支持

  • 采用 Branch SDK 1.14.5

  • 加到onStart()onStop()

@Override
protected void onStart() {
    super.onStart();
    Branch.getInstance(getApplicationContext()).initSession();
}

@Override
protected void onStop() {
    super.onStop();
    branch.closeSession();
}
override fun onStart() {
    super.onStart()
    Branch.getInstance().initSession()
}

override fun onStop() {
    super.onStop()
    Branch.getInstance().closeSession()
}

使用默认的 application class

  • 如果您的应用程序没有 application class
<application android:name="io.branch.referral.BranchApp">

生成签名证书

  • 用于Android App Link 深度链接接

  • 找到您的密钥库文件

  • 运行 keytool -list -v -keystore my-release-key.keystore

  • 将产生一个像这样的值: AA:C9:D9:A5:E9:76:3E:51:1B:FB:35:00:06:9B:56:AC:FB:A6:28:CE:F3:D6:65:38:18:E3:9C:63:94:FB:D2:C1

  • 将此值复制到您的Branch仪表板

通过 Install Listener 进行匹配

  • 启用将link_click_id 从Google Play传递到Branch的功能

  • 这将增加归因以及延迟深度链接的准确性

  • Branch默认为1.5 秒以等待Google Play分析

  • 可以优化根据需要的性能(例如0500010000

  • getAutoInstance 之前添加到您的应用程序类( 加载分支

Branch.setPlayStoreReferrerCheckTimeout(5000);
Branch.setPlayStoreReferrerCheckTimeout(5_000)
  • 测试
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n io.branch.androidexampledemo/io.branch.referral.InstallListener --es "referrer" "link_click_id=123"

启用 Multidexing

  • 添加依赖项可能会超出dex限制并导致NoClassDefFoundErrorClassNotFoundException

  • 添加如下设置到您的 build.gradle

defaultConfig {
    multiDexEnabled true
}
  • 添加到您的Application class ,并确保它扩展MultiDexApplication
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
override fun attachBaseContext(base: Context?) {
    super.attachBaseContext(base)
    MultiDex.install(this)
}

InvalidClassException,ClassLoadingError或VerificationError

  • 通常是由Proguard 错误引起的。尝试设置最新版本的Proguard或通过设置-dontoptimize禁用Proguard优化

Answers-shim 模块的 Proguard 警告或错误

  • 通常在排除answers-shim时引起。尝试将-dontwarn com.crashlytics.android.answers.shim.** 添加到Proguard 文件

带有 AppIndexing 模块保护警告或错误

  • Branch SDK对Firebase应用程序索引具有可选的依赖关系,以提供新的Firebase内容列表功能。根据您的proguard设置,这可能会导致proguard警告。请将以下内容添加到您的proguard文件中以解决此问题: -dontwarn com.google.firebase.appindexing.

没有Play服务广告模块的Proguard规则

  • Branch SDK对GAID匹配具有对Play服务广告的可选依赖项。不使用此库而使用Proguard可能会在创建Branch会话和事件时获取GAID时产生问题。

请将以下内容添加到您的proguard文件中以解决此问题:

-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient { com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context); }
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info { java.lang.String getId(); boolean isLimitAdTrackingEnabled(); }

无法打开此链接错误

  • URI方案重定向失败时发生。
  • 确保您没有$deeplink_path$deeplink_path ,而您的AndroidManifest.xml 可以接受

卡在`initState_ == SESSION_STATE.INITIALISING`中

  • 通常是由于Branch没有从您的活动中获得正确的应用程序上下文而引起的。要解决此问题,请在访问Branch实例时传递单例类:
Branch.getInstance(getApplicationContext());

最低版本

如果' d喜欢支持下至API版本9 Android上,请针到1.14.5版本。如果' d喜欢支持API级别15,请针到2.X版本。我们支持3.x的最低版本是Android版本16。

2个月前更新

Android故障排除


建议的编辑仅限于API参考页

您只能建议对Markdown正文内容进行修改,而不能建议对API规范进行修改。