Build errors on a previously working sketch

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:

org.gradle.tooling.BuildException: Could not execute build using Gradle distribution ''.
Caused by: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to merge dex
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Unable to merge dex
Caused by: java.lang.RuntimeException: Unable to merge dex
Caused by: Unable to merge dex
Caused by: method ID not in [0, 0xffff]: 65536

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

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

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

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.

import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;

public void setup() {

public void draw() {

@ Override
  public void onCreate(Bundle 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());
  AdRequest newAdReq = new AdRequest.Builder()
  window.addContentView(adsLayout, lp2);

It needs a few additional things to work:

  • this file to be placed in the /sketch/code folder to work
  • <meta-data android:name="" android:value="8298000"/>
    in the <application> bit of the android manifest
  • Permissions for:
    • network state
    • wifi state
    • internet
    • read phone state

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 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.

1 Like