L
L
lovesuper2015-01-22 21:01:09
Java
lovesuper, 2015-01-22 21:01:09

Android. Why is a strange error reported in the application's runtime?

It was necessary to include a library for working with the BitTorrent protocol into the project. I work on Android Studio 1.0.2 (osx), JDK8. I connected the ttorrent: 1.4 maven repository via gradle and just started to enjoy life, when an amazing error arose inside ttorrent:

java.lang.NoSuchMethodError: No static method encodeHex([BZ)[C in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of 'org.apache.commons.codec.binary.Hex' appears in /system/framework/ext.jar)

I went to look at the source codes of the dependency library org.apache.commons.codec (where ttorrent goes for Hex) to which the studio refers, my "not found" method looks at me there. I have a template break: there is a method in the source code of the library (available, all the cases), and runtime swears that there is no such method. How can this be? And what are you supposed to do? UPD: I tried to connect another library - jBittorrentAPI, there is the same story. When trying to execute a hex, it fails with the same error. What is wrong with my environment?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lovesuper, 2015-01-24
@lovesuper

Actually the solution turned out to be more complicated than I thought. So, let's start with the fact that I came across an article on the Internet Dieser Beitrag, from which it is clear that I was not the only one who had similar problems. The whole point turned out to be that within the Android operating system itself there are ALREADY some libraries that have a higher usage priority than those loaded with dependencies along with the application. Among them is my org.apache.commons.codec. Yes, yes, things like that. There are two ways to solve the problem, either download the libraries you need and use the builder to rename the project (for example, org.apache.commons.codec to org.apache.commons.codec.android), build a .jar nickname from it, include it in project and import the necessary classes in the code only from "our" library, or simply pull the necessary class into your project and not drag unnecessary megabytes of code along with you. However, that's exactly what I did.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question