0

I'm using https://github.com/AppsFlyerSDK/react-native-appsflyer in our react-native app.

  • I managed to set up the iOS part of it and ran the integration tests successfully
  • but I'm struggling with the Android integration.

1st problem:

  • When I build the app on my device I get this error:

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

inside the appsFlyer.initSdk

2nd problem:

  • When I run the Android SDK Integration test:

I get this result (see screenshot)

enter image description here

Here's my code :

```

...
...

// 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 });
 }
}

```

AziCode
  • 2,510
  • 6
  • 27
  • 53

1 Answers1

1

I found the solution:

  • Initially, I was following the documentation by adding new RNAppsFlyerPackage(MainApplication.this) inside the getPackages() method in MainApplication.java but I kept having an error saying I couldn't use arguments with RNAppsFlyerPackage()

  • I had to remove the arguments so that I can build the project, but that didn't make the Android integration tests

1 - The solution was to clean the project

2 - delete the node_modules using :

rm -rf /node_modules

3- after doing that, I was prompted to use arguments inside the method

new RNAppsFlyerPackage(MainApplication.this)

and now the Android integration tests are passing

AziCode
  • 2,510
  • 6
  • 27
  • 53