transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.65k stars 426 forks source link

installing for Android #1769

Closed milobob closed 1 year ago

milobob commented 1 year ago

Could not get unknown property 'background_geolocation'

I am able to get the react-native-background-geolocation working on iOS, but I'm trying to compile for Android and having issues. I think it has to do with gradle settings, which are somewhat of a black box

My Environment

/**

/**

/**

android { ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion

namespace "com.REMOVEDFORPRIVACY"
defaultConfig {
    applicationId "com.REMOVEDFORPRIVACY"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    missingDimensionStrategy 'react-native-camera', 'general'
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://reactnative.dev/docs/signed-apk-android.
        signingConfig signingConfigs.debug
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro"
    }
}

}

dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android")

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
    implementation("com.facebook.react:hermes-android")
} else {
    implementation jscFlavor
}

}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Project background_geolocation = project(':react-native-background-geolocation') apply from: "${background_geolocation.projectDir}/app.gradle"


## Expected Behavior
Compiles and runs on emulator

## Actual Behavior
When I try react-native run-android, it starts building and installing, but then crashes with "Command failed with exit code 1"

## Steps to Reproduce
reproduce this issue; include code to reproduce, if relevant 
1. follow help guide at https://github.com/transistorsoft/react-native-background-geolocation/blob/master/README.md

## Context
Migrate app from iOS to Android

## Debug logs
One thing that was weird is Android studio does not seem to like the line
`Project background_geolocation = project(':react-native-background-geolocation')
`
Although this line was suggested by transistorsoft in the readme, Android Studio is throwing an error of "Cannot resolve symbol 'Project'" in the app\build.grade file 

I'm probably missing something simple because I am completely new to Android development, any help would be much appreciated
<details><summary>Logs</summary>

error Failed to install the app. Command failed with exit code 1: gradlew.bat tasks FAILURE: Build failed with an exception. Where: Build file 'C:\Users\REMOVEDFORPRIVACY\Documents\REMOVEDFORPRIVACY\REMOVEDFORPRIVACY\android\app\build.gradle' line: 103 What went wrong: A problem occurred evaluating project ':app'. > Could not get unknown property 'background_geolocation' for BuildType$AgpDecorated_Decorated{name=release, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, minifyEnabled=false, zipAlignEnabled=true, signingConfig=SigningConfig$AgpDecorated_Decorated{name=debug, storeFile=C:\Users\REMOVEDFORPRIVACY\Documents\REMOVEDFORPRIVACY\REMOVEDFORPRIVACY\android\app\debug.keystore, storePassword=android, keyAlias=androiddebugkey, keyPassword=android, storeType=pkcs12, v1SigningEnabled=true, v2SigningEnabled=true, enableV1Signing=null, enableV2Signing=null, enableV3Signin g=null, enableV4Signing=null}, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[C:\Users\REMOVEDFORPRIVACY\Documents\REMOVEDFORPRIVACY\REMOVEDFORPRIVACY\android\app\build\intermediates\default_proguard_files\global\proguard-android.txt-7 .4.2, C:\Users\REMOVEDFORPRIVACY\Documents\REMOVEDFORPRIVACY\REMOVEDFORPRIVACY\android\app\proguard-rules.pro], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.BuildType$AgpDecorated. 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. Get more help at https://help.gradle.org BUILD FAILED in 35s

Task :gradle-plugin:compileKotlin UP-TO-DATE > Task :gradle-plugin:compileJava NO-SOURCE > Task :gradle-plugin:pluginDescriptors UP-TO-DATE > Task :gradle-plugin:processResources UP-TO-DATE > Task :gradle-plugin:classes UP-TO-DATE > Task :gradle-plugin:jar UP-TO-DATE > Task :gradle-plugin:inspectClassesForKotlinIC UP-TO-DATE 5 actionable tasks: 5 up-to-date.



</details>
christocracy commented 1 year ago

OS version: API 34

I have not yet released api 34 support.

Jorge-Luis-Rangel-Peralta commented 1 year ago

This is still happening with this api version:

buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33

Is there something that I could do?, I am using react native 0.72.5

christocracy commented 1 year ago

Create for me a simple HelloWorld app that reproduces this. Push to a public GitHub repository and share the url here.

Jorge-Luis-Rangel-Peralta commented 1 year ago

Hi, I did create the repo: https://github.com/Jorge-Luis-Rangel-Peralta/example-background-geolocation-rn-0.72.5/commits/main but it works and I found a typo in my config, the repo has the steps I followed to config, thanks!

christocracy commented 1 year ago

So you solved your problem?

Jorge-Luis-Rangel-Peralta commented 1 year ago

It is still compiling on the server but probably it is solved, I will confirm you both when the server reports back

christocracy commented 1 year ago

What was your mistake?

Jorge-Luis-Rangel-Peralta commented 1 year ago

All solved, the mistake was:

https://github.com/transistorsoft/react-native-background-geolocation/blob/HEAD/help/INSTALL-ANDROID-AUTO.md#open_file_folder-androidappbuildgradle // background-geolocation Project background_geolocation = project(':react-native-background-geolocation') apply from: "${background_geolocation.projectDir}/app.gradle"

Forgot the // before https and the error was almost in the same place as the report above that is why I thought was the same