mauron85 / react-native-background-geolocation

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
Apache License 2.0
1.33k stars 559 forks source link

SDK 31 - Android 12 specify an explicit value for `android:exported` #571

Open romancxx opened 2 years ago

romancxx commented 2 years ago

Your Environment

Context

I am trying to run my app on Android after installing the package. I had a few errors that I solved with answers of other issues but I'm stuck with this one :

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/romancirier/Documents/freelance/SkydingApp/node_modules/@mauron85/react-native-background-geolocation/android/lib/src/main/AndroidManifest.xml Error:
    android:exported needs to be explicitly specified for <service>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':@mauron85_react-native-background-geolocation:processDebugManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
   > Manifest merger failed : android:exported needs to be explicitly specified for <service>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

Not like the example app, I'm trying to compile with the SDK 31. I couldn't find any example using higher than 28 but it is mandatory for me. My build.gradle ext looks like :

    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        // I added this but it doesn't change anything with or without it
        googlePlayServicesVersion = "9.8.0"

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }

    }

My dependencies are (I'm using react-native-maps if that could be a problem) :

"@mauron85/react-native-background-geolocation": "^0.6.3",
    "@react-native-async-storage/async-storage": "^1.17.6",
    "@react-native-community/checkbox": "^0.5.12",
    "@react-navigation/bottom-tabs": "^6.3.1",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/native-stack": "^6.6.2",
    "@reduxjs/toolkit": "^1.8.1",
    "@sentry/react-native": "^3.4.3",
    "axios": "^0.27.2",
    "i18n-js": "^3.9.2",
    "moment": "^2.29.3",
    "react": "17.0.2",
    "react-native": "0.68.2",
    "react-native-animated-scroll-modal": "^0.6.5",
    "react-native-background-actions": "^2.6.7",
    "react-native-fast-image": "^8.5.11",
    "react-native-geolocation-service": "^5.3.0-beta.4",
    "react-native-gesture-handler": "^2.4.2",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-maps": "^0.30.1",
    "react-native-maps-directions": "^1.8.0",
    "react-native-pager-view": "^5.4.23",
    "react-native-permissions": "^3.3.1",
    "react-native-reanimated": "^2.8.0",
    "react-native-safe-area-context": "^4.2.5",
    "react-native-screens": "^3.13.1",
    "react-native-splash-screen": "^3.3.0",
    "react-native-svg": "^12.3.0",
    "react-native-tab-view": "^3.1.1",
    "react-native-toast-message": "^2.1.5",
    "react-native-track-player": "^2.2.0-rc3",
    "react-redux": "^8.0.2",
    "redux-persist": "^6.0.0",
    "use-debounce": "^8.0.1"

I also added :

include ':@mauron85_react-native-background-geolocation-common'
project(':@mauron85_react-native-background-geolocation-common').projectDir = new File(rootProject.projectDir, '../node_modules/@mauron85/react-native-background-geolocation/android/common')
include ':@mauron85_react-native-background-geolocation'
project(':@mauron85_react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@mauron85/react-native-background-geolocation/android/lib')

to the setting.gradle to solve another issue.

Expected Behavior

Build successfully

Actual Behavior

Error

Possible Fix

No idea.

Steps to Reproduce

  1. Installing the dependencies as I have
  2. Building the app

Context

Debug logs

romancxx commented 2 years ago

If anyone is experiencing the same problem, I solved it by patching this package with :

       <service
            android:name="com.marianhello.bgloc.sync.AuthenticatorService">
            android:exported="true">  <<<<< Add this to AndroidManifest.xml L34
gomezmark commented 2 years ago

android:exported="true"

I tried this one, unlucky for me not working on my end.

Do you have any suggestion?

skvaghasiya402 commented 1 year ago

I solved it by

OR

add android:exported="true" in /node_modules/@mauron85/react-native-background-geolocation/android/lib/src/main/AndroidManifest.xml

I hope it's working.

kapilavaiya commented 1 year ago

android sdk 31, android exported fix #574

This

you have to add android:exported="true" in /node_modules/@mauron85/react-native-background-geolocation/android/lib/src/main/AndroidManifest.xml

I have tried this but still i'm getting this error

Y-k-Y commented 1 year ago

If anyone is experiencing the same problem, I solved it by patching this package with :

       <service
            android:name="com.marianhello.bgloc.sync.AuthenticatorService" // maybe should remove '>'
            android:exported="true">  <<<<< Add this to AndroidManifest.xml L34
kapilavaiya commented 1 year ago

<service android:name="com.marianhello.bgloc.sync.AuthenticatorService" // maybe should remove '>' android:exported="true"> <<<<< Add this to AndroidManifest.xml L34

Solved using this thanks !

fatinfarzanaazizan commented 1 year ago

hi, is there a way we can get this in the library and not update the AndroidManifest.xml manually?

kapilavaiya commented 1 year ago

@fatinfarzanaazizan You can update your react native version if you don't want to update manually

fatinfarzanaazizan commented 1 year ago

@avaiyakapil thanks. can you help to explain how would that help? would it also help solving Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE error that occurs in DistanceFilterLocationProvider file for this library?

adewalebanjo commented 1 year ago

@fatinfarzanaazizan Did you find a solution to the Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE error?

fatinfarzanaazizan commented 1 year ago

@adewalebanjo no, still having this issue unfortunately.

nassimmiled commented 1 year ago

@fatinfarzanaazizan the same issue for me

Linuhusainnk commented 6 months ago

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE

Any solution?