React-native-background-geolocation: Could not find method flavorDimensions() for arguments [tier] on object of type org.gradle.api.internal.initialization.DefaultScriptHandler.

Created on 11 Apr 2018  Â·  40Comments  Â·  Source: mauron85/react-native-background-geolocation

Your Environment

  • Plugin version: latest
  • Platform: Android
  • OS version: build tools 3.1.0
  • Device manufacturer and model:
  • React Native version: 43
  • Plugin configuration options:
  • Link to your project:

Context


Cant install onto my project with simple react-native link 'name'

Expected Behavior


project should be linked.

Actual Behavior


Got a flavor issue with the build gradle. Added a flavorDimension as specified and it does not work.

Possible Fix

Steps to Reproduce



1.
2.
3.
4.

Context

Debug logs

gradle

Most helpful comment

Just published 0.5.0-alpha.31 with experimental gradle3 support.

  1. To enable it you would need to add following into your root build.gradle:
ext {
    compileSdkVersion = 26
    targetSdkVersion = 26
    buildToolsVersion = "27.0.3"
    supportLibVersion = "27.1.0"
    googlePlayServicesVersion = "11.8.0"
    gradle3EXPERIMENTAL = "yes"
}
  1. Add google maven repository maven { url 'https://maven.google.com' } into allprojects -> repositories
  2. Edit android/app/build.gradle
android {
...
    compileSdkVersion 26
    buildToolsVersion "27.0.3"
...
}

All 40 comments

Can you please try create it on new project:

  1. react-native init tmpProject
  2. yarn add react-native-mauron85-background-geolocation
  3. react-native link react-native-mauron85-background-geolocation

I think this issue comes if you try to compile with com.android.tools.build:gradle 3+. I am also facing this as my project uses both react-native-maps and your plugin. Latest version of react-native-maps wants gradle 3+ but not able to compile. Following is the log of run-android:

> Configure project :react-native-mauron85-background-geolocation 
Configuration 'releaseCompile' in project ':react-native-mauron85-background-geolocation' is deprecated. Use 'releaseImplementation' instead.
Configuration 'debugCompile' in project ':react-native-mauron85-background-geolocation' is deprecated. Use 'debugImplementation' instead.
Configuration 'compile' in project ':react-native-mauron85-background-geolocation' is deprecated. Use 'implementation' instead.
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-mauron85-background-geolocation-common 
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Configuration 'androidTestCompile' in project ':react-native-mauron85-background-geolocation-common' is deprecated. Use 'androidTestImplementation' instead.
Configuration 'compile' in project ':react-native-mauron85-background-geolocation-common' is deprecated. Use 'implementation' instead.
Configuration 'testCompile' in project ':react-native-mauron85-background-geolocation-common' is deprecated. Use 'testImplementation' instead.
Configuration 'oreoCompile' in project ':react-native-mauron85-background-geolocation-common' is deprecated. Use 'oreoImplementation' instead.
WARNING: The specified Android SDK Build Tools version (26.0.1) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-mauron85-background-geolocation-common'.
> All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

* 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 49s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Thanks

@shashanksinghal this was helpful.
I will try to reproduce with gradle 3+. Till it's fixed you can use older react-native-maps. I'm using version 0.20.1 in example https://github.com/mauron85/react-native-background-geolocation-example/blob/master/package.json.

Just realized you can already fix this by adding following into root build.gradle

ext {
  buildToolsVersion = "25.0.2"
}

Edit: This will fix probably the warning only and not flavor error.

What are your version of com.android.tools.build:gradle gradle and buildTools?

I have tried com.android.tools.build:gradle:2.3.0, gradle-3.5 and buildToolsVersion "25.0.2" and those are working.

In build.gradle:

com.android.tools.build:gradle:3.1.0

In gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

buildToolsVersion 25.0.2 will be ignored anyways as minimum required for gradle plugin 3.1.0 is 27 and gradle plugin 3.0.1 is 26. I tried both but same error

Please also refer Declare flavor dimensions section in Gradle 3 migration

@shashanksinghal ok I can reproduce it now with those versions.

After reading Gradle 3 migration and some testing I have bad feeling that making this work on gradle3 will require more work that I expected. Gradle 3 dropped option to specify build flavor via configuration for local modules

// This is the old method and no longer works for local
// library modules:
// debugImplementation project(path: ':library', configuration: 'debug')
// releaseImplementation project(path: ':library', configuration: 'release')

which this plugin is using to create oreo and normal flavors. But will try to finding replacement that would be be still easy to use.

Any status on this?

@kruyvanna Thanks for you work, maybe you can submit it as a pull request here?

@ivosabev I regard it as a temporary workaround since I drop support for pre-oreo build. If that's ok with @mauron85 , I can prepare a PR.
@mauron85 what do you think?

Just published 0.5.0-alpha.31 with experimental gradle3 support.

  1. To enable it you would need to add following into your root build.gradle:
ext {
    compileSdkVersion = 26
    targetSdkVersion = 26
    buildToolsVersion = "27.0.3"
    supportLibVersion = "27.1.0"
    googlePlayServicesVersion = "11.8.0"
    gradle3EXPERIMENTAL = "yes"
}
  1. Add google maven repository maven { url 'https://maven.google.com' } into allprojects -> repositories
  2. Edit android/app/build.gradle
