yarn add react-native-background-geolocationnpm install react-native-background-geolocation--save+include ':react-native-background-geolocation'
+project(':react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-geolocation/android')
+include ':react-native-background-fetch'
+project(':react-native-background-fetch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-fetch/android')buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
// You can control the SDK's version of play-services:location
// You should always use the latest available version.
+ googlePlayServicesLocationVersion = "16.0.0"
}
.
.
.
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
+ maven {
+ // Required for react-native-background-geolocation
+ url("${project(':react-native-background-geolocation').projectDir}/libs")
+ }
+ maven {
+ // Required for react-native-background-fetch
+ url("${project(':react-native-background-fetch').projectDir}/libs")
+ }
+ }
}Background Geolocation requires a gradle extension for your app/build.gradle.
apply from: "../../node_modules/react-native/react.gradle"
+Project background_geolocation = project(':react-native-background-geolocation')
+apply from: "${background_geolocation.projectDir}/app.gradle"
.
.
.
dependencies {
+ implementation project(':react-native-background-geolocation')
+ implementation project(':react-native-background-fetch')
}If you've not purchased a license, ignore this step — the plugin is fully functional in DEBUG builds so you can try before you buy.
📂 android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.transistorsoft.backgroundgeolocation.react">
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<!-- react-native-background-geolocation licence -->
+ <meta-data android:name="com.transistorsoft.locationmanager.license" android:value="YOUR_LICENCE_KEY_HERE" />
.
.
.
</application>
</manifest>
+import com.transistorsoft.rnbackgroundgeolocation.*;
+import com.transistorsoft.rnbackgroundfetch.RNBackgroundFetchPackage;
public class MainApplication extends ReactApplication {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNBackgroundGeolocation(),
+ new RNBackgroundFetchPackage(),
new MainReactPackage()
);
}
}If you've enabled def enableProguardInReleaseBuilds = true in your app/build.gradle, be sure to add the BackgroundGeolocation SDK's proguard-rules.pro to your proguardFiles:
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = true
.
.
.
android {
.
.
.
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
// Add following proguardFiles (leave existing one above untouched)
+ proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro"
signingConfig signingConfigs.release
}
}
}"ERROR: Could not get unknown property 'background_geolocation' for project ':app'", see above and make sure to define the Project background_geolocation.