Oraylien
Oraylien

Reputation: 21

How to make my expo app an android Accessibility Service

When trying to make an android Accessibility Service by adding a custom module to my expo app, I get an error building my dev build

I've just started using expo a few weeks ago because I wanted to build an android app able to block the usage of other apps (an app blocker). It would restrict me from opening YouTube more than 1 hour a day for example.

This type of android app is called an accessibility service. I understand that I need to use a development build because expo go isn't allowed to be an Accessibility Service.

So my approach is to create a module using "npx create-expo-module@latest --local" (because i get this error if I don't create it localy) In my new module, I update my manifest in modules/my-module/android/src/main/AndroixManifest.xml following these guidelines

I then create a new class extending AccessibilityService()

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo

class MyAccessibilityService : AccessibilityService() {

    override fun onAccessibilityEvent(event: AccessibilityEvent) {
        if (event.packageName != null && event.packageName.toString() == com.google.android.youtube") {
            performGlobalAction(GLOBAL_ACTION_BACK)
        }
    }

    override fun onInterrupt() { }
}

But when I try to test it and run eas build --profile development --platform android, I get an error at the step "Run gradlew" :

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed with multiple errors, see logs
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4m 3s
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

Am I doing this the right way and if so, how to I solve this error ?

Thank you so much

Upvotes: 2

Views: 434

Answers (0)

Related Questions