react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Build fails to compile

Open lucidtheory opened this issue 8 years ago • 8 comments

  • Plugin version: 2.11
  • Platform: Android
  • OS version: Mac High Sierra 10.13
  • Device manufacturer / model: Simulator/Devices
  • React Native version (react-native -v): 52

What I did: Build Project

Expected behavor: Builds correctly

Actual:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDev19Debug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

This issue pops up. Below is my build.gradle I am not sure where I am going wrong

buildscript {
  repositories {
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
  }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
//apply plugin: 'com.neenbedankt.android-apt'

repositories {
  maven { url 'https://maven.fabric.io/public' }
  flatDir {
      dirs "../../node_modules/react-native-background-geolocation/android/libs"
  }
}

android {
  compileSdkVersion 26
  buildToolsVersion '26.0.1'

  defaultConfig {
    applicationId 'com.eatpurely.driverapp'
    targetSdkVersion 25
    versionCode 1
    versionName '1.0.0'
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    // Deprecated. Used by net.openid:appauth
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'host.exp.exponent'
    ]
  }
  dexOptions {
    javaMaxHeapSize System.getenv("DISABLE_DEX_MAX_HEAP") ? null : "8g"
  }
  flavorDimensions "tier"
  productFlavors {
    // Define separate dev and prod product flavors.
    dev {
      // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
      // to pre-dex each module and produce an APK that can be tested on
      // Android Lollipop without time consuming dex merging processes.
      minSdkVersion 21
      dimension "tier"
    }
    devRemoteKernel {
      minSdkVersion 21
      dimension "tier"
    }
    dev19 {
      // For debugging / development on older SDK versions. Increases build
      // time so use 'dev' if not running on older SDKs.
      minSdkVersion 19
      dimension "tier"
    }
    prod {
      // The actual minSdkVersion for the application.
      minSdkVersion 19
      dimension "tier"
    }
  }
  buildTypes {
    debug {
      debuggable true
    }
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      zipAlignEnabled true
    }
  }
  signingConfigs {
    debug {
      storeFile file('../debug.keystore')
    }
  }
  lintOptions {
    abortOnError false
  }
}

// Don't use modern jsc-android since it still has some critical bugs that
// crash applications when the string for the JS bundle is loaded and when
// locale-specific date functions are called.
// configurations.all {
//   resolutionStrategy {
//     force 'org.webkit:android-jsc:r216113'
//   }
// }


task exponentPrebuildStep(type: Exec) {
  workingDir '../'
  if (System.getProperty('os.name').toLowerCase().contains('windows')) {
    commandLine 'cmd', '/c', '.\\detach-scripts\\prepare-detached-build.bat'
  } else {
    commandLine './detach-scripts/prepare-detached-build.sh'
  }
}
preBuild.dependsOn exponentPrebuildStep


