0

我在我们的 react-native 应用程序中使用https://github.com/AppsFlyerSDK/react-native-appsflyer 。

  • 我设法设置了它的 iOS 部分并成功运行了集成测试
  • 但我正在为 Android 集成而苦苦挣扎。

第一个问题:

  • 当我在我的设备上构建应用程序时,我收到此错误:

'Attempt to invoke virtual method \'android.content.Context android.app.Application.getApplicationContext()\' on a null object reference'

在 - 的里面appsFlyer.initSdk

第二个问题:

  • 当我运行 Android SDK 集成测试时:

我得到了这个结果(见截图)

在此处输入图像描述

这是我的代码:

```

...
...

// appsFlyer options
const options = {
  devKey: 'Bl9i45ho07lp43',
  isDebug: true,
};

if (Platform.OS === 'ios') {
  options.appId = '1165972436';
}

this.onInstallConversionDataCanceller = appsFlyer.onInstallConversionData(
 (data) => {
   console.log(data);
 }
);

appsFlyer.initSdk(options,
  (result) => {
    console.log(result);
 },
  (error) => {
    console.error('error inside appsFlyer.initSdk ==>', error);
 }
);

.....
.....

class App extends React.PureComponent {


  state = {
    appState: AppState.currentState,
  }

  componentDidMount() {
    AppState.addEventListener('change', this._handleAppStateChange);
  }

  componentWillUnmount() {
    if (this.onInstallConversionDataCanceller) {
      this.onInstallConversionDataCanceller();
    }
    AppState.removeEventListener('change', this._handleAppStateChange);
  }

  _handleAppStateChange = (nextAppState) => {
    if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
      if (Platform.OS === 'ios') {
        appsFlyer.trackAppLaunch();
      }
   }

  if (this.state.appState.match(/active|foreground/) && nextAppState === 'background') {
    if (this.onInstallConversionDataCanceller) {
      this.onInstallConversionDataCanceller();
    }
  }

  this.setState({ appState: nextAppState });
 }
}

```

4

1 回答 1

1

我找到了解决方案:

  • 最初,我通过 new RNAppsFlyerPackage(MainApplication.this)getPackages()方法中添加来遵循文档,MainApplication.java但我一直有一个错误,说我不能使用参数RNAppsFlyerPackage()

  • 我必须删除参数才能构建项目,但这并没有进行 Android 集成测试

1 - 解决方案是清理项目

2 - 删除 node_modules 使用:

rm -rf /node_modules

3- 之后,我被提示在方法中使用参数

new RNAppsFlyerPackage(MainApplication.this)

现在Android集成测试正在通过

于 2018-02-16T00:38:33.097 回答