Open christocracy opened 4 years ago
Try replacing the plugin's build.gradle
with this one, which is purely based upon $projectDir
(no userDir
).
def TAG = "[cordova-background-geolocation] "
def userDir = System.getProperty("user.dir")
def libDir = "${projectDir}/libs"
println("userDir: $userDir");
println("projectDir: $projectDir");
File capacitorConfig = new File("${projectDir}/../../capacitor.config.json")
if (capacitorConfig.exists()) {
def pluginName = ""
def CORDOVA_BACKGROUND_GEOLOCATION_LT = "cordova-background-geolocation-lt"
def CORDOVA_BACKGROUND_GEOLOCATION = "cordova-background-geolocation"
// Capacitor app
libDir = "${projectDir}/../../node_modules"
File folder = new File("${libDir}/${CORDOVA_BACKGROUND_GEOLOCATION}")
if (folder.exists() && folder.isDirectory()) {
pluginName = CORDOVA_BACKGROUND_GEOLOCATION
} else {
folder = new File("${libDir}/${CORDOVA_BACKGROUND_GEOLOCATION_LT}")
if (folder.exists() && folder.isDirectory()) {
pluginName = CORDOVA_BACKGROUND_GEOLOCATION_LT
} else {
println("$TAG Gradle error: Failed to locate plugin directory")
}
}
libDir = "${libDir}/${pluginName}/src/android/libs"
println("${TAG} Capacitor detected")
} else {
// Capacitor does not have the scope here to use android.applicationVariants.
// Capacitor users must manually include app.gradle in their app's gradle file.
cdvPluginPostBuildExtras.add({
android {
purgeBackgroundGeolocationDebugResources(applicationVariants)
}
})
}
println("${TAG} libDir: ${libDir}")
dependencies {
// Load tslocationmanager.aar
implementation fileTree(include: ['*.aar'], dir: "${libDir}/tslocationmanager")
}
/**
* Background Geolocation's aar includes about 1.5M of mp3 sound-files for its debugging sound FX.
* This method strips those mp3s out in RELEASE builds.
*/
def purgeBackgroundGeolocationDebugResources(applicationVariants) {
if ((ext.has("removeBackgroundGeolocationDebugSoundsInRelease")) && (ext.removeBackgroundGeolocationDebugSoundsInRelease == false)) return
applicationVariants.all { variant ->
// Only Gradle v3.3.0 has this method. Bail out for older versions of Cordova.
if (!variant.hasProperty('mergeResourcesProvider')) return
if (variant.buildType.name == "release") {
println("[cordova-background-geolocation] Purging debug resources in release build")
variant.mergeResourcesProvider.configure {
doLast {
delete(fileTree(dir: outputDir, includes: ["raw_tslocationmanager*"]))
}
}
}
}
}
My original results where:
[19:21:32]: ▸ [cordova-background-geolocation] : userDir: /builds/soleary1222/helloworld-background-geolocation
[19:21:32]: ▸ [cordova-background-geolocation] : projectDir: /builds/soleary1222/helloworld-background-geolocation/android/app
I think your second post is the correct solution. From my limited knowledge and what I read, "System.getProperty("user.dir")" is not globally reliable across platforms and build systems.
Please let me know ASAP if my modified build.gradle above works for you.
Yes - your modified build.gradle did in fact work for me.
After cloning this app, I successfully built locally without a problem.
I do not use 3rd party build systems.
Add the following logging lines to the plugin's
build.gradle
and show me the result:Here's what I see: