React-native-background-geolocation: Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints

Created on 4 Jul 2019  路  18Comments  路  Source: transistorsoft/react-native-background-geolocation

Your Environment

"name": "newBackgroundGps",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"cocoa-lumberjack": "^3.0.5",
"react": "16.8.6",
"react-native": "0.60.0",
"react-native-background-fetch": "^2.6.0",
"react-native-background-geolocation": "^3.0.7"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/runtime": "^7.4.5",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.8.0",
"eslint": "^6.0.1",
"jest": "^24.8.0",
"metro-react-native-babel-preset": "^0.55.0",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}

  • Plugin config
    NA

Expected Behavior

Android can build successfully - using React-native 0.60.0

Actual Behavior

Failed with error message:

Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints:

Steps to Reproduce

  1. Build a brand new app via react-native init
  2. Install react-native-background-geolocation following instructions precisely
  3. Open in Android studio
  4. Error is shown, even after "clean build" is run

Context

Create a barebone project with react-native 0.60 and react-native-background-geolocation
See gif recording off all steps:

react-native-0 60-background-geolocation-error

Debug logs


Logs

```
Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints:
Dependency path 'newBackgroundGps:react-native-background-geolocation:unspecified' --> 'com.android.support:appcompat-v7:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled
Constraint path 'newBackgroundGps:react-native-background-geolocation:unspecified' --> 'androidx.appcompat:appcompat:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
Dependency path 'newBackgroundGps:react-native-background-geolocation:unspecified' --> 'com.facebook.react:react-native:0.60.0' --> 'androidx.appcompat:appcompat:1.0.2'

```

Most helpful comment

react-native-firebase has some issues with androidx library specification, and an unrelated issue with CI that is stopping us from releasing v5.5.7 :-(

https://github.com/invertase/react-native-firebase/pull/2476

I have attached a patch-package file in a comment on that pull request for people to use in the meantime, I needed it in my project - either for this module in combo with react-native-firebase or another, I'm not sure https://github.com/invertase/react-native-firebase/pull/2476#issuecomment-521670164

All 18 comments

Yes, migrating to AndroidX is going to be a pain for the next while.

See here

https://github.com/mikehardy/jetifier should ease the transition but gradle dependencies analysis is a skill that most have avoided so there's always some learning involved

Thanks @mikehardy. I'm going to have to look into providing better support for AndroidX. I see what you did here. I knew AndroidX was going to be painful. Can't wait until this is all behind us.

I鈥檝e pushed a commit to master of private repo which should help fix this.

Will your update be pushed to the public repo? kinda makes the library dead in the water as it is now

See CHANGELOG

Hi,
as a temporary solution !!! I changed the build.gradle under android folder in node_modules react-native-background-geolocation.

compileOnly 'com.facebook.react:react-native:+'

TO

implementation('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}

full build.gradle:

apply plugin: 'com.android.library'

// Android dependencies
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0"

// Plugin dependencies
def DEFAULT_GOOGLE_PLAY_SERVICES_LOCATION_VERSION = "17.0.0"
def DEFAULT_OK_HTTP_VERSION = "3.12.1"
def DEFAULT_ANDROID_PERMISSIONS_VERSION = "0.1.8"
def DEFAULT_EVENTBUS_VERSION = "3.0.0"
def DEFAULT_REMOVE_DEBUG_SOUNDS_IN_RELEASE = true

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)

defaultConfig {
    minSdkVersion 16
    targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
    versionCode 1
    versionName "1.0"
}

// TODO
def removeDebugSounds = safeExtGet('removeBackgroundGeolocationDebugSoundsInRelase', DEFAULT_REMOVE_DEBUG_SOUNDS_IN_RELEASE)

}

repositories{
maven {
url './libs'
}
}

dependencies {
def supportLibVersion = safeExtGet('supportLibVersion', DEFAULT_SUPPORT_LIB_VERSION)
def supportLibMajorVersion = supportLibVersion.split('\.')[0] as int
def appCompatLibName = (supportLibMajorVersion < 20) ? "androidx.appcompat:appcompat" : "com.android.support:appcompat-v7"
def playServicesLocationVersion = safeExtGet('googlePlayServicesLocationVersion', DEFAULT_GOOGLE_PLAY_SERVICES_LOCATION_VERSION)
def okHttpVersion = safeExtGet('okHttpVersion', DEFAULT_OK_HTTP_VERSION)
def androidPermissionsVersion = safeExtGet('androidPermissionsVersion', DEFAULT_ANDROID_PERMISSIONS_VERSION)
def eventBusVersion = safeExtGet('eventBusVersion', DEFAULT_EVENTBUS_VERSION)

implementation('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
implementation "$appCompatLibName:$supportLibVersion"
implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
implementation "org.greenrobot:eventbus:$eventBusVersion"
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation(group: 'com.transistorsoft', name:'tslocationmanager', version: '+')
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.github.tony19:logback-android:1.3.0-2'
implementation "com.intentfilter:android-permissions:$androidPermissionsVersion"

}

The latest version works perfectly fine with a new RN app - I didn鈥檛 have to change anything.

I still get this error :(
Doing

implementation('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}

Fixes it

If you have to exclude com.android.support, you have problems with other plugins or you haven鈥檛 carefully followed the setup steps.

There鈥檚 no such thing as com.android.support when using AndroidX.

Changing compileonly too

implementation('com.facebook.react:react-native:+')

Without exclude group Works too.. I had/have only problems with "compileOnly"
In RN 0.60.4

It鈥檚 always a good idea to generate a fresh new react native init foo to see what the default template generates.

Sometimes it鈥檚 a good idea to regen a fresh app and move your JS into it.

Hi again Just created a new test project , everything Works fine with only backgroundgeolocation installed, after installing firebase and react-native-maps i run into this problem again.

:(..

I found the quick solution for changing compileonly to implementation here:
HTTPS://github.com/react-native-community/react-native-maps/issues/2940

Runing with RN 0.60.4

@christocracy I had/have the same issue. I am on 0.60.5 and have followed the guide for >= 0.60. I also have some of the same modules as people mention above. (rn-firebase, rn-maps). Though I am not sure it is the correct solution, it is true, that if I change your build.gradle to not use compileOnly the app compiles.

Change: https://github.com/transistorsoft/react-native-background-geolocation/blob/master/android/build.gradle#L48

To

implementation ('com.facebook.react:react-native:+') {
    exclude group: 'com.android.support'
}

Possibly without the exclude

PS: I have jetifier enabled. That might be relevant

Show me your gradle files:

  • android/build.gradle
  • android/app/build.gradle

react-native-firebase has some issues with androidx library specification, and an unrelated issue with CI that is stopping us from releasing v5.5.7 :-(

https://github.com/invertase/react-native-firebase/pull/2476

I have attached a patch-package file in a comment on that pull request for people to use in the meantime, I needed it in my project - either for this module in combo with react-native-firebase or another, I'm not sure https://github.com/invertase/react-native-firebase/pull/2476#issuecomment-521670164

Thanks @mikehardy.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ca057 picture ca057  路  7Comments

lyseiha picture lyseiha  路  6Comments

farshid1 picture farshid1  路  5Comments

alanhoff picture alanhoff  路  7Comments

leighquince picture leighquince  路  3Comments