How to run a service(to perform some task) exactly every 5 minute without any fail. I had a working code for the above requirement using Alarmmanager but its failing since i am trying to target Android 8(Oreo).
There are lots of things in Android when put together, they won't work as expected. The problem you are facing has been solved by new WorkManager API. From official documentation:
WorkManager chooses the appropriate way to run your task based on such factors as the device API level and the app state. If WorkManager executes one of your tasks while the app is running, WorkManager can run your task in a new thread in your app's process. If your app is not running, WorkManager chooses an appropriate way to schedule a background task--depending on the device API level and included dependencies, WorkManager might use JobScheduler, Firebase JobDispatcher, or AlarmManager.
So WorkManager will take care of what to run based various factors and makes everything a lot easier and cleaner.
For your scenario, You can use recurring tasks:
https://developer.android.com/topic/libraries/architecture/workmanager#recurring