Skip to content

Commit

Permalink
[Android]: Add support for Android devices with 16kb page size (#4212)
Browse files Browse the repository at this point in the history
* [Android]: Add support for Android devices with 16kb page size

* Upgrade Android SDK to 35, NDK to 28

* [Android]: Update wallet-core-kotlin AGP, SDK and NDK

* Change CI internal cache

* MISC: agp and kgp version bumps (#4213)

* [CI]: Update gradle to 8.10.2

* MISC: specify java compatibility version

* MISC: remove expect-actual-classes warnings

* [Misc]: Fix C++ Android warnings

* [Misc]: Fix iOS KMP compile errors

* [Misc]: Fix Android and KMP Android compile errors

* [Misc]: Fix KMP JVM

* [Misc]: minor change

* [Misc]: Disable `[[maybe_unused]]` for KMP

---------

Co-authored-by: Egor Kurnikov <[email protected]>
  • Loading branch information
satoshiotomakan and eakurnikov authored Jan 16, 2025
1 parent ea602ba commit c465eb6
Show file tree
Hide file tree
Showing 48 changed files with 179 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}

- name: Install internal dependencies
run: tools/install-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}

- name: Install internal dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kotlin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}

- name: Install internal dependencies
run: tools/install-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-ci-sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}

- name: Install internal dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-sys-dependencies-linux') }}-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('tools/install-sys-dependencies-linux') }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}
- name: Install internal dependencies
run: |
tools/install-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-sampleapp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-sys-dependencies-linux') }}-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('tools/install-sys-dependencies-linux') }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}
- name: Install internal dependencies
run: |
tools/install-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wasm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/cache@v3
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-dependencies') }}
key: ${{ runner.os }}-${{ runner.arch }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}

- name: Install internal dependencies
run: tools/install-dependencies
Expand Down
8 changes: 6 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'kotlin-android'

