React原生android初始化Branch.io SDK时出现问题



我在初始化react原生分支5.0.0 SDK时遇到问题。在主应用程序组件的useEffect:中调用Branch.subscribe((后

useEffect(() => {
Branch.subscribe(({ error, response }) => {
console.log(error, "error");
console.log(response, "response");
});
}, []);

以下错误得到控制台记录的

Trouble initializing Branch. Branch API Error: Please enter your branch_key in your project's manifest file first

我已经按照文档中的步骤安装和配置了SDK,我不知道自己做错了什么。

这是我的AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.****.*********">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
...
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="myappuri" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App 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="myactualappname.app.link" />
</intent-filter>

<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_*********"/>
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_*******"/>
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
...
</activity>
</manifest>

在主活动中,我有:

import io.branch.rnbranch.*;
import android.content.Intent;
...
public class MainActivity extends ReactActivity {
// Override onStart, onNewIntent:
@Override
protected void onStart() {
super.onStart();
RNBranchModule.initSession(getIntent().getData(), this);
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null &&
intent.hasExtra("branch_force_new_session") && 
intent.getBooleanExtra("branch_force_new_session",false)) {
RNBranchModule.onNewIntent(intent);
}
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "main";
}
}

以及主要应用

...
import io.branch.rnbranch.RNBranchModule;
public class MainApplication extends Application implements ReactApplication {
...
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ApplicationLifecycleDispatcher.onApplicationCreate(this);
RNBranchModule.getAutoInstance(this);
}
...
}

我尝试重置仪表板中的branch_key,但结果是一样的。

首先"应用程序";您的清单中缺少标签。第二,分支键应该在"之外;活动";标签请按照下面url中给出的说明操作,您的应用程序将正常工作。

https://help.branch.io/developers-hub/docs/android-basic-integration

下面是你的清单应该是什么样子的:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.****.*********">
<application
android:allowBackup="true"
android:name="com.eneff.branch.example.android.CustomApplicationClass"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Launcher Activity to handle incoming Branch intents -->
<activity
android:name=".LauncherActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="yourapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App 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="example.app.link" />
<!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website.  -->
<data android:scheme="https" android:host="example-alternate.app.link" />
</intent-filter>
</activity>
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_*********"/>
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_*******"/>
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
</application>

最新更新