Skip to content

Commit f7ecd77

Browse files
committed
ANDROID: initial ioio integration
1 parent ddb9f8e commit f7ecd77

File tree

10 files changed

+76
-10
lines changed

10 files changed

+76
-10
lines changed

src/platform/android/app/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
// can override some attributes in main/AndroidManifest.xml
88
defaultConfig {
99
applicationId 'net.sourceforge.smallbasic'
10-
minSdkVersion 16
10+
minSdkVersion 19
1111
targetSdkVersion 34
1212
versionCode 59
1313
versionName '12.26'
@@ -26,16 +26,10 @@ android {
2626
}
2727

2828
buildTypes {
29-
debug {
30-
buildConfigField "boolean", "DEBUG_VIEW", "true"
31-
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + System.currentTimeMillis() + "L)"
32-
}
3329
release {
3430
ndk {
3531
debugSymbolLevel = 'FULL'
3632
}
37-
buildConfigField "boolean", "DEBUG_VIEW", "false"
38-
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + System.currentTimeMillis() + "L)"
3933
shrinkResources true
4034
minifyEnabled true
4135
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
@@ -60,5 +54,6 @@ android {
6054

6155
dependencies {
6256
implementation 'androidx.core:core:1.12.0'
57+
implementation project(':ioio')
6358
testImplementation 'junit:junit:4.13.2'
6459
}

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import androidx.core.content.ContextCompat;
4343
import androidx.core.content.FileProvider;
4444

45+
import net.sourceforge.smallbasic.ioio.IOIOUtility;
46+
4547
import java.io.BufferedReader;
4648
import java.io.BufferedWriter;
4749
import java.io.ByteArrayInputStream;
@@ -357,6 +359,20 @@ public int getWindowHeight() {
357359
return rect.height();
358360
}
359361

362+
public boolean loadModules() {
363+
Log.i(TAG, "loadModules");
364+
boolean result;
365+
try {
366+
System.loadLibrary("ioio");
367+
IOIOUtility.init();
368+
result = true;
369+
} catch (SecurityException | UnsatisfiedLinkError e) {
370+
Log.i(TAG, "loadModules", e);
371+
result = false;
372+
}
373+
return result;
374+
}
375+
360376
@Override
361377
public void onGlobalLayout() {
362378
super.onGlobalLayout();

src/platform/android/gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
12-
android.defaults.buildfeatures.buildconfig=true
1312
android.enableJetifier=true
1413
android.nonFinalResIds=false
1514
android.nonTransitiveRClass=false

src/platform/android/ioio/ioio.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SmallBASIC
2+
# Copyright(C) 2024 Chris Warren-Smith.
3+
#
4+
# This program is distributed under the terms of the GPL v2.0 or later
5+
# Download the GNU Public License (GPL) from www.gnu.org
6+
#
7+
8+
JNI_PATH := $(call my-dir)
9+
SB_HOME := $(JNI_PATH)/../../../..
10+
11+
include $(call all-subdir-makefiles)
12+
LOCAL_PATH := $(JNI_PATH)
13+
14+
include $(CLEAR_VARS)
15+
LOCAL_MODULE := ioio
16+
LOCAL_CFLAGS := -DHAVE_CONFIG_H=1 -Wno-unknown-pragmas
17+
LOCAL_C_INCLUDES := $(SB_HOME) $(SB_HOME)/src
18+
LOCAL_SRC_FILES := src/main/cpp/ioio.cpp
19+
LOCAL_LDLIBS := -llog -landroid
20+
include $(BUILD_SHARED_LIBRARY)
21+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <jni.h>
2+
#include <android/log.h>
3+
4+
JNIEnv *g_env;
5+
6+
extern "C" JNIEXPORT void JNICALL
7+
Java_net_sourceforge_smallbasic_ioio_IOIOUtility_init(JNIEnv *env, jclass clazz) {
8+
__android_log_print(ANDROID_LOG_INFO, "smallbasic", "init entered");
9+
g_env = env;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package net.sourceforge.smallbasic.ioio;
2+
3+
public class IOIOUtility {
4+
private IOIOUtility() {
5+
// no access
6+
}
7+
8+
public static native void init();
9+
10+
}

src/platform/android/jni/runtime.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define SERVER_TOKEN_KEY "serverToken"
3636
#define MUTE_AUDIO_KEY "muteAudio"
3737
#define THEME_KEY "theme"
38+
#define LOAD_MODULES_KEY "loadModules"
3839
#define OPT_IDE_KEY "optIde"
3940
#define GBOARD_KEY_QUESTION 274
4041
#define EVENT_TYPE_EXIT 100
@@ -557,7 +558,14 @@ void Runtime::loadConfig() {
557558
loadEnvConfig(settings, SERVER_SOCKET_KEY);
558559
loadEnvConfig(settings, SERVER_TOKEN_KEY);
559560
loadEnvConfig(settings, FONT_ID_KEY);
561+
562+
s = settings.get(LOAD_MODULES_KEY);
563+
if (s && s->toInteger() == 1) {
564+
trace("calling loadModules");
565+
getBoolean("loadModules");
566+
}
560567
}
568+
561569
}
562570

563571
bool Runtime::loadSettings(Properties<String *> &settings) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
include ':app'
2+
include ':ioio'

src/platform/android/webui/.eslintrc.js renamed to src/platform/android/webui/.eslintrc.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ module.exports = {
2929
],
3030
"rules": {
3131
"react/prop-types": "off"
32+
},
33+
"settings": {
34+
"react": {
35+
"version": "detect"
36+
}
3237
}
3338
}

src/platform/android/webui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "webui",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"private": true,
5+
"type": "module",
56
"dependencies": {
67
"@emotion/react": "^11.11.4",
78
"@emotion/styled": "^11.11.0",
@@ -22,7 +23,7 @@
2223
},
2324
"scripts": {
2425
"start": "vite --host",
25-
"build": "GENERATE_SOURCEMAP=false vite && rm ../app/src/main/assets/webui/static/js/main.* && cp -R build/* ../app/src/main/assets/webui/",
26+
"build": "GENERATE_SOURCEMAP=false vite build && rm ../app/src/main/assets/webui/static/js/main.* && cp -R build/* ../app/src/main/assets/webui/",
2627
"update": "npm update && ncu -u && npm install && npm audit fix"
2728
},
2829
"eslintConfig": {

0 commit comments

Comments
 (0)