android {
namespace 'com.trustwallet.core.app'
compileSdkVersion 32
ndkVersion '23.1.7779620'
compileSdk 35
ndkVersion '28.0.12674087'
defaultConfig {
applicationId "com.trustwallet.core.app"
minSdkVersion 23
Expand All @@ -25,6 +25,10 @@ android {
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '2.1.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath 'com.android.tools.build:gradle:8.8.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 11 additions & 8 deletions android/wallet-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@ group = 'com.trustwallet'

android {
namespace 'wallet.core'
compileSdkVersion 32
ndkVersion '23.1.7779620'
compileSdk 35
ndkVersion '28.0.12674087'
defaultConfig {
minSdkVersion 23
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
arguments "-DCMAKE_BUILD_TYPE=Release", "-DTW_UNITY_BUILD=ON"
}
}
}

lintOptions {
abortOnError false
disable 'InvalidPackage'
}

buildTypes {
release {
Expand Down Expand Up @@ -52,6 +46,15 @@ android {
withSourcesJar()
}
}
lint {
abortOnError false
disable 'InvalidPackage'
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion codegen/lib/templates/jni/compare_to.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% less = locals[:less] -%>
<% equal = locals[:equal] -%>
<% compareMethod = JNIHelper.compareMethod(entity) -%>
<%= render('jni/method_prototype.erb', { method: compareMethod }) %> {
<%= render('jni/method_prototype.erb', { method: compareMethod, maybe_unused: true }) %> {
<%= render('jni/instance_access.erb', { entity: entity }) %>
<%= render('jni/parameter_access.erb', { method: compareMethod }) -%>
<% if entity.struct? -%>
Expand Down
2 changes: 1 addition & 1 deletion codegen/lib/templates/jni/method.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% method = locals[:method] -%>
<%= render('jni/method_prototype.erb', { method: method }) %> {
<%= render('jni/method_prototype.erb', { method: method, maybe_unused: true }) %> {
<% if !method.static -%>
<%= render('jni/instance_access.erb', { entity: entity }) %>
<% end -%>
Expand Down
13 changes: 10 additions & 3 deletions codegen/lib/templates/jni/method_prototype.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<%
method = locals[:method]
maybe_unused = locals[:maybe_unused]

maybe_unused_str = ''
if maybe_unused
maybe_unused_str = '[[maybe_unused]] '
end

if method.static
parameters = 'jclass thisClass' + JNIHelper.parameters(method.parameters)
parameters = maybe_unused_str + 'jclass thisClass' + JNIHelper.parameters(method.parameters)
else
parameters = 'jobject thisObject' + JNIHelper.parameters(method.parameters.drop(1))
parameters = maybe_unused_str + 'jobject thisObject' + JNIHelper.parameters(method.parameters.drop(1))
end
-%>
<%= JNIHelper.type(method.return_type) %> JNICALL <%= JNIHelper.function_name(entity: entity, function: method) %>(JNIEnv *env, <%= parameters %>)<% -%>
<%= JNIHelper.type(method.return_type) %> JNICALL <%= JNIHelper.function_name(entity: entity, function: method) %>(<%= maybe_unused_str %>JNIEnv *env, <%= parameters %>)<% -%>
6 changes: 3 additions & 3 deletions codegen/lib/templates/jni_c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<%# Constructors -%>
<% entity.static_methods.each do |method| -%>
<% next unless method.name.start_with?('Create') -%>
jlong JNICALL <%= JNIHelper.function_name(entity: entity, function: method, native_prefix: true) %>(JNIEnv *env, jclass thisClass<%= JNIHelper.parameters(method.parameters) %>) {
jlong JNICALL <%= JNIHelper.function_name(entity: entity, function: method, native_prefix: true) %>([[maybe_unused]] JNIEnv *env, [[maybe_unused]] jclass thisClass<%= JNIHelper.parameters(method.parameters) %>) {
<%= render('jni/parameter_access.erb', { method: method }) -%>
struct TW<%= entity.name %> *instance = TW<%= entity.name %><%= method.name %>(<%= JNIHelper.arguments(method.parameters).join(', ') %>);
<%= render('jni/parameter_release.erb', { method: method }) -%>
Expand All @@ -31,15 +31,15 @@ jlong JNICALL <%= JNIHelper.function_name(entity: entity, function: method, nati
<%# Destructors -%>
<% entity.methods.each do |method| -%>
<% next unless method.name.start_with?('Delete') -%>
void JNICALL <%= JNIHelper.function_name(entity: entity, function: method, native_prefix: true) %>(JNIEnv *env, jclass thisClass, jlong handle) {
void JNICALL <%= JNIHelper.function_name(entity: entity, function: method, native_prefix: true) %>([[maybe_unused]] JNIEnv *env, [[maybe_unused]] jclass thisClass, jlong handle) {
TW<%= entity.name %>Delete((struct TW<%= entity.name %> *) handle);
}

<% end -%>
<%# Initializers -%>
<% entity.static_methods.each do |method| -%>
<% next unless method.name.start_with?('Init') -%>
jbyteArray JNICALL <%= JNIHelper.function_name(entity: entity, function: method) %>(JNIEnv *env, jclass thisClass<%= JNIHelper.parameters(method.parameters.drop(1)) %>) {
jbyteArray JNICALL <%= JNIHelper.function_name(entity: entity, function: method) %>(JNIEnv *env, [[maybe_unused]] jclass thisClass<%= JNIHelper.parameters(method.parameters.drop(1)) %>) {
jbyteArray array = (*env)->NewByteArray(env, sizeof(struct TW<%= entity.name %>));
jbyte* bytesBuffer = (*env)->GetByteArrayElements(env, array, NULL);
struct TW<%= entity.name %> *instance = (struct TW<%= entity.name %> *) bytesBuffer;
Expand Down
10 changes: 5 additions & 5 deletions codegen/lib/templates/jni_h.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ jbyteArray JNICALL <%= JNIHelper.function_name(entity: entity, function: method)
<%# Static property declarations -%>
<% entity.static_properties.each do |property| -%>
JNIEXPORT
<%= render('jni/method_prototype.erb', { method: property }) %>;
<%= render('jni/method_prototype.erb', { method: property, maybe_unused: false }) %>;

<% end -%>
<%# Static method declarations -%>
<% entity.static_methods.each do |method| -%>
<% next if method.name.start_with?('Create') || method.name.start_with?('Init') -%>
JNIEXPORT
<%= render('jni/method_prototype.erb', { method: method }) %>;
<%= render('jni/method_prototype.erb', { method: method, maybe_unused: false }) %>;

<% end -%>
<%# Property declarations -%>
<% entity.properties.each do |property| -%>
JNIEXPORT
<%= render('jni/method_prototype.erb', { method: property }) %>;
<%= render('jni/method_prototype.erb', { method: property, maybe_unused: false }) %>;

<% end -%>
<%# Method declarations -%>
<% entity.methods.each do |method| -%>
<% next if method.name.start_with?('Delete') -%>
JNIEXPORT
<%= render('jni/method_prototype.erb', { method: method }) %>;
<%= render('jni/method_prototype.erb', { method: method, maybe_unused: false }) %>;

<% end -%>
<% less = entity.static_methods.detect{ |i| i.name == 'Less' } -%>
<% equal = entity.static_methods.detect{ |i| i.name == 'Equal' } -%>
<% if !less.nil? && !equal.nil? -%>
JNIEXPORT
<%= render('jni/method_prototype.erb', { method: JNIHelper.compareMethod(entity) }) %>;
<%= render('jni/method_prototype.erb', { method: JNIHelper.compareMethod(entity), maybe_unused: false }) %>;

<% end -%>

Expand Down
5 changes: 3 additions & 2 deletions codegen/lib/templates/kotlin/ios_class.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import kotlinx.cinterop.toCValues
<% constructors = entity.static_methods.select { |method| method.name.start_with?('Create') } -%>
<% methods = entity.methods.select { |method| not method.name.start_with?('Delete') } -%>
<% static_methods = entity.static_methods.select { |method| not method.name.start_with?('Create') } -%>
@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
actual class <%= entity.name %> constructor(
val pointer: CPointer<TW<%= entity.name %>>,
) {
<% unless entity.methods.select{ |x| x.name == "Delete" }.empty? -%>
@OptIn(ExperimentalStdlibApi::class)
private val cleaner = kotlin.native.internal.createCleaner(pointer) { ptr ->
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
private val cleaner = kotlin.native.ref.createCleaner(pointer) { ptr ->
TW<%= entity.name %>Delete(ptr)
}
<% end -%>
Expand Down
1 change: 1 addition & 0 deletions codegen/lib/templates/kotlin/ios_enum.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.trustwallet.core.<%= "TW#{entity.name}" %>.*

<% end -%>
<% type = ": TW#{entity.name}" -%>
@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
actual enum class <%= entity.name %>(
<% if has_string -%>
val nativeValue<%= type %>,
Expand Down
1 change: 1 addition & 0 deletions codegen/lib/templates/kotlin/ios_struct.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import kotlinx.cinterop.toCValues

@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
actual object <%= entity.name %> {
<%# Static property declarations -%>
<% entity.static_properties.each do |property| -%>
Expand Down
2 changes: 1 addition & 1 deletion codegen/lib/templates/kotlin_jni/compare_to.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% less = locals[:less] -%>
<% equal = locals[:equal] -%>
<% compareMethod = KotlinJniHelper.compareMethod(entity) -%>
<%= render('kotlin_jni/method_prototype.erb', { method: compareMethod }) %> {
<%= render('kotlin_jni/method_prototype.erb', { method: compareMethod, maybe_unused: false }) %> {
<%= render('kotlin_jni/instance_access.erb', { entity: entity }) %>
<%= render('kotlin_jni/parameter_access.erb', { method: compareMethod }) -%>
<% if entity.struct? -%>
Expand Down
2 changes: 1 addition & 1 deletion codegen/lib/templates/kotlin_jni/method.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% method = locals[:method] -%>
<%= render('kotlin_jni/method_prototype.erb', { method: method }) %> {
<%= render('kotlin_jni/method_prototype.erb', { method: method, maybe_unused: false }) %> {
<% if !method.static -%>
<%= render('kotlin_jni/instance_access.erb', { entity: entity }) %>
<% end -%>
Expand Down
13 changes: 10 additions & 3 deletions codegen/lib/templates/kotlin_jni/method_prototype.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<%
method = locals[:method]
maybe_unused = locals[:maybe_unused]

maybe_unused_str = ''
if maybe_unused
maybe_unused_str = '[[maybe_unused]] '
end

if method.static
parameters = 'jclass thisClass' + KotlinJniHelper.parameters(method.parameters)
parameters = maybe_unused_str + 'jclass thisClass' + KotlinJniHelper.parameters(method.parameters)
else
parameters = 'jobject thisObject' + KotlinJniHelper.parameters(method.parameters.drop(1))
parameters = maybe_unused_str + 'jobject thisObject' + KotlinJniHelper.parameters(method.parameters.drop(1))
end
-%>
<%= KotlinJniHelper.type(method.return_type) %> JNICALL <%= KotlinJniHelper.function_name(entity: entity, function: method) %>(JNIEnv *env, <%= parameters %>)<% -%>
<%= KotlinJniHelper.type(method.return_type) %> JNICALL <%= KotlinJniHelper.function_name(entity: entity, function: method) %>(<%= maybe_unused_str %>JNIEnv *env, <%= parameters %>)<% -%>
10 changes: 5 additions & 5 deletions codegen/lib/templates/kotlin_jni_h.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ jbyteArray JNICALL <%= KotlinJniHelper.function_name(entity: entity, function: m
<%# Static property declarations -%>
<% entity.static_properties.each do |property| -%>
JNIEXPORT
<%= render('kotlin_jni/method_prototype.erb', { method: property }) %>;
<%= render('kotlin_jni/method_prototype.erb', { method: property, maybe_unused: false }) %>;

<% end -%>
<%# Static method declarations -%>
<% entity.static_methods.each do |method| -%>
<% next if method.name.start_with?('Create') || method.name.start_with?('Init') -%>
JNIEXPORT
<%= render('kotlin_jni/method_prototype.erb', { method: method }) %>;
<%= render('kotlin_jni/method_prototype.erb', { method: method, maybe_unused: false }) %>;

<% end -%>
<%# Property declarations -%>
<% entity.properties.each do |property| -%>
JNIEXPORT
<%= render('kotlin_jni/method_prototype.erb', { method: property }) %>;
<%= render('kotlin_jni/method_prototype.erb', { method: property, maybe_unused: false }) %>;

<% end -%>
<%# Method declarations -%>
<% entity.methods.each do |method| -%>
<% next if method.name.start_with?('Delete') -%>
JNIEXPORT
<%= render('kotlin_jni/method_prototype.erb', { method: method }) %>;
<%= render('kotlin_jni/method_prototype.erb', { method: method, maybe_unused: false }) %>;

<% end -%>
<% less = entity.static_methods.detect{ |i| i.name == 'Less' } -%>
<% equal = entity.static_methods.detect{ |i| i.name == 'Equal' } -%>
<% if !less.nil? && !equal.nil? -%>
JNIEXPORT
<%= render('kotlin_jni/method_prototype.erb', { method: KotlinJniHelper.compareMethod(entity) }) %>;
<%= render('kotlin_jni/method_prototype.erb', { method: KotlinJniHelper.compareMethod(entity), maybe_unused: false }) %>;

<% end -%>

Expand Down
2 changes: 1 addition & 1 deletion jni/cpp/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
void random_buffer(uint8_t *buf, size_t len);
}

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, [[maybe_unused]] void *reserved) {
cachedJVM = jvm;
return JNI_VERSION_1_2;
}
Expand Down
1 change: 1 addition & 0 deletions kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ allprojects {
compilerOptions {
allWarningsAsErrors.set(true)
jvmTarget.set(JvmTarget.JVM_17)
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
10 changes: 5 additions & 5 deletions kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
android-sdk-tools = "33.0.2"
android-sdk-tools = "35.0.0"
android-sdk-min = "24"
android-sdk-compile = "33"
android-sdk-compile = "35"
android-cmake = "3.22.1"
android-ndk = "25.2.9519653"
android-ndk = "28.0.12674087"

kotlin = "1.8.21"
agp = "8.0.0"
kotlin = "2.1.0"
agp = "8.8.0"
wire = "4.5.6"

androidx-test-runner = "1.5.2"
Expand Down
Binary file modified kotlin/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit c465eb6

Please sign in to comment.