I have recently upgraded the Android build tools I use to build an app from 19.1.0 to 21.0.2. The app compiles, but when I start it I get this error:
net.i2p.and
I can't find the specific change in the build tools that surfaced the problem, but after looking at the answer to a different Dalvik problem, I figured out the error.
Dalvik rejects Ed25519FieldElement.multiply() because it contains 155 local variables. This method was directly ported from corresponding C code, and does not translate well into Java bytecode. It would seem that between 19.1.0 and 21.0.+, the compiler in the build tools was changed in a way that prevents Dalvik from handling this many local variables.
The last post on this page provides some additional insight:
Yep, the Dalvik compiler attempts to assign a "register" to every local variable in the method. It should be able to handle that many, but apparently can't. By making them instance variables you remove the compiler's need/desire to "manage" them (and also make the method a fair amount smaller).
My solution was to remove twenty unnecessary variables (the no-op assignments like g0 = g[0]
), and instead using the arrays directly. This does increase the likelihood of a future bug creeping into the code (if one of the array indices is changed accidentally), but reducing the number of local variables to 135 resolved the runtime class rejection.
The "correct" solution would be to refactor the method entirely to reduce its length. This must be done with care, to avoid introducing side-channel attack vectors.