dependencies {
  implementation( project(':react-native-background-geolocation')){
    exclude group: 'com.google.android.gms'
  }
  compile(name: 'tslocationmanager', ext: 'aar')

  implementation project(':react-native-vector-icons')
  implementation project(':react-native-check-app-install')
  compile fileTree(dir: 'libs', include: ['*.jar'])

  compile 'com.android.support:multidex:1.0.1'

  // Our dependencies
  compile 'com.android.support:appcompat-v7:26.0.1'

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  compile 'com.android.support:appcompat-v7:26.0.1'
  compile 'com.facebook.android:facebook-android-sdk:4.7.0'
  compile('com.facebook.android:audience-network-sdk:4.22.1') {
    exclude module: 'play-services-ads'
  }
  provided 'org.glassfish:javax.annotation:3.1.1'
  annotationProcessor 'com.jakewharton:butterknife:7.0.1'
  compile 'com.jakewharton:butterknife:7.0.1'
  compile 'de.greenrobot:eventbus:2.4.0'
  compile 'com.amplitude:android-sdk:2.9.2' // Be careful when upgrading! Upgrading might break experience scoping. Check with Jesse. See Analytics.resetAmplitudeDatabaseHelper
  compile 'com.squareup.picasso:picasso:2.5.2'
  compile 'com.google.android.gms:play-services-gcm:11.8.0'
  compile 'com.google.android.gms:play-services-analytics:11.8.0'
  compile 'com.google.android.gms:play-services-maps:11.8.0'
  compile 'com.google.android.gms:play-services-auth:11.8.0'
  compile 'com.google.android.gms:play-services-location:11.8.0'
  compile 'com.google.android.gms:play-services-ads:11.8.0'
  annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
  compile "com.raizlabs.android:DBFlow-Core:2.2.1"
  compile "com.raizlabs.android:DBFlow:2.2.1"
  compile "com.madgag.spongycastle:core:1.53.0.0"
  compile "com.madgag.spongycastle:prov:1.53.0.0"
  debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  // debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
  releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  compile 'com.facebook.device.yearclass:yearclass:1.0.1'
  compile 'commons-io:commons-io:1.3.2'
  compile 'me.leolin:ShortcutBadger:1.1.4@aar'
  compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
  compile 'com.theartofdev.edmodo:android-image-cropper:2.4.7'
  compile 'com.yqritc:android-scalablevideoview:1.0.1'
  compile 'commons-codec:commons-codec:1.10'
  compile 'com.segment.analytics.android:analytics:4.3.0'
  compile 'com.google.zxing:core:3.2.1'
  compile 'net.openid:appauth:0.4.1'
  compile 'com.airbnb.android:lottie:2.2.0'
  compile 'io.branch.sdk.android:library:2.6.1'
  compile('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  compile 'com.android.support:exifinterface:26.0.1'
  compile 'com.squareup.okhttp3:okhttp:3.4.1'
  compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
  compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
  compile 'com.squareup.okio:okio:1.9.0'

  // Testing
  androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
  // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
  androidTestCompile 'com.android.support.test:runner:1.0.1'
  androidTestCompile 'com.android.support:support-annotations:26.0.1'
  androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
  androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
  androidTestCompile 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'



  compile('host.exp.exponent:expoview:25.0.0@aar') {
    transitive = true
  }


}

// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'

I know there are a lot of dependencies, but that is because this is an Expo react native project. My project worked fine before adding the library and then when I added the library I ran into issues. I have tried a few things to try and fix it because I have seen this issue many places when I googled it:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDev19Debug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

A more detailed crash error:

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzagm;

lucidtheory avatar Mar 01 '18 15:03 lucidtheory

First-of-all, you have appcompat-v7 imported twice:

// Our dependencies
  compile 'com.android.support:appcompat-v7:26.0.1'

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  compile 'com.android.support:appcompat-v7:26.0.1'

It's not the reason for your problem, but it is a symptom of confusion in your dependencies.

christocracy avatar Mar 01 '18 16:03 christocracy

Thank you for that. It looks like it is an issue with google play services everywhere I search for this error:

Multiple dex files define Lcom/google/android/gms/internal/zzagm;

I see google play dependency errors mentioned. Is there a specific version of google play services used? I might be able to just change everything to that version?

lucidtheory avatar Mar 01 '18 16:03 lucidtheory

Yes, you've got some other component importing a different version of play-services.

$ cd android
$ ./gradlew app:dependencies

christocracy avatar Mar 01 '18 16:03 christocracy

It looks like my modules are importing 9.8.0, I changed it to 11.8.0 because I saw in the manual that the plugin needs 11.2.0 or greater though. Is this going to be an issue if I leave it at 9.8.0?

(the error goes away when I go back to 9.8.0)

lucidtheory avatar Mar 01 '18 16:03 lucidtheory

Do not even think about giving up and using 9.8.0. Do you know how old that version is? Google recommends to always use the latest version of play-services.

Using 9.8.0 is a cop-out.

christocracy avatar Mar 01 '18 17:03 christocracy

Ok, thank you so much for pointing me in the right direction. I will figure out a way to upgrade them then. I dont think this should be a ticket though since it's about my dependencies and not an issue with the library

lucidtheory avatar Mar 01 '18 17:03 lucidtheory

I don't like this idea of Expo. Doing anything outside their walled-garden seems way too complex. Easier just to drop Expo and go pure RN.

christocracy avatar Mar 01 '18 17:03 christocracy

I honestly may just have to do that.

lucidtheory avatar Mar 01 '18 17:03 lucidtheory