question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Background-Fetch: Cannot read property 'configure' of Undefined

See original GitHub issue

I have been trying to integrate the transistorsoft background-fetch library without success.

When I chain any method to the BackgroundFetch component I get the error:

image

import BackgroundFetch from "react-native-background-fetch";

  class TimerScreen extends React.Component {

...

componentDidMount() {

    this.configureBackgroundFetch();

}
...
configureBackgroundFetch() {
    // Configure BackgroundFetch.
    BackgroundFetch.configure({
      minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
      stopOnTerminate: false, // <-- Android-only,
      startOnBoot: true, // <-- Android-only
      enableHeadless: true
    }, async () => {
      console.log('BackgroundFetch has started');
      BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
    }, (error) => {
      console.log('RNBackgroundFetch failed to start')
    });
}
...

I haven’t been able to find out why the library isn’t working. I have used react native link and installed it in package.json

 ...
 {
       ...
       "react-native-background-fetch": "^2.5.3",
       ...
 }
 ...

Your Environment

  • Plugin version: 2.5.3
  • Platform: iOS or Android
  • OS version: Linux
  • Device manufacturer / model: Lenovo PC
  • React Native version (react-native -v): react-native-cli: 2.0.1 react-native: 0.57.1
  • Plugin config: Just added these two commands - $ npm install --save react-native-background-fetch $ react-native link react-native-background-fetch

Expected Behavior

The BackgroundFetch should be confiugred and run in the background every 15 minutes.

Actual Behavior

Error whenever any method from the plugin is chained to the BackgroundFetch

Steps to Reproduce

  1. Install react-native-background-fetch and use link it
  2. Import library
  3. Write function for configuring BackgroundFetch
  4. Execute the function in componentDidMount lifecycle method.

Context

I am trying to run a background task that will ping an API in the background while the app is in the background or the phone is locked.

Debug logs

04-25 12:52:30.467  4759  4759 E EventBus: Could not dispatch event: class com.transistorsoft.locationmanager.event.HeadlessEvent to subscribing class class com.transistorsoft.rnbackgroundgeolocation.HeadlessTask
04-25 12:52:30.467  4759  4759 E EventBus: java.lang.ClassCastException: com.transistorsoft.locationmanager.service.HeartbeatService cannot be cast to com.facebook.react.ReactApplication
04-25 12:52:30.467  4759  4759 E EventBus:      at com.transistorsoft.rnbackgroundgeolocation.HeadlessTask.startTask(HeadlessTask.java:109)
04-25 12:52:30.467  4759  4759 E EventBus:      at com.transistorsoft.rnbackgroundgeolocation.HeadlessTask.onHeadlessEvent(HeadlessTask.java:95)
04-25 12:52:30.467  4759  4759 E EventBus:      at java.lang.reflect.Method.invoke(Native Method)
04-25 12:52:30.467  4759  4759 E EventBus:      at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:485)
04-25 12:52:30.467  4759  4759 E EventBus:      at org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:420)
04-25 12:52:30.467  4759  4759 E EventBus:      at org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:397)
04-25 12:52:30.467  4759  4759 E EventBus:      at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:370)
04-25 12:52:30.467  4759  4759 E EventBus:      at org.greenrobot.eventbus.EventBus.post(EventBus.java:251)
04-25 12:52:30.467  4759  4759 E EventBus:      at com.transistorsoft.locationmanager.util.a.a(Unknown Source)
04-25 12:52:30.467  4759  4759 E EventBus:      at com.transistorsoft.locationmanager.service.HeartbeatService.onStartCommand(Unknown Source)
04-25 12:52:30.467  4759  4759 E EventBus:      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3326)
04-25 12:52:30.467  4759  4759 E EventBus:      at android.app.ActivityThread.-wrap21(ActivityThread.java)
04-25 12:52:30.467  4759  4759 E EventBus:      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1582)
04-25 12:52:30.467  4759  4759 E EventBus:      at android.os.Handler.dispatchMessage(Handler.java:102)
04-25 12:52:30.467  4759  4759 E EventBus:      at android.os.Looper.loop(Looper.java:154)
04-25 12:52:30.467  4759  4759 E EventBus:      at android.app.ActivityThread.main(ActivityThread.java:6119)
04-25 12:52:30.467  4759  4759 E EventBus:      at java.lang.reflect.Method.invoke(Native Method)
04-25 12:52:30.467  4759  4759 E EventBus:      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
04-25 12:52:30.467  4759  4759 E EventBus:      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
04-25 12:52:30.467  4759  4759 D EventBus: No subscribers registered for event class org.greenrobot.eventbus.SubscriberExceptionEvent
04-25 12:52:30.467  1390  1415 W audio_hw_generic: Not supplying enough data to HAL, expected position 42494451 , only wrote 42494400
04-25 12:52:31.406  1398 14683 D NuPlayerDriver: notifyListener_l(0xaaf93180), (2, 0, 0), loop setting(0, 0)
04-25 12:52:31.406  1398  1408 D NuPlayerDriver: reset(0xaaf93180) at state 6
04-25 12:52:31.406  1398  1408 D NuPlayerDriver: notifyListener_l(0xaaf93180), (8, 0, 0), loop setting(0, 0)
04-25 12:52:31.408  1398 14683 W AMessage: failed to post message as target looper for handler 0 is gone.
04-25 12:52:31.409  1398 14683 D NuPlayerDriver: notifyResetComplete(0xaaf93180)
04-25 12:52:34.368  1390  1416 W audio_hw_generic: Not supplying enough data to HAL, expected position 42866716 , only wrote 42681600
04-25 12:52:34.442  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:52:39.459  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:52:44.475  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:52:49.493  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:52:54.509  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:52:59.530  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:53:04.543  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:53:09.568  4619 14567 D j       : WARNING: getPackageName called on ScopedContext
04-25 12:53:14.575  4619 14567 D j       : WARNING: getPackageName called on ScopedContext

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
christocracycommented, Apr 25, 2019

Ahhh…ejected Expo. Good luck with that. I hate Expo.

0reactions
codeNameKCcommented, May 1, 2019

It was indeed the Expokit that was the culprit behind the problem. The Expokit setup wasn’t configured properly to run native code. I made a hello world app with Expokit and another one with a regular react native setup. The Expokit project failed to link without an error and the regular setup worked as it should.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Background-Fetch: Cannot read property 'configure' of ...
The problem was caused by Expokit not being configured correctly to use native modules. I made a bare React Native app and the...
Read more >
react-native-background-fetch | Yarn - Package Manager
Background Fetch is a very simple plugin which attempts to awaken an app in the background about every 15 minutes, providing a short...
Read more >
Cannot Read Property 'Configure' Of Undefined In React-Native
im trying to authenticate a bank account using IAV and im getting the following error: Uncaught TypeError: Cannot read property 'configure' of undefined....
Read more >
BackgroundFetch - Expo Documentation
This method doesn't take any effect on Android. It is a global value which means that it can overwrite settings from another application...
Read more >
error cannot read property 'configurations' of undefined. react ...
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found