Skip to content

Latest commit

 

History

History
71 lines (53 loc) · 2.68 KB

INSTALL-AUTO-ANDROID.md

File metadata and controls

71 lines (53 loc) · 2.68 KB

Android Auto-linking Setup

react-native >= 0.60

With yarn

$ yarn add react-native-background-fetch

With npm

$ npm install --save react-native-background-fetch

Gradle Configuration

The SDK requires a custom maven url in the root android/build.gradle. Please note that some more recent versions of React Native the Android template may not include allprojects section. You should add this manually as a separate section along with the nested repositories section in the same android/build.gradle file.

📂 android/build.gradle

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 {
+           // react-native-background-fetch
+           url("${project(':react-native-background-fetch').projectDir}/libs")
+       }

    }
}

Configure proguard-rules.pro

If you're using minifyEnabled true with your Android release build, the plugin's HeadlessTask class will be mistakenly removed and you will have this crash.

  1. Edit android/app/proguard-rules.pro.
  2. Add the following rule:
# [react-native-background-fetch]
-keep class com.transistorsoft.rnbackgroundfetch.HeadlessTask { *; }

Precise event-scheduling with forceAlarmManager: true:

Only If you wish to use precise scheduling of events with forceAlarmManager: true, Android 14 (SDK 34), has restricted usage of "AlarmManager exact alarms". To continue using precise timing of events with Android 14, you can manually add this permission to your AndroidManifest. Otherwise, the plugin will gracefully fall-back to "in-exact AlarmManager scheduling":

📂 In your AndroidManifest, add the following permission (exactly as-shown):

  <manifest>
      <uses-permission android:minSdkVersion="34" android:name="android.permission.USE_EXACT_ALARM" />
      .
      .
      .
  </manifest>

⚠️ It has been announced that Google Play Store has plans to impose greater scrutiny over usage of this permission (which is why the plugin does not automatically add it).