sbugert / react-native-admob

A react-native component for Google AdMob banners
BSD 2-Clause "Simplified" License
1.13k stars 531 forks source link

Build Failed Multiple 'dex files define' #379

Open Batuhan-Akkaya opened 5 years ago

Batuhan-Akkaya commented 5 years ago

My project has not been working since last week. When i removed node_modules and 'npm i' my project crashed. Also i have been facing this issue in my other projects that contains 'admob' since last week. This error: `* What went wrong: Execution failed for task ':app:transformClassesWithDexForRelease'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/measurement/zzdz;` Note: I did try things in internet but i couldnt find a solution.

imran1992 commented 5 years ago

ReactNative v0.57.4

buildToolsVersion = "27.0.3"
minSdkVersion = 19
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"

same here...:(

kaelsooo commented 5 years ago

might be similar to an issue i recently encountered. i believe google released an update for com.google.android.gms:play-services-ads and it caused a conflict with the version in android\app\build.gradle

ERROR: `

Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED D8: Program type already present: com.google.android.gms.internal.measurement.zzfq

FAILURE: Build failed with an exception.

FIX: changed the version for com.google.android.gms:play-services-ads to my current build version in node_modules\react-native-admob\android\build.gradle

dependencies { compile 'com.facebook.react:react-native:+' compile 'com.google.android.gms:play-services-ads:+' } to dependencies { compile 'com.facebook.react:react-native:+' compile 'com.google.android.gms:play-services-ads:17.0.0' }

alternatively i believe it could also work if you update the version in android\app\build.gradle

implementation 'com.google.android.gms:play-services-ads:17.0.0' to implementation 'com.google.android.gms:play-services-ads:+'

imran1992 commented 5 years ago

dependencies { compile 'com.facebook.react:react-native:+' compile 'com.google.android.gms:play-services-ads:17.0.0' }

I tried You proposed Fix And Yes it complied and run. But On phone it just install amd message popup App has stopped.

My Android Device: 
Android 8.1
//==============================================================
My Project Specification:
"react": "16.6.1",
"react-native": "0.57.5",
"react-native-admob": "^2.0.0-beta.5"
//==============================================================
My Project's Android Specs:(MyProject/android/build.gradle)
  ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
//==============================================================
Admob's Android Specs:(react-native-admob/android/src/build.gradle)
compileSdkVersion 23
buildToolsVersion "23.0.1"
 defaultConfig {
   minSdkVersion 16
   targetSdkVersion 22
 }
dependencies { 
compile 'com.facebook.react:react-native:+' 
compile 'com.google.android.gms:play-services-ads:17.0.0' 
            }
dancork commented 5 years ago

@imran1992 I had same issue as you. Set it to 16.0.0 and the app now loads for me.

imran1992 commented 5 years ago

@dancork . Thanks Its running but didn't test it by putting ads in it. I just checked for empty project.

wanderbon commented 5 years ago

I tried You proposed Fix And Yes it complied and run. But On phone it just install amd message popup App has stopped.

You need follow this step:

Update your AndroidManifest.xml Add your AdMob App ID to your app's AndroidManifest.xml file by adding the tag shown below. You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="[ADMOB_APP_ID]"/>
    </application>
</manifest>

Also this solution worked with 17.1.0 Version Ads com.google.android.gms:play-services-ads:17.1.0

alekaka commented 5 years ago

Hello worked here

**android/gradle.properties**
android.enableAapt2=false <-add

**android/app/build.gradle**
android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        ....
        multiDexEnabled true  <- add 
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.4'   <- add 
    implementation 'com.google.firebase:firebase-ads:16.0.1'   <- add 
    compile (project(':react-native-admob')) {    <- add
        exclude group: 'com.google.android.gms'
    }
}