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: https://pastebin.com/j5AzNmuQ

org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.3-bin.zip'.
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: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Caused by: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Caused by: com.android.dex.DexIndexOverflowException: 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;
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 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

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