mauron85 / react-native-background-geolocation

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
Apache License 2.0
1.33k stars 562 forks source link

Android release build error - classes defined multiple times #505

Open himat opened 4 years ago

himat commented 4 years ago

Your Environment

When I run ./gradlew bundleRelease, I get this error

Type org.apache.commons.io.Charsets is defined multiple times:  /Users/x/Workspace/Web/x/node_modules/@mauron85/react-native-background- 
 geolocation/android/common/build/.transforms/a8e102993c8c7adae72bf050e6cc7e7e/classes/classes.dex,   
/Users/x/Workspace/Web/x/android/app/build/intermediates/external_libs_dex/release/out/classes2.dex

Here is my android/build.grade file in my react native project

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 21
        compileSdkVersion = 28
        targetSdkVersion = 28

        googlePlayServicesVersion = "17.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.6.4')
        classpath 'com.google.gms:google-services:4.3.3'

    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {

            url("$rootDir/../node_modules/react-native/android")
        }
        maven {

            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven { url 'https://maven.google.com'  }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

I'm able to build the app and the gps is working with yarn react-native android for local debug building. But the release build is failing using the command above.

How do I resolve this?

himat commented 4 years ago

I ran ./gradlew app:dependencies and this gave me

+--- project :mauron85_react-native-background-geolocation
|    +--- project :@mauron85_react-native-background-geolocation-common
|    |    +--- com.google.android.gms:play-services-location:17.0.0 (*)
|    |    +--- com.android.support:support-compat:28.0.0 -> androidx.core:core:1.1.0 (*)
|    |    +--- com.android.support:appcompat-v7:28.0.0 -> androidx.appcompat:appcompat:1.1.0 (*)
|    |    +--- com.intentfilter:android-permissions:0.1.7
|    |    +--- com.github.tony19:logback-android:1.1.1-9
|    |    |    \--- com.github.tony19:apktool-lib:1.4.4-5
|    |    +--- org.slf4j:slf4j-api:1.7.21
|    |    \--- com.github.jparkie:promise:1.0.3
|    +--- org.slf4j:slf4j-api:1.7.21
|    \--- com.facebook.react:react-native:+ -> 0.61.5 (*)

which seems fine and it doesn't seem like there are any same modules imported at the highest level.

So it seems like some internal module (org.apache.commons.io.Charsets) is being imported within the library somewhere.

lyseiha commented 4 years ago

using npx jetify

Edwardp17 commented 3 years ago

@himat by any chance were you able to resolve this error? I seem to be getting it as well

npx jetify did not solve my issue

darron1217 commented 3 years ago

I created fork to solve this issue. https://github.com/darron1217/react-native-background-geolocation

You can install it by command below

npm install https://github.com/darron1217/react-native-background-geolocation#develop
menynu commented 3 years ago

I had same problem with org.apache.commons.io.Charsets. Thank you @darron1217 for whatever you did, it fixed my problem.

Isaachi1 commented 1 year ago

@darron1217 your module not build release using androidX. Your module it is Symbol problem.