3

I implements a project in Intellij Idea with kotlin . this is working without Error . this is my Intellij project photo without Error

enter image description here but when i implement this project in Android Studio , i got Error because the studio can not find this method in BigInteger class

longValueExact()

Android Studio project photo :

enter image description here I have one JDK in my computer (v 1.8) . but in Itellij project this method worked and in android studio not worked.

i opened java.math.BigInteger class in android studio and saw longValueExact() method :

enter image description here kotlin class :

open class AuthKey(val key: ByteArray) {

constructor(key: ByteBuffer) : this(key.array())

init {
    if (key.size != 256)
        throw RuntimeException("AuthKey must be 256 Bytes found ${key.size} bytes")
}

// see https://core.telegram.org/mtproto/description#key-identifier
// SHA1 generates 20 bytes long hash, authKeyId is the lower 8 bytes
val keyId = CryptoUtils.substring(CryptoUtils.SHA1(key), 12, 8)

fun getKeyIdAsLong() = BigInteger(keyId).longValueExact()
}

class TempAuthKey(key: ByteArray, val expiresAt: Int) : AuthKey(key)

it mean we have this class in java 1.8 and we added this in android studio . and android studio loading this class with all methods in external library . but we cant use these methods in project classes!

any one can help me ?

MrNadimi
  • 1,424
  • 4
  • 18
  • 33

1 Answers1

4

Android has its own implementation of java.whatever classes and can have different interfaces as well, especially when it comes to things added in recent Java versions. At https://developer.android.com/reference/java/math/BigInteger.html you can see even the latest Android API (25) doesn't have this method. So if you managed to compile the program, it would fail to actually run on the device.

The <1.8> external library is not used for Android projects, if you look in module dependencies you shouldn't see it.


UPDATE - This method and the other "value exact" methods were added to Android in API 31.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • there is any way to added these classes? – MrNadimi Mar 02 '17 at 09:59
  • 1
    I don't think so. You can look at the source of the method in IDEA and implement the equivalent yourself if it's possible using the available methods (for `longValueExact` it is). – Alexey Romanov Mar 02 '17 at 10:06
  • @AlexeyRomanov so android not implement all java 8 API even using target level 8 ? – Alessandro Scarozza Jul 26 '17 at 09:06
  • @Xan No, it doesn't. APIs available in Android don't and can't depend on language level you set, they depend on `compileSdkVersion`. See https://stackoverflow.com/questions/26694108/what-is-the-difference-between-compilesdkversion-and-targetsdkversion for more. – Alexey Romanov Jul 26 '17 at 12:53