0

So I am trying to use Tensorflow-lite version 0.1.1.

But when I add the library in the gradle dependencies I get:

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define LR;

I am using AGP 3.1.0-alpha5, but I also get errors (different ones) in alpha06, alpha07...I am using multidex, but it is correctly set and works without tensorflow.

I tried to remove D8 (this thing here) and change the gradle wrapper version... but still no luck.

I don't really understand what this error means, so could someone explain what Multiple dex files define LR means? Or give some solution?

Edit 1:

I am more interested about what is the class/file LR. I do understand that a class is defined twice in my dex files, but I don't understand what this class is about. So it get a lot harder to solve the problem.

Any help is appreciated!

Leandro Borges Ferreira
  • 12,422
  • 10
  • 53
  • 73
  • LR is the duplicated class. What that in effect is varies between code, but it is effectively a dupe of that question ^ – Zoe Jan 08 '18 at 16:23
  • Hello Zoe, thanks for the help. Although those questions are very similar, I believe my question has some particularities. The problem in the other question could be solved by simply setting Multidex in the app, but in my case the Mutlidex is already set. Also the exception is different (DexException vs ProcessException) – Leandro Borges Ferreira Jan 08 '18 at 16:31
  • You know the NPE question that most NPE questions are marked as a dupe of, right? The stacktraces don't need to match 100% – Zoe Jan 08 '18 at 16:33
  • For "LR;", it's resource class 'R' without package name. In the dex file, the initial L and ending ; are decorations. – Isabella Chen Jan 18 '18 at 17:20
  • That was exactly the problem, Isabella. Tensorflow lite didn't have any package. If you post an asnwer, I can accept it – Leandro Borges Ferreira Jan 18 '18 at 17:23

1 Answers1

1

This error is caused when you have a duplicate namespace.classname compiled into your code base.

This is typically caused by duplicating a dependency. Often times the culprit is a "transitive dependency" aka a dependency of a dependency.

You can look at your gradle android resource tree to find the culprit. Then use transitive = false on the dependency that included it.

If you need to remove just part of the transitive dependencies of that child dependency then use exclude instead. There are plenty of examples of how to do this.

I believe there is also a gradle flag to say "use latest" and screw the rest, but this is bad, you should be intentional with your versions. Hope that helps

Sam
  • 5,342
  • 1
  • 23
  • 39