# Build errors on a previously working sketch

**URL:** <https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784>\
**Category:** Processing for Android\
**Created:** [October 18, 2019, 9:59pm UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784 "2019-10-18T21:59:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 18, 2019, 9:59pm UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784/1 "2019-10-18T21:59:44Z")

</div>

I was working on implementing ads into my sketch, then I started getting this error.

I have reverted the sketch back to its original state, but it’s still getting the new error.

full error at: [https://pastebin.com/j5AzNmuQ](https://pastebin.com/j5AzNmuQ)

```auto
org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.3-bin.zip'.

```

```auto
Caused by: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

```

```auto
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

```

```auto
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

```

```auto
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

```

```auto
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

```

```auto
Caused by: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

```

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

```

---

<div class="post-metadata">

**Author:** ![PhoenixStormJr](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@PhoenixStormJr](https://discourse.processing.org/u/PhoenixStormJr)\
**Post date:** [October 20, 2019, 3:49am UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784/2 "2019-10-20T03:49:05Z")

</div>

Paste your code so i might be able to run it and get it to work.

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 20, 2019, 4:09am UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784/3 "2019-10-20T04:09:26Z")

</div>

It’s quite long, I will get a pastebin together tomorrow

---

<div class="post-metadata">

**Author:** ![PhoenixStormJr](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@PhoenixStormJr](https://discourse.processing.org/u/PhoenixStormJr)\
**Post date:** [October 20, 2019, 5:41pm UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784/4 "2019-10-20T17:41:32Z")

</div>

That might be the problem. Sometimes if you copy over 10 mbs of code it has errors NOT caused by you. Probably a misspelled word. that happened to me

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 20, 2019, 6:40pm UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784/6 "2019-10-20T18:40:47Z")

</div>

I cant bring myself to share my entire sketch, as I am planning on releasing it on the play store.

When I implement this code into any of my pre-existing android sketches, it causes the errors mentioned above.  
But when I put it into a new sketch, it causes no errors, running fine.

```auto
import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;
import android.app.Activity;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.MobileAds;

public void setup() {
  fullScreen();
}

public void draw() {
  background(0);
}

@ Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //here you get the window
  Window window = getActivity().getWindow();
  RelativeLayout adsLayout = new RelativeLayout(this.getActivity());
  RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);
  AdView adView = new AdView(this.getActivity());
  adView.setAdSize(AdSize.SMART_BANNER);
  adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
  adsLayout.addView(adView);
  AdRequest newAdReq = new AdRequest.Builder()
    .build();
  adView.loadAd(newAdReq);
  window.addContentView(adsLayout, lp2);
};

```

It needs a few additional things to work:

- [this file](https://drive.google.com/file/d/1tcx5j_2gjurrGa44WDraunafkTZP0d-H/view?usp=sharing) to be placed in the `/sketch/code` folder to work
- `<meta-data android:name="com.google.android.gms.version" android:value="8298000"/>`  
in the `<application>` bit of the android manifest
- Permissions for:
  - network state
  - wifi state
  - internet
  - read phone state

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 20, 2019, 6:59pm UTC](https://discourse.processing.org/t/build-errors-on-a-previously-working-sketch/14784/7 "2019-10-20T18:59:08Z")

</div>

I may have figured something out.  
After exporting the project to android studio and doing the usual fixes required following that, I got this error:  
`Cannot fit requested classes in a single dex file (# methods: 68587 > 65536)`  
and somewhere else in the errors this:  
`The number of method references in a .dex file cannot exceed 64K.`

the solution to this normally according to [this stackoverflow](https://stackoverflow.com/questions/36785014/the-number-of-method-references-in-a-dex-file-cannot-exceed-64k-api-17) is to add ` multiDexEnabled true` in `build.gradle`

This worked but I want to continue working in processing for now.  
I will mark this as a solution and start a new topic for that.
