Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android: fix crash with Android <12 and go 1.23 #3243

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .containerversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29
30
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

.DS_Store
.idea
.cxx/


### Vim ###
Expand Down
11 changes: 11 additions & 0 deletions frontends/android/BitBoxApp/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ android {
versionCode 59
versionName "android-4.47.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags '-std=c++11'
}
}
}
buildTypes {
release {
Expand All @@ -23,6 +28,12 @@ android {
}
}
namespace 'ch.shiftcrypto.bitboxapp'
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.31.6'
}
}
}

dependencies {
Expand Down
23 changes: 23 additions & 0 deletions frontends/android/BitBoxApp/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.16)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a bunch of warnings in CI that would be nice to fix

> Task :app:configureCMakeDebug[arm64-v8a]
C/C++: CMake Warning (dev) in CMakeLists.txt:
C/C++:   No project() command is present.  The top-level CMakeLists.txt file must
C/C++:   contain a literal, direct call to the project() command.  Add a line of
C/C++:   code such as
C/C++:     project(ProjectName)
C/C++:   near the top of the file, but after cmake_minimum_required().
C/C++:   CMake is pretending there is a "project(Project)" command on the first
C/C++:   line.
C/C++: This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: CMake Warning (dev) in CMakeLists.txt:
C/C++:   cmake_minimum_required() should be called prior to this top-level project()
C/C++:   call.  Please see the cmake-commands(7) manual for usage documentation of
C/C++:   both commands.
C/C++: This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /opt/android-sdk/cmake/3.31.6/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:146 (include)
C/C++:   CMakeLists.txt
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android-legacy.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:55 (include)
C/C++:   /opt/android-sdk/cmake/3.31.6/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:146 (include)
C/C++:   CMakeLists.txt
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/3.31.6/CMakeSystem.cmake:6 (include)
C/C++:   CMakeLists.txt
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/3.31.6/CMakeSystem.cmake:6 (include)
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/CMakeScratch/TryCompile-Mhx4cL/CMakeLists.txt:4 (project)
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android-legacy.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:55 (include)
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/3.31.6/CMakeSystem.cmake:6 (include)
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/CMakeScratch/TryCompile-Mhx4cL/CMakeLists.txt:4 (project)
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/3.31.6/CMakeSystem.cmake:6 (include)
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/CMakeScratch/TryCompile-3f9Hms/CMakeLists.txt:4 (project)
C/C++: CMake Deprecation Warning at /opt/android-sdk/ndk/27.0.12077973/build/cmake/android-legacy.toolchain.cmake:35 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.
C/C++: Call Stack (most recent call first):
C/C++:   /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake:55 (include)
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/3.31.6/CMakeSystem.cmake:6 (include)
C/C++:   /root/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/Debug/3j161s34/arm64-v8a/CMakeFiles/CMakeScratch/TryCompile-3f9Hms/CMakeLists.txt:4 (project)
C/C++: CMake Deprecation Warning at CMakeLists.txt:3 (cmake_minimum_required):
C/C++:   Compatibility with CMake < 3.10 will be removed from a future version of
C/C++:   CMake.
C/C++:   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
C/C++:   to tell CMake that the project requires at least <min> but has been updated
C/C++:   to work with policies introduced by <max> or earlier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the one about "project" but the one about the compatibility with 3.10 seems trickier. It is not directly related to the one I specify in the CMakeLists.txt file, bur rather comes from an auto-generated file

( /opt/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/.cxx/RelWithDebInfo/4m1d2f1o/x86_64/CMakeFiles/3.31.6/CMakeSystem.cmake)

more specifically this line:

include("/opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake")

and indeed:

> cat /opt/android-sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake | grep minimum
cmake_minimum_required(VERSION 3.6.0)

I checked the newest NDK releases and we'd need to upgrade to ndk 28 to fix this warning. I think it would be better to do it in another PR, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense, thanks

project(signal_handler)

add_library( # Specifies the name of the library.
signal_handler

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
signal_handler.c
)

find_library(
log-lib
log
)

target_link_libraries(
signal_handler
${log-lib}
)
28 changes: 28 additions & 0 deletions frontends/android/BitBoxApp/app/src/main/cpp/signal_handler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// signal_handler.c
#include <jni.h>
#include <signal.h>
#include <android/log.h>

#define LOG_TAG "SignalHandler"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

void sigsys_handler(int signum, siginfo_t *info, void *context) {
LOGI("SIGSYS signal received and ignored.");
}

void setup_sigsys_handler() {
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigsys_handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGSYS, &sa, NULL) == -1) {
LOGI("Failed to set up SIGSYS handler");
} else {
LOGI("SIGSYS handler set up successfully");
}

}

JNIEXPORT void JNICALL Java_ch_shiftcrypto_bitboxapp_MainActivity_initsignalhandler(JNIEnv *env, jobject thisObj) {
setup_sigsys_handler();
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
import mobileserver.Mobileserver;

public class MainActivity extends AppCompatActivity {
static {
System.loadLibrary("signal_handler");
}
public native void initsignalhandler();
private final int PERMISSIONS_REQUEST_CAMERA_QRCODE = 0;
private static final String ACTION_USB_PERMISSION = "ch.shiftcrypto.bitboxapp.USB_PERMISSION";
// The WebView is configured with this as the base URL. The purpose is so that requests made
Expand Down Expand Up @@ -123,13 +127,12 @@ public void onReceive(Context context, Intent intent) {
@Override
public void onReceive(Context context, Intent intent) {
Mobileserver.usingMobileDataChanged();
}
}
};



@Override
public void onConfigurationChanged(Configuration newConfig){
public void onConfigurationChanged(Configuration newConfig) {
int currentNightMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
Expand Down Expand Up @@ -172,6 +175,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Util.log("lifecycle: onCreate");

initsignalhandler();

getSupportActionBar().hide(); // hide title bar with app name.
onConfigurationChanged(getResources().getConfiguration());
setContentView(R.layout.activity_main);
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/BitBoxSwiss/bitbox-wallet-app

go 1.22
go 1.23

require (
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20250212204931-2b90fadfc774
Expand Down
4 changes: 2 additions & 2 deletions scripts/docker_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ aqt install-qt linux desktop 6.8.2 -m qtpositioning qtserialport qtwebchannel qt
npm install -g npm@10
npm install -g locize-cli

curl https://dl.google.com/go/go1.22.5.linux-amd64.tar.gz | tar -xz -C /usr/local
curl https://dl.google.com/go/go1.23.7.linux-amd64.tar.gz | tar -xz -C /usr/local

# fuse is needed to run the linuxdeployqt appimage.
apt-get install -y --no-install-recommends fuse
Expand All @@ -101,4 +101,4 @@ gem install --no-document fpm
# Needed for Android.
apt-get install -y --no-install-recommends openjdk-17-jdk
# Keep versions in sync with build.gradle and frontends/android/Makefile.
/opt/android-sdk/cmdline-tools/tools/bin/sdkmanager "ndk;21.2.6472646" "platforms;android-34" "build-tools;34.0.0" "platform-tools"
/opt/android-sdk/cmdline-tools/tools/bin/sdkmanager "ndk;21.2.6472646" "platforms;android-34" "build-tools;34.0.0" "platform-tools" "cmake;3.31.6"
Loading