android {
...
    compileSdkVersion 26
    buildToolsVersion "27.0.3"
...
}

@kruyvanna sorry I somehow missed your comment. Thank you for your effort, but I would like to keep support for preoreo builds and react-native project template defaults.

@mauron85 No problem. thanks for the great work :)

@mauron85 I'm not seeing the release 0.5.0-alpha.31, am I missing something?

@equesteo i used 0.5.0-alpha.34

@mauron85 @dengue8830 I use react native firebase and React-native-Maps with gralde 4.4, these two libraries are important in my project, and now I want to use them with native native background locations mauron85, but here it does not support 4 .x. This is the problem I encountered!
Your link fix gradle will only 3.x. Is there a better way? thank you 😃

Your link fix gradle will only 3.x. Is there a better way? thank you

no it should work with gradle4. Actually gradle3 is just tag name for the issue and gradle3 in my experience is not working with Android.

@mauron85 Unfortunately :(

@xuanduy96 im using the same stack,
react-native-maps
react-native-firebase
with gralde 4.4 and works fine

@mauron85 thanks, it worked with gradle 4.4.
But when I add your example code to my app, my app is quitting.

  • RN-Firebase
  • RN-Maps
  • react-native-background-geolocation
    image

@dengue8830 Can you show me the config in the project that you have successfully implemented with:
RN-Maps
RN-Firebase
RN-background-geolocation
???
And you are sure that when adding the example code of these three libraries at the same time it still works normally: D Tks

@mauron85 , @dengue8830 . I install and work ok in gradle 4.4. But when install react-native-firebase v4.2.0 then app crash. I tried doing it again many times but it still does not work. When i run react-native-firebase, no use Background thì it still work.

this dependencies app/build.gralde config
denpence
comment all config firebase then Background Work. @dengue8830 can you shgw config dependencies. please, help me.

@xuanduy96 @nguyensythinhk7

Sorry for the delay, here is my config:
UPDATE: the post became too long so i put it in this gist. Give it a star if it's useful for you

i'm not fully tested the background location yet, but it sends location to the server on foreground and background mode, i checked that

@dengue8830 thank you ! Although I have tried config according to you but still not. I configed vs gradle and firebase v3, it's work. I thing i should use this version. thank you for enthusiastic support.

my build.gradle working file

`// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
compileSdkVersion = 26
targetSdkVersion = 26
buildToolsVersion = "27.0.3"
supportLibVersion = "27.1.0"
googlePlayServicesVersion = "11.8.0"
gradle3EXPERIMENTAL = "yes"
}
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}

             maven { url 'https://plugins.gradle.org/m2/' }
              maven { url "https://jitpack.io" }
}
dependencies {
   // classpath 'com.android.tools.build:gradle:2.2.3'

    classpath 'com.android.tools.build:gradle:3.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
mavenLocal()

       mavenLocal()
                           maven { url 'https://maven.google.com' }

                   maven { url "https://jitpack.io" }
                   maven {
                       url 'https://maven.google.com/'
                       name 'Google'
                   }

                    maven { url 'https://plugins.gradle.org/m2/' }



    jcenter()

    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
}

}

subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.0.1"
}
}
}

afterEvaluate {
    project -> if (project.hasProperty("android")) {
        android {
            compileSdkVersion 26
            buildToolsVersion '26.0.1'
        }
    }
}

}
`

gradle3EXPERIMENTAL = true
this should solve it

~Just small warning. You cannot have both GRADLE3 and OREO support enabled (because react-native build script doesn't support specifying build flavor in command line and gradle3 dropped support for flavors in compile declaration).~

Sorry for confusion. I was wrong (even though I wrote the gradle scripts myself). Actually OREO support is automatically enabled with GRADLE3.

ok thanks for the info

On Mon, Jul 16, 2018 at 10:03 AM Marián Hello notifications@github.com
wrote:

Just small warming. You cannot have both GRADLE3 and OREO support enabled
(react-native build script doesn't support specifying build flavor in
command line).
If you need GRADLE3 and OREO support you need to edit
android/lib/build.gradle:

// EDIT following line from (change 'preoreo' to 'oreo')
def projectFlavor = "oreo"
if (rootProject.hasProperty('oreoEXPERIMENTAL')) {
projectFlavor = "oreo"
}

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/mauron85/react-native-background-geolocation/issues/176#issuecomment-405186585,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AjCNJ_V9eBownsYZohpazD1Ij9i_9ps-ks5uHFb7gaJpZM4TPNQB
.

I've got this happening with Gradle 4.4 :/

@rewieer check this

@dengue8830 thanks mate, adding gradle3EXPERIMENTAL fixed it for me through

Fixed by downgrading Gradle from 4.4 and linked again.
Don't know which of this fixed my issue (possibly linking issue).

i have a general purpose skeleton project, you could check the config, run it or use it directly (using react-native-rename project)

im fucked of about this plugin, i cant install ... how ever im gonna sleep

Was this page helpful?
0 / 5 - 0 ratings