react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

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

Open romancxx opened this issue 2 years ago • 14 comments

Your Environment

  • Plugin version: 0.6.3
  • Platform: Android
  • OS version: 12
  • Device manufacturer and model: Mi 10 Lite
  • Running in Simulator: No
  • React Native version: 0.68.2
  • Plugin configuration options: /
  • Link to your project: /

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 avatar Jul 11 '22 15:07 romancxx

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

romancxx avatar Jul 12 '22 08:07 romancxx

android:exported="true"

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

Do you have any suggestion?

gomezmark avatar Aug 17 '22 05:08 gomezmark

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

harshgupta-harry avatar Sep 09 '22 11:09 harshgupta-harry

I solved it by

  • Deleting node_modules is as simple as writing the node_modules without a slash:
  • rm -rf node_modules // in your project path
  • npm install or npm install --force
  • npx react-native run-android

OR

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

I hope it's working.

skvaghasiya402 avatar Nov 01 '22 11:11 skvaghasiya402

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

  • 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 : 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.

kapilavaiya avatar Nov 25 '22 13:11 kapilavaiya

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

Y-k-Y avatar Nov 28 '22 08:11 Y-k-Y

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

Solved using this thanks !

kapilavaiya avatar Nov 28 '22 08:11 kapilavaiya

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

fatinfarzanaazizan avatar Feb 10 '23 08:02 fatinfarzanaazizan

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

kapilavaiya avatar Feb 13 '23 04:02 kapilavaiya

@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?

fatinfarzanaazizan avatar Feb 13 '23 05:02 fatinfarzanaazizan

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

adewalebanjo avatar Apr 05 '23 18:04 adewalebanjo

@adewalebanjo no, still having this issue unfortunately.

fatinfarzanaazizan avatar Apr 06 '23 02:04 fatinfarzanaazizan

@fatinfarzanaazizan the same issue for me

nassimmiled avatar Apr 28 '23 17:04 nassimmiled

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

Any solution?

Linuhusainnk avatar Feb 18 '24 13:02 Linuhusainnk