React-native-background-geolocation: Gradle project sync failed

Created on 30 Jul 2019  路  15Comments  路  Source: transistorsoft/react-native-background-geolocation

My environment

Plugin version:

    "react-native-background-fetch": "^2.6.1",
    "react-native-background-geolocation": "^3.0.9",

Platform: Android
OS Version: 27
Device manufacturer / model: /
React Native version:

    "react-native": "0.60.0",

Expected Behaviour

No gradle project sync issues

Actual Behaviour

Gradle project sync failed

Steps to Reproduce

  1. Install react-native-background-geolocation according to the documentation for Android
  2. Gradle project sync failed message on Android Studio IDE => click Try Again

Debug logs

Logs

```
WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
REASON: Called from: /Users/laurens/Documents/SweetMustard/locator/android/app/build.gradle:209
WARNING: Debugging obsolete API calls can take time during configuration. It's recommended to not keep it on at all times.
Affected Modules: app

</details>

## Issue

The issue seems to come from following code in ```app build.gradle```

// [Added by react-native-background-geolocation] Purge debug sounds from release build.
def purgeBackgroundGeolocationDebugResources(applicationVariants) {
if ((rootProject.ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (rootProject.ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
applicationVariants.all { variant ->
if (variant.buildType.name == "release") {
println("[react-native-background-geolocation] Purging debug resources in release build")
variant.mergeResources.doLast {
delete(fileTree(dir: variant.mergeResources.outputDir, includes: ["raw_tslocationmanager*"]))
}
}
}
}
```

bug

Most helpful comment

I was able to clear the warning by following @mikehardy link. Final code:

def purgeBackgroundGeolocationDebugResources(applicationVariants) {
    if ((rootProject.ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (rootProject.ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
    applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            println("[react-native-background-geolocation] Purging debug resources in release build")
            variant.mergeResourcesProvider.configure {
                doLast {
                    delete(fileTree(dir: outputDir, includes: ["raw_tslocationmanager*"]))
                }
            }
        }
    }
}

All 15 comments

That is not the reason, it鈥檚 only a warning.

I'm having the same warning thrown, but my app still builds though. What is the timeline for this fix @christocracy? Thanks.

This is a very minor thing. The plugin includes a number of debug sound effect sound-files in its native library, which adds about 1M in size to your `.apk.

The script where this warning is coming from strips these extra mp3s from your .apk.

When Google removes this method, it will do so in the latest release of gradle, which you won't be using with RN for quite some time after 2019, probably more like some time in late 2020.

That's where this warning was coming from! I was going to hunt that down at some point, forgot about this code.

I agree it's not time-pressing, but perhaps seeing the diff on similar code is useful as it seems to snipe this one (module change from assets to resources) https://stackoverflow.com/posts/39760001/revisions

I was able to clear the warning by following @mikehardy link. Final code:

def purgeBackgroundGeolocationDebugResources(applicationVariants) {
    if ((rootProject.ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (rootProject.ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
    applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            println("[react-native-background-geolocation] Purging debug resources in release build")
            variant.mergeResourcesProvider.configure {
                doLast {
                    delete(fileTree(dir: outputDir, includes: ["raw_tslocationmanager*"]))
                }
            }
        }
    }
}

Thanks @mikehardy. Works with a slight modification, using variant.mergeResourcesProvider instead of variant.mergeAssetsProvider.

applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            println("[react-native-background-geolocation] Purging debug resources in release build")
            variant.mergeResourcesProvider.configure {
                doLast {
                    delete(fileTree(dir: outputDir, includes: ["raw_tslocationmanager*"]))
                }
            }
        }
    }

@Raymond-Cox I see you've independently confirmed as well. This will be applied to next release.

Release apk file size:

No stripping:  22 234 220
Old method:   20 797 611
New method: 20 797 635

Odd that there is any difference :thinking: - but mostly saying there's a typo here https://github.com/transistorsoft/react-native-background-geolocation/blob/master/android/build.gradle#L30 (the method call)

Thanks @mikehardy. That variable isn't used and will be deleted. That's a relic from when I was trying to perform the gradle task within the context of the plugin's build.gradle, which turned out to be impossible.

The gradle option is actually used within the auto-rendered function itself within the context of the app's build.gradle

// [Added by react-native-background-geolocation] Purge debug sounds from release build.
def purgeBackgroundGeolocationDebugResources(applicationVariants) {
    // >>>>>>>>>>> HERE <<<<<<<<<<<<<
    if ((rootProject.ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (rootProject.ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
    applicationVariants.all { variant ->
        if (variant.buildType.name == "release") {
            println("[react-native-background-geolocation] Purging debug resources in release build")
            variant.mergeResourcesProvider.configure {
                doLast {
                    delete(fileTree(dir: outputDir, includes: ["raw_tslocationmanager*"]))
                }
            }
        }
    }
}

I'm probably the only person who actually uses removeBackgroundGeolocationDebugSoundsInRelease = false. When I publish the SampleApp to Play Store, I actually want the debug sounds to stay.

Incidentally, you might actually be able to do what you want to do without code in build.gradle, but people would still need to reference a gradle file from your project - this is how vector-icons controls which fonts are copied into the APK https://github.com/oblador/react-native-vector-icons#android / https://github.com/oblador/react-native-vector-icons/blob/master/fonts.gradle - it's sort of similar.

Is this better? I dunno - it puts you in control of the gradle code so it is auto-updated as versions update, vs just publishing a doc change with a release and notifying people they need to paste new code in the changelog, so it seems a little better, but it still isn't awesome.

I noticed this because even after the previous change I have something else doing mergeResources access instead of the provider style. Still not important but I thought I had a quick broken window fixed here :-)

It's always better to be able to perform this within the plugin's build.gradle. Removes the ugliness of having to render that gradle function with the react-native init hook-script.

If anyone is hunting these down and also using react-native-firebase, they're the another cause of this https://github.com/google/play-services-plugins/pull/62

My build's all quiet with the change here and the one referenced in that PR

And that concludes my priority inversion for the day

This is fixed in 3.2.0. See new Setup Guides

Was this page helpful?
0 / 5 - 0 ratings