'Installation of @mauron85/react-native-background-geolocation

I am building a react native app and I have to get user geolocation in background. I have this error when I run npm run android after I installed this library https://github.com/mauron85/react-native-background-geolocation

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Script 'C:\Users\emanu\App\DetectApp - backup\DetectApp\node_modules\@mauron85\react-native-background-geolocation\android\common\VERSIONS.gradle' line: 27

* What went wrong:
A problem occurred evaluating project ':@mauron85_react-native-background-geolocation-common'.
> Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project.

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':@mauron85_react-native-background-geolocation-common'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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.

To install it I ran yarn add @mauron85/react-native-background-geolocation and node ./node_modules/@mauron85/react-native-background-geolocation/scripts/postlink.js as described in the automatic setup

I also use react-native-maps so I add googlePlayServicesVersion = "17.6.0" in the ext of android/build.gradle

Why I have the error? Someone can help me please?

Very thanks



Solution 1:[1]

I experienced this before. You need to do the manual setup

In android/settings.gradle

...
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')
...

In android/app/build.gradle

dependencies {
    ...
    compile project(':@mauron85_react-native-background-geolocation')
    ...
}


You may see the full documentation here
https://github.com/mauron85/react-native-background-geolocation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Riku