invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.71k stars 2.22k forks source link

React native crash when adding @react-native-firebase/admob on Android #3412

Closed RafilAlArs closed 4 years ago

RafilAlArs commented 4 years ago

Please help with this issue, I am trying to add Admob on the project but always get crash when run npx react-native run android if I remove admob package the application build again with no error my package.json

"dependencies": { "@react-native-community/async-storage": "^1.8.1", "@react-native-community/geolocation": "^2.0.2", "@react-native-community/masked-view": "^0.1.7", "@react-native-community/slider": "^2.0.9", "@react-native-firebase/admob": "^6.4.0", "@react-native-firebase/app": "^6.4.0", "@react-navigation/bottom-tabs": "^5.2.5", "@react-navigation/native": "^5.1.3", "@react-navigation/stack": "^5.2.9", "moment": "^2.24.0", "react": "16.11.0", "react-native": "0.62.0", "react-native-geocoder": "^0.5.0", "react-native-gesture-handler": "^1.6.1", "react-native-maps": "0.27.1", "react-native-reanimated": "^1.7.1", "react-native-safe-area-context": "^0.7.3", "react-native-screens": "^2.4.0", "react-native-size-matters": "^0.3.0" } I follow the instruction and I added firebase.json on the root of the project. please note that firebase/app is working and log analytics perfectly.

Errors that I got....

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 D8: Cannot fit requested classes in a single dex file (# methods: 83489 > 65536 ; # fields: 79523 > 65536) com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131) at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:118) at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102) at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:444) at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:335) at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50) at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:50) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:65) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:61) at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61) at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44) at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41) at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416) at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406) at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36) at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41) at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:53) at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:217) at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:212) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56) at java.lang.Thread.run(Thread.java:748) Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete at com.android.tools.r8.utils.t.a(:55) at com.android.tools.r8.D8.run(:11) at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:116) ... 34 more Caused by: com.android.tools.r8.utils.AbortException: Error: null, Cannot fit requested classes in a single dex file (# methods: 83489 > 65536 ; # fields: 79523 > 65536) at com.android.tools.r8.utils.Reporter.a(:21) at com.android.tools.r8.utils.Reporter.a(:7) at com.android.tools.r8.dex.VirtualFile.a(:33) at com.android.tools.r8.dex.VirtualFile$h.a(:5) at com.android.tools.r8.dex.ApplicationWriter.a(:13) at com.android.tools.r8.dex.ApplicationWriter.write(:35) at com.android.tools.r8.D8.d(:44) at com.android.tools.r8.D8.b(:1) at com.android.tools.r8.utils.t.a(:23) ... 36 more

FAILURE: Build failed with an exception.

mikehardy commented 4 years ago

Hi there! You're missing multidex support. This script shows how to do it: https://github.com/mikehardy/rnfbdemo/blob/master/make-demo-v6.sh#L124

In fact, that script will also build a full throwaway react-native-firebase app with admob integrated and it runs when it's done - just clone the repo and try it, reading the script comments to follow along with what it's doing

RafilAlArs commented 4 years ago

I solve this issue by enable multidex and everything went good.

defaultConfig { applicationId "com.RafilAlArs.ShiaPrayerTimes" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 4 versionName "4.0" // added for admob problem multiDexEnabled true //Add this line app/build/gradle }

and in app/build/gradle dependencies section add this line implementation "androidx.multidex:multidex:2.0.1"

also you need to replace this line in MainApplication.java public class MainApplication extends Application implements ReactApplication { // remove this public class MainApplication extends MultiDexApplication implements ReactApplication { // add this instead

that's it.

RafilAlArs commented 4 years ago

Thank you Mike Hardy for reaching out, I really appreciate your answer but I preferred to do 3 of very simple steps that I can understand them easily over running script I did not know what exactly would do. Best Regards Rafil Al Ars

On Wed, Apr 8, 2020 at 4:05 AM Mike Hardy notifications@github.com wrote:

Hi there! You're missing multidex support. This script shows how to do it: https://github.com/mikehardy/rnfbdemo/blob/master/make-demo-v6.sh#L124

In fact, that script will also build a full throwaway react-native-firebase app with admob integrated and it runs when it's done

  • just clone the repo and try it, reading the script comments to follow along with what it's doing

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/invertase/react-native-firebase/issues/3412#issuecomment-610726001, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCOM62PZASMUWQC3ISQXZTRLPSWJANCNFSM4MDR6WFQ .