Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Fetch Headless Class Not Found Exception #12

Open
ssulei7 opened this issue Sep 20, 2018 · 8 comments
Open

Background Fetch Headless Class Not Found Exception #12

ssulei7 opened this issue Sep 20, 2018 · 8 comments

Comments

@ssulei7
Copy link

ssulei7 commented Sep 20, 2018

When I try to enable headless mode on Android 8.1 / Nexus 6P, I get an error java.lang.ClassNotFoundException. We are running the latest version of NativeScript and the latest available version of your plugin. Not sure if relevant, but we're also using your background geolocation plugin.

BackgroundFetch.registerHeadlessTask(async () => {
	console.log('[My BackgroundFetch HeadlessTask] onFetch');    
	// Do some asynchronous work (eg: HTTP Request)
	
	// Politely signal to the OS that our processing is complete.
	BackgroundFetch.finish();
});

// Configure Background Fetch
BackgroundFetch.configure({
	stopOnTerminate: false,
	startOnBoot: true,
	enableHeadless: true
}, () => {
	console.log("[js] BackgroundFetch event received");
	// do stuff
	console.log("[js] BackgroundFetch event completed");
}, (status) => {
	console.log('BackgroundFetch not supported by your OS', status);
});

This is the log of the error:

System.err: java.lang.ClassNotFoundException: com.transistorsoft.backgroundfetch.HeadlessJobService
System.err:     at java.lang.Class.classForName(Native Method)
System.err:     at java.lang.Class.forName(Class.java:453)
System.err:     at java.lang.Class.forName(Class.java:378)
System.err:     at com.transistorsoft.tsbackgroundfetch.BackgroundFetch.onFetch(BackgroundFetch.java:176)
System.err:     at com.transistorsoft.tsbackgroundfetch.BackgroundFetch.onFetch(BackgroundFetch.java:151)
System.err:     at com.transistorsoft.tsbackgroundfetch.FetchJobService.onStartJob(FetchJobService.java:22)
System.err:     at android.app.job.JobService$1.onStartJob(JobService.java:71)
System.err:     at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
System.err:     at android.os.Looper.loop(Looper.java:164)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6494)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.transistorsoft.backgroundfetch.HeadlessJobService" on path: DexPathList[[zip file "/data/app/com.test.app-hFj8-9wq6p-ke3BOsoW15Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.app-hFj8-9wq6p-ke3BOsoW15Q==/lib/arm, /data/app/com.test.app-hFj8-9wq6p-ke3BOsoW15Q==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
System.err:     ... 14 more

Any ideas? A full re-build didn't help.

@christocracy
Copy link
Member

Ensure you’re using latest background-fetch

@ssulei7
Copy link
Author

ssulei7 commented Sep 21, 2018

I'm using version 1.20 of the plugin, and I'm still receiving the Class Not Found exception.

Not sure if relevant, but our background geolocation config is below - in case there's some sort of conflict with this plugin?

        await BackgroundGeolocation.clearDatabase();
        await BackgroundGeolocation.ready({
            ...baseCfg,

            reset: true,

            // enable background tracking
            stopOnTerminate: false,

            // HTTP
            url: `${this.baseCloudFunc}/updateUserLocation`,
            httpRootProperty: 'data',
            locationTemplate: '{ "lat": <%= latitude %>, "lon": <%= longitude %> }',
            geofenceTemplate: '{ "lat": <%= latitude %>, "lon": <%= longitude %>, "geofenceId": "<%= geofence.identifier %>", "geofenceAction": "<%= geofence.action %>" }',
            autoSync: true,

            // battery opts
            disableMotionActivityUpdates: true // disable for all but select group
        });

@christocracy
Copy link
Member

@neil-119
Copy link

I'm getting this same issue, even after installing the latest version and doing the above. It seems using Background Geolocation plugin and this plugin at the same time (since the former also uses background fetch?) causes issues?

@neil-119
Copy link

I'll come up with a workaround for this no problem

@christocracy
Copy link
Member

@neil-119 They're designed to work together. Background Geolocation uses background-fetch internally for its own purposes.

@FranciZ
Copy link

FranciZ commented Feb 2, 2019

This issue appears on SDK version 19 for me. Any updates on solution?

System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.transistorsoft.backgroundfetch.HeadlessJobService" on path: DexPathList[[zip file "/data/app/app.loco-1.apk", zip file "/data/data/app.loco/code_cache/secondary-dexes/app.loco-1.apk.classes2.zip", zip file "/data/data/app.loco/code_cache/secondary-dexes/app.loco-1.apk.classes3.zip"],nativeLibraryDirectories=[/data/app-lib/app.loco-1, /vendor/lib, /system/lib]]

@svilenkov
Copy link

@FranciZ I'm getting the same crash reports on google play for some phones (eg Android 4.3). Probably because of the targetApi(21) https://github.com/transistorsoft/transistor-background-fetch/blob/master/android/tsbackgroundfetch/src/main/java/com/transistorsoft/tsbackgroundfetch/FetchJobService.java#L12

For me the background service is not a mandatory feature, but a desired one. So I'll try disabling the feature on <21 sdk versions using device.sdkVersion

Also might be useful looking it this answer: https://stackoverflow.com/a/58427864

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants