Skip to content

Commit

Permalink
[Android] Bump ndk/cmake/jdk version (trustwallet#1950)
Browse files Browse the repository at this point in the history
* bump ndk / cmake version
* use java 11
* use new sdkmanager
* fix path in test script
* Fix some warnings
* Fix test error
* move code to script
  • Loading branch information
hewigovens authored Jan 20, 2022
1 parent 3306b1a commit f3c8e13
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 54 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ on:
jobs:
build:

runs-on: macos-10.15
runs-on: macos-11

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Install system dependencies
run: brew install boost ninja
- name: Install Android Dependencies
run: |
$ANDROID_HOME/tools/bin/sdkmanager --verbose "cmake;3.10.2.4988404" "ndk;21.2.6472646"
$ANDROID_HOME/tools/bin/sdkmanager "system-images;android-26;google_apis;x86"
- name: Accept Licenses
run: echo -e "y\ny\ny\ny\ny\n" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
tools/install-android-dependencies
- name: Cache internal dependencies
id: internal_cache
uses: actions/[email protected]
Expand Down
8 changes: 4 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
ndkVersion '21.2.6472646'
compileSdkVersion 29
ndkVersion '23.1.7779620'
defaultConfig {
applicationId "com.trustwallet.core.app"
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -43,7 +43,7 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'android.arch.core:core-testing:1.1.1'

implementation 'io.grpc:grpc-protobuf:1.34.0'
implementation 'io.grpc:grpc-protobuf:1.43.2'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ package com.trustwallet.core.app.blockchains.oasis

import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.Numeric
import com.trustwallet.core.app.utils.toHexByteArray
import com.trustwallet.core.app.utils.toHexBytes
import com.trustwallet.core.app.utils.toHexBytesInByteString
import junit.framework.Assert.assertEquals
import org.junit.Test
import org.junit.Assert.assertEquals
import wallet.core.java.AnySigner
import wallet.core.jni.CoinType.OASIS
import wallet.core.jni.proto.Oasis
import wallet.core.jni.proto.Oasis.SigningOutput
import java.math.BigInteger

class TestOasisSigner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestAddress {
val pubkey = key.publicKeyEd25519
val address = AnyAddress(pubkey, CoinType.STELLAR)

assertEquals(pubkey.data().toHex(), "0x09A966BCAACC103E38896BAAE3F8C2F06C21FD47DD4F864FF0D33F9819DF5CA2".toLowerCase())
assertEquals(pubkey.data().toHex(), "0x09A966BCAACC103E38896BAAE3F8C2F06C21FD47DD4F864FF0D33F9819DF5CA2".lowercase())
assertEquals(address.description(), "GAE2SZV4VLGBAPRYRFV2VY7YYLYGYIP5I7OU7BSP6DJT7GAZ35OKFDYI")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestAddress {
val pubkey = key.publicKeyCurve25519
val address = AnyAddress(pubkey, CoinType.WAVES)

assertEquals(pubkey.data().toHex(), "0x559a50cb45a9a8e8d4f83295c354725990164d10bb505275d1a3086c08fb935d".toLowerCase())
assertEquals(pubkey.data().toHex(), "0x559a50cb45a9a8e8d4f83295c354725990164d10bb505275d1a3086c08fb935d".lowercase())
assertEquals(address.description(), "3P2uzAzX9XTu1t32GkWw68YFFLwtapWvDds")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@ class TestData {
assertEquals(Numeric.toHexString(data), "0x01020304")
}

@Test
fun testUsingExtensions() {
{
val data = "01020304".toHexBytes()
assertEquals(data.toHex(), "0x01020304")
}
{ // with prefix
val data = "0x01020304".toHexBytes()
assertEquals(data.toHex(), "0x01020304")
}
val data = "01020304".toHexBytes()
assertEquals(data.toHex(), "0x01020304")

// with prefix
val data2 = "0x01020304".toHexBytes()
assertEquals(data2.toHex(), "0x01020304")
}

@Test
fun testOddLength() {
{
val data = "0x0".toHexBytes()
assertEquals(data.toHex(), "0x00")
}
{
val data = "0x28fa6ae00".toHexBytes()
assertEquals(data.toHex(), "0x28fa6ae00")
}
val data = "0x0".toHexBytes()
assertEquals(data.toHex(), "0x00")

val data2 = "0x28fa6ae00".toHexBytes()
assertEquals(data2.toHex(), "0x028fa6ae00")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class TestPrivateKey {
@Test
fun testGetSharedKey() {
val privateKeyData = "9cd3b16e10bd574fed3743d8e0de0b7b4e6c69f3245ab5a168ef010d22bfefa0".toHexBytes()
val privateKey = PrivateKey(privateKeyData)!!
val privateKey = PrivateKey(privateKeyData)

val publicKeyData = "02a18a98316b5f52596e75bfa5ca9fa9912edd0c989b86b73d41bb64c9c6adb992".toHexBytes()
val publicKey = PublicKey(publicKeyData, PublicKeyType.SECP256K1)!!
val publicKey = PublicKey(publicKeyData, PublicKeyType.SECP256K1)

val derivedData = privateKey.getSharedKey(publicKey, Curve.SECP256K1)
assertNotNull(derivedData)
Expand All @@ -83,10 +83,10 @@ class TestPrivateKey {
@Test
fun testGetSharedKeyWycherproof() {
val privateKeyData = "f4b7ff7cccc98813a69fae3df222bfe3f4e28f764bf91b4a10d8096ce446b254".toHexBytes()
val privateKey = PrivateKey(privateKeyData)!!
val privateKey = PrivateKey(privateKeyData)

val publicKeyData = "02d8096af8a11e0b80037e1ee68246b5dcbb0aeb1cf1244fd767db80f3fa27da2b".toHexBytes()
val publicKey = PublicKey(publicKeyData, PublicKeyType.SECP256K1)!!
val publicKey = PublicKey(publicKeyData, PublicKeyType.SECP256K1)

val derivedData = privateKey.getSharedKey(publicKey, Curve.SECP256K1)
assertNotNull(derivedData)
Expand All @@ -97,11 +97,11 @@ class TestPrivateKey {
@Test
fun testGetSharedKeyBidirectional() {
val privateKeyData1 = "9cd3b16e10bd574fed3743d8e0de0b7b4e6c69f3245ab5a168ef010d22bfefa0".toHexBytes()
val privateKey1 = PrivateKey(privateKeyData1)!!
val privateKey1 = PrivateKey(privateKeyData1)
val publicKey1 = privateKey1.getPublicKeySecp256k1(true)

val privateKeyData2 = "ef2cf705af8714b35c0855030f358f2bee356ff3579cea2607b2025d80133c3a".toHexBytes()
val privateKey2 = PrivateKey(privateKeyData2)!!
val privateKey2 = PrivateKey(privateKeyData2)
val publicKey2 = privateKey2.getPublicKeySecp256k1(true)

val derivedData1 = privateKey1.getSharedKey(publicKey2, Curve.SECP256K1)
Expand All @@ -116,10 +116,10 @@ class TestPrivateKey {
@Test
fun testGetSharedKeyError() {
val privateKeyData = "9cd3b16e10bd574fed3743d8e0de0b7b4e6c69f3245ab5a168ef010d22bfefa0".toHexBytes()
val privateKey = PrivateKey(privateKeyData)!!
val privateKey = PrivateKey(privateKeyData)

val publicKeyData = "02a18a98316b5f52596e75bfa5ca9fa9912edd0c989b86b73d41bb64c9c6adb992".toHexBytes()
val publicKey = PublicKey(publicKeyData, PublicKeyType.SECP256K1)!!
val publicKey = PublicKey(publicKeyData, PublicKeyType.SECP256K1)

val derivedData = privateKey.getSharedKey(publicKey, Curve.ED25519)
assertNull(derivedData)
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.21'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
Expand All @@ -10,7 +10,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
Expand Down
6 changes: 3 additions & 3 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 16 12:35:47 JST 2021
#Wed Jan 19 18:01:57 JST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
6 changes: 3 additions & 3 deletions android/trustwalletcore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'maven-publish'
group='com.github.trustwallet'

android {
compileSdkVersion 28
ndkVersion '21.2.6472646'
compileSdkVersion 29
ndkVersion '23.1.7779620'
defaultConfig {
minSdkVersion 23
targetSdkVersion 29
Expand Down Expand Up @@ -41,7 +41,7 @@ android {

externalNativeBuild {
cmake {
version "3.10.2"
version "3.18.1"
path "../../CMakeLists.txt"
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Ethereum/RLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ RLP::DecodedItem RLP::decode(const Data& input) {
}
if (prefix <= 0xbf) {
// b8--bf: long string
auto lenOfStrLen = prefix - 0xb7;
auto strLen = parseVarInt(lenOfStrLen, input, 1);
auto lenOfStrLen = size_t(prefix - 0xb7);
auto strLen = static_cast<size_t>(parseVarInt(lenOfStrLen, input, 1));
if (inputLen < lenOfStrLen || inputLen < (1 + lenOfStrLen + strLen)) {
throw std::invalid_argument(std::string("Invalid rlp encoding length, length ") + std::to_string(strLen));
}
Expand All @@ -157,7 +157,7 @@ RLP::DecodedItem RLP::decode(const Data& input) {
}
if (prefix <= 0xf7) {
// c0--f7: a list between 0-55 bytes long
auto listLen = prefix - 0xc0;
auto listLen = size_t(prefix - 0xc0);
if (inputLen < (1 + listLen)) {
throw std::invalid_argument(std::string("Invalid rlp string length, length ") + std::to_string(listLen));
}
Expand All @@ -176,8 +176,8 @@ RLP::DecodedItem RLP::decode(const Data& input) {
return item;
}
// f8--ff
auto lenOfListLen = prefix - 0xf7;
auto listLen = parseVarInt(lenOfListLen, input, 1);
auto lenOfListLen = size_t(prefix - 0xf7);
auto listLen = static_cast<size_t>(parseVarInt(lenOfListLen, input, 1));
if (listLen < 56) {
throw std::invalid_argument("length below 56 must be encoded in one byte");
}
Expand Down
2 changes: 1 addition & 1 deletion tools/android-test
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SERIAL=emulator-${PORT}

# We have to echo "no" because it will ask us if we want to use a custom hardware profile, and we don't.
echo -e "\nCreating Android emulator...\n"
echo "no" | "$ANDROID_HOME/tools/bin/avdmanager" create avd \
echo "no" | "$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager" create avd \
-n "${AVD_NAME}" \
-k "system-images;android-26;google_apis;x86" \
-f
Expand Down
8 changes: 8 additions & 0 deletions tools/install-android-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --verbose "cmake;3.18.1" "ndk;23.1.7779620"
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-26;google_apis;x86"

echo -e "y\ny\ny\ny\ny\n" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses

0 comments on commit f3c8e13

Please sign in to comment.