10 Replies Latest reply on Oct 24, 2016 7:09 PM by naluz52240580

    Android gradle build error with Admob

    naluz52240580 Level 1
      In my project, I am using the cordova-admob plugin (the only plugin that I have added so far), and am trying to build using the Android platform on the Cordova CLI. Without the plugin, the app builds fine. However, when the plugin is added, the following error is produced:

       

      To run dex in process, the Gradle daemon needs a larger heap.

      It currently has approximately 910 MB.

      For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.

      To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.

      For more information see https://docs.gradle.org/current/userguide/build_environment.html

      Dex: 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

          UNEXPECTED TOP-LEVEL EXCEPTION:

      com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

              at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:495)

              at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)

              at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:504)

              at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)

              at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)

              at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)

              at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)

              at com.android.dx.command.dexer.Main.run(Main.java:277)

              at com.android.dx.command.dexer.Main.main(Main.java:245)

              at com.android.dx.command.Main.main(Main.java:106)

       

       

      :transformClassesWithDexForDebug FAILED

       

       

      BUILD FAILED

       

       

      Total time: 3 mins 9.915 secs

       

       

      FAILURE: Build failed with an exception.

       

       

      * What went wrong:

      Execution failed for task ':transformClassesWithDexForDebug'.

      > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 2

       

       

      * Try:

      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

      Error: cmd: Command failed with exit code 1 Error output:

      Dex: 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

          UNEXPECTED TOP-LEVEL EXCEPTION:

      com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

              at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:495)

              at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)

              at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:504)

              at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)

              at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)

              at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)

              at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)

              at com.android.dx.command.dexer.Main.run(Main.java:277)

              at com.android.dx.command.dexer.Main.main(Main.java:245)

              at com.android.dx.command.Main.main(Main.java:106)

       

       

       

       

      FAILURE: Build failed with an exception.

       

       

      * What went wrong:

      Execution failed for task ':transformClassesWithDexForDebug'.

      > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 2

       

       

      * Try:

      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

      Any thoughts? I know that the problem is something with the gradle heap size, but I don't know how phonegap handles gradle. Any help appreciated!
        • 1. Re: Android gradle build error with Admob
          simon.macdonald Adobe Employee

          Yeah, this bug will be fixed in cordova-android 5.3.0 but in the meantime here is a work around for you.

           

          Edit the file $HOME/.grade/gradle.properties and add the following line:

           

               org.gradle.jvmargs=-Xmx2048m

           

          This should get your build going.

          • 2. Re: Android gradle build error with Admob
            naluz52240580 Level 1

            Sorry, this might be a noob question, but what is $HOME? For me when I do <Phonegap Project Name>/platforms/android/.gradle I only get a folder called 2.13, which does not contain gradle.properties either.

            • 3. Re: Android gradle build error with Admob
              simon.macdonald Adobe Employee

              $HOME is your home directory. On Mac/Linux it would be /home/username on Windows the path is dependent on the OS version but should be accessible by %USERPROFILE%. Basically you just need to edit a file in your user directory not the project directory.

              • 4. Re: Android gradle build error with Admob
                naluz52240580 Level 1

                I can't seem to find the gradle.properties file in .gradle. I am navigated to the Users/NaluZou/.gradle directory. There wasn't a gradle.properties text file, so I added a new text file named "gradle.properties" and put: org.gradle.jvmargs=-Xmx2048M; in the text file. It is still failing to build, but this time the error says that "XML document structures must start and end within the same entity". Where did I go wrong? Thanks in advance.

                • 5. Re: Android gradle build error with Admob
                  naluz52240580 Level 1

                  Sorry for the inconvenience, but can you lead me through the process of configuring gradle.properties? I've searched the web on how to make the gradle properties work, because every time I add the gradle.properties with org.gradle.jvmargs=-Xmx2048M; (gradle.properties does not exist so I created a new blank .properties file with only this line inside) there is this error message:

                   

                   

                  Error: cmd: Command failed with exit code 1 Error output:

                  FAILURE: Build failed with an exception.

                   

                   

                  * What went wrong:

                  Unable to start the daemon process.

                  This problem might be caused by incorrect configuration of the daemon.

                  For example, an unrecognized jvm option is used.

                  Please refer to the user guide chapter on the daemon at https://docs.gradle.org/2.13/userguide/gradle_daemon.html

                  Please read the following process output to find out more:

                  -----------------------

                  Error: Could not create the Java Virtual Machine.

                  Error: A fatal exception has occurred. Program will exit.

                  Invalid maximum heap size: -Xmx2048M;

                   

                   

                   

                   

                  * Try:

                  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

                   

                  Thanks in advance!

                  • 6. Re: Android gradle build error with Admob
                    simon.macdonald Adobe Employee

                    Remove the ; from the end of the line you added to gradle.properties.

                    1 person found this helpful
                    • 7. Re: Android gradle build error with Admob
                      naluz52240580 Level 1

                      I created a new empty phonegap project, ran "cordova plugin add cordova-admob" on the cordova CLI, created a new properties file called "gradle" and put in the required line, but the error persists: 

                       

                      BUILD FAILED

                       

                       

                      Total time: 1 mins 57.451 secs

                      FAILURE: Build failed with an exception.

                       

                       

                      * What went wrong:

                      Execution failed for task ':transformClassesWithDexForDebug'.

                      > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

                       

                       

                      * Try:

                      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

                      Error: cmd: Command failed with exit code 1 Error output:

                      FAILURE: Build failed with an exception.

                       

                       

                      * What went wrong:

                      Execution failed for task ':transformClassesWithDexForDebug'.

                      > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

                       

                       

                      * Try:

                      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

                       

                      Could this be an issue with the plugin? Am I using the right plugin?

                      Thanks in advance for all the help you've given

                      • 8. Re: Android gradle build error with Admob
                        simon.macdonald Adobe Employee

                        Okay, if you have properly created the file /Users/NaluZou/.gradle/gradle.properties and added the line I suggested then the issue with running our of memory while building should be fixed. Based upon the log you've posted that problem is fixed but you now have a new problem. Now you are using two many methods for Android.

                        Try adding this plugin GitHub - jwall149/cordova-multidex: Add multidex to cordova application  to you app and seeing if the last error finally goes away.

                        1 person found this helpful
                        • 9. Re: Android gradle build error with Admob
                          naluz52240580 Level 1

                          I figured out the solution! Thank you so much for your time and help, I truly appreciate it! Good luck with your projects

                          • 10. Re: Android gradle build error with Admob
                            naluz52240580 Level 1

                            For future reference and for anyone who is facing a similar problem, I finally solved the problem by installing cordova admob simple. It is much smaller, so there is no overflow in gradle.