Branch.io SDK无法在Unity3D中的Android构建上初始化

时间:2019-04-30 02:41:32

标签: android unity3d android-manifest branch.io

Unity3d的Branch.io sdk尚未在Android构建中初始化。我正在使用的是进行深层链接,但是正如我在调试日志中看到的那样,它甚至在应用启动时都没有初始化(通常在iOS版本中,我看到了一些日志记录,但Android为空)。我正在使用最新的Branch.io sdk和Unity3d 2018.3.9f1

我意识到资产标准的“ Update AndroidManifest”按钮在预制件“ BranchPrefab”上不起作用。那什么也没做。我尝试使用docs(似乎不实际)/ samples项目/论坛来手动设置清单的不同组合,但没有结果。 我已经联系了branch.io支持人员,但它们根本没有用。他们向我提供了“固定”清单,但实际上不起作用。在这里:

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

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
            android:name=".SampleBranchApplication"
            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">

        <!-- Branch init -->
        <meta-data
                android:name="io.branch.sdk.BranchKey"
                android:value="key_live_my_key_here"/>
        <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:launchMode="singleTask">

            <!-- AppLink example -->
            <!-- Branch App Links (optional) -->
            <intent-filter android:autoVerify="true"
                           tools:targetApi="m">
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data
                        android:host="tdetectives.app.link"
                        android:scheme="https"/>
                <data
                        android:host="tdetectives-alternate.app.link"
                        android:scheme="https"/>
            </intent-filter>

            <!-- Branch URI Scheme -->
            <intent-filter>
                <data
                        android:host="open"
                        android:scheme="tdetectives"/>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>

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

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <!-- Branch install referrer tracking (optional) -->
        <receiver
                android:name="io.branch.referral.InstallListener"
                android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>

结果是,深层链接无法正常工作,动态链接的创建和共享也无法正常工作,sdk尚未初始化...

已更新 花了许多小时之后,我发现sdk分支没有合并它的清单到主清单,这就是为什么资源没有加载的原因。似乎仅当根本没有主清单时,此方法才有效。 在完成一个技巧后,自动清单更新完成了:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.myapp.app" android:versionCode="1" android:versionName="1.0">
  <application android:label="@string/app_name" android:icon="@drawable/app_icon" android:name="io.branch.unity.BranchUnityApp">
    <!-- The MessagingUnityPlayerActivity is a class that extends
         UnityPlayerActivity to work around a known issue when receiving
         notification data payloads in the background. -->
    <activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTask">
      <intent-filter>
        <data android:host="open" android:scheme="myAppUrlScheme" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
      </intent-filter>
      <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="myapp.app.link" />
        <data android:scheme="https" android:host="myapp-alternate.app.link" />
      </intent-filter>
    </activity>
    <service android:name="com.google.firebase.messaging.MessageForwardingService" android:exported="false" />
    <meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
    <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_my_key" />
  </application>
  <uses-permission android:name="android.permission.INTERNET" />
</manifest>```

For now branch sdk initialise well, deeplink sharing works, but not the opening the app by deeplink click. So, if the app is running in background and I click the deeplink app just restarts without providing the parameters. If app is closed, that just do nothing (app attempts to start, but stacks)

Seems there is some conflict with activities from Firebase Messaging. I am not good with that, may be I am wrong.

Any suggestions?

1 个答案:

答案 0 :(得分:0)

缺少行

  <meta-data
            android:name="io.branch.sdk.TestMode"
            android:value="false" /> <!-- Set to true to use Branch_Test_Key -->

还要对此进行测试,您需要在Play商店上载应用程序,或者可以使用adb命令

adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <PackageName>/io.branch.referral.InstallListener --es "referrer " "utm_source%3DFacebook"

关于第一次活动

@Override
    protected void onStart() {
        super.onStart();
        try {
            // Branch init
            Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
                @Override
                public void onInitFinished(JSONObject referringParams, BranchError error) {
                    if (error == null) {
                        Log.i("BRANCH SDK", referringParams.toString());
                    } else {
                        Log.i("BRANCH SDK", error.getMessage());
                    }
                }
            }, this.getIntent().getData(), this);
        } catch (
                Exception e) {
            e.printStackTrace();
        }


    }