oney / react-native-gcm-android

GCM for React Native Android
MIT License
172 stars 76 forks source link

Unable to Build #2

Closed ryanmcdermott closed 8 years ago

ryanmcdermott commented 8 years ago

I've been seeing this error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

Have you encountered this? The solutions on StackOverflow haven't seem to resolve it. http://stackoverflow.com/questions/26342444/multiple-dex-files-define-landroid-support-annotation-animres

oney commented 8 years ago

In android/app/build.gradle

android {
   ...
    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        ...
        multiDexEnabled true
    }

Please try adding these lines, may resolve the problem.

oney commented 8 years ago

Other lines in my android/app/build.gradle

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:0.14.+"
   ...
ryanmcdermott commented 8 years ago

Thanks that worked! Throw that in the README

oney commented 8 years ago

Good! Will do.

ghost commented 8 years ago

As multiDexEnable true is not recommended solution, maybe it would be better if changed the dependency from whole compile 'com.google.android.gms:play-services:8.1.0' to just the subset compile 'com.google.android.gms:play-services-gcm:8.1.0'. In my settings, it builds when you additionally add compile 'com.android.support:mediarouter-v7:23.0.+' to build.gradle of this project.

nabati commented 8 years ago

Let me just add an additional piece here; I had the same issue as above and despite a lot of tinkering, I still got the same error.

What worked for me was to delete the android/app/build folder after changing any of my *.gradle files.

jawadrehman commented 8 years ago

if any of you has this issue, then do this cd android ./gradlew clean

lynndylanhurley commented 8 years ago

@herby - what is the issue with using multiDexEnable true? That is the only way I can get my app to build with this package.

jiw0220 commented 8 years ago

https://facebook.github.io/react-native/docs/android-building-from-source.html --> 4. Making 3rd-party modules use your fork

If you use 3rd-party React Native modules, you need to override their dependencies so that they don't bundle the pre-compiled library. Otherwise you'll get an error while compiling - Error: more than one library with package name 'com.facebook.react'.

Modify your android/app/build.gradle and replace compile project(':react-native-custom-module') with:

compile(project(':react-native-custom-module')) { exclude group: 'com.facebook.react', module: 'react-native' }

After run command

cd android

./gradlew clean