Exclude java class from lib replaced by own class to avoid duplicate

(Jeffrey Riaboy) #1

In Android Studio, there is a specific file (src/org/luaj/vm2/lib/jse/JavaMethod.java) that I need to overwrite from a package that is pulled in via Gradle (dependencies {compile ‘org.luaj:luaj-jse:3.0.1’}).

I copied the file into my source directory with the exact same path and made my changes to it. This was working fine for an individual JUnit test case that was using it. It also works fine for a normal android API v23 compile of my project.

However, when I try to run the project via the android emulator running API v16 or API v19 OR run all my tests at once via a configuration of ProjectType=“Android Tests”, I get Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lorg/luaj/vm2/lib/jse/JavaMethod$Overload;.

Is there a specific task or command that I need to add to my Gradle file to make sure the project selects the file in my local source directory? I tried the Copy task and the sourceSets->main->java->exclude command, but neither seemed to work (I may have done them wrong). I also tried the “exclude module/group” directive under “compile” from this post.

The non-default settings for the Run/Debug Confirmation:

  • Type=Android Tests
  • Module=My module
  • Test: All in package
  • Package: “test”

All my JUnit test cases are in the “test” package.

I’m at my wits end trying to figure this one out :-\