2017-03-02 88 views
2

我使用kotlin在Intellij Idea中實現了一個項目。這是沒有錯誤的工作。這是沒有錯誤Android工作室找不到java.math.BigInteger項目中的一些方法

enter image description here 我的IntelliJ項目的照片,但是當我執行Android Studio中這個項目中,我得到了錯誤,因爲該工作室找不到的BigInteger類

longValueExact()

這種方法

的Android Studio項目的照片:

enter image description here 我有一個JDK在我的電腦(v 1.8)。但在Itellij項目這個方法工作,並在android工作室沒有工作。

我打開在Android Studio中java.math.BigInteger中的類,看到longValueExact()方法:

enter image description here 科特林類:

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) 

這意味着我們在Java 1.8有這樣的班級,我們加入這在android工作室。和android工作室加載這個類與外部庫中的所有方法。但我們不能在項目類中使用這些方法!

任何人都可以幫助我嗎?

+1

請添加代碼,而不是附加圖像。 –

+0

我加了代碼 – b4hr4m

回答

2

Android有它自己的java.whatever類的實現,並且可以有不同的接口,特別是當涉及到在最近的Java版本中添加的東西時。在https://developer.android.com/reference/java/math/BigInteger.html你甚至可以看到最新的Android API(25)沒有這個方法。所以,如果你設法編譯程序,它將無法真正在設備上運行。

<1.8>外部庫不用於Android項目,如果您查看模塊依賴關係,則不應該看到它。

+0

有什麼辦法可以加這些類嗎? – b4hr4m

+1

我不這麼認爲。你可以在IDEA中查看該方法的源代碼,如果可以使用可用的方法(對於'longValueExact'),則可以自己實現相應的方法。 –

+0

非常感謝你 – b4hr4m

相關問題