diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc1a2608..f927b7d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,19 @@ jobs: - name: Build (tomato) run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato + - name: Build (SDL3-jar) (workaround) + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t SDL3-jar + + - name: Build (apk) + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato-apk + + - uses: actions/upload-artifact@v4 + with: + name: ${{ github.event.repository.name }}-android-arm64 + # TODO: do propper packing + path: | + ${{github.workspace}}/build/tomato.apk + macos: timeout-minutes: 10 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2436386c..e56307bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,3 +70,104 @@ endif() add_subdirectory(./src) +# TODO: move to src +if (ANDROID AND TARGET SDL3::Jar) + message("II building for ANDROID!!!") + + list(APPEND CMAKE_MODULE_PATH "${SDL3_SOURCE_DIR}/cmake/android") + + # here be dragons + + find_package(SdlAndroid MODULE) + find_package(Java) + find_package(SdlAndroidPlatform MODULE) + # the existence of SDL3::Jar usually implies platform + if(SdlAndroid_FOUND) + include(SdlAndroidFunctions) + sdl_create_android_debug_keystore(tomato-debug-keystore) + sdl_android_compile_resources(tomato-resources RESFOLDER android/app/res) + + + set(ANDROID_MANIFEST_PACKAGE "org.libsdl.app.tomato") + #set(generated_manifest_path "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src/AndroidManifest.xml") + string(REPLACE "." "/" JAVA_PACKAGE_DIR "${ANDROID_MANIFEST_PACKAGE}") + #set(GENERATED_SRC_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src") + #set(GENERATED_RES_FOLDER "${GENERATED_SRC_FOLDER}/res") + #set(JAVA_PACKAGE_DIR "${GENERATED_SRC_FOLDER}/${JAVA_PACKAGE_DIR}") + set(JAVA_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android/app/java/${JAVA_PACKAGE_DIR}") + + sdl_android_link_resources(tomato-apk-linked + MANIFEST "android/app/AndroidManifest.xml" + PACKAGE ${ANDROID_MANIFEST_PACKAGE} + RES_TARGETS tomato-resources + TARGET_SDK_VERSION 31 + ) + + set(CMAKE_JAVA_COMPILE_FLAGS "-encoding;utf-8") + set(classes_path "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/tomato-java.dir/classes") + # Some CMake versions have a slow `cmake -E make_directory` implementation + if(NOT IS_DIRECTORY "${classes_path}") + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}") + endif() + set(OUT_JAR "${CMAKE_CURRENT_BINARY_DIR}/tomato.jar") + add_custom_command( + OUTPUT "${OUT_JAR}" + COMMAND ${CMAKE_COMMAND} -E rm -rf "${classes_path}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}" + COMMAND ${Java_JAVAC_EXECUTABLE} + -source 1.8 -target 1.8 + -bootclasspath "$" + "${JAVA_PACKAGE_DIR}/TomatoActivity.java" + $ + -cp "$:${SDL_ANDROID_PLATFORM_ANDROID_JAR}" + -d "${classes_path}" + COMMAND ${Java_JAR_EXECUTABLE} cf "${OUT_JAR}" -C "${classes_path}" . + DEPENDS $ "$" + ) + add_custom_target(tomato-jar DEPENDS "${OUT_JAR}") + add_dependencies(tomato-jar SDL3::Jar) # HACK: somehow their jar is not registered as an output + set_property(TARGET tomato-jar PROPERTY OUTPUT "${OUT_JAR}") + + set(dexworkdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/tomato-dex.dir") + # Some CMake versions have a slow `cmake -E make_directory` implementation + if(NOT IS_DIRECTORY "${dexworkdir}") + execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${dexworkdir}") + endif() + set(classes_dex_base_name "classes.dex") + set(classes_dex "${dexworkdir}/${classes_dex_base_name}") + add_custom_command( + OUTPUT "${classes_dex}" + COMMAND SdlAndroid::d8 + $ + $ + --lib "${SDL_ANDROID_PLATFORM_ANDROID_JAR}" + --output "${dexworkdir}" + DEPENDS $ $ + ) + add_custom_target(tomato-dex DEPENDS "${classes_dex}") + set_property(TARGET tomato-dex PROPERTY OUTPUT "${classes_dex}") + set_property(TARGET tomato-dex PROPERTY OUTPUT_BASE_NAME "${classes_dex_base_name}") + + # file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt) + + sdl_add_to_apk_unaligned(tomato-unaligned-apk + APK_IN tomato-apk-linked + OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" + #ASSETS ${RESOURCE_FILES} + #NATIVE_LIBS SDL3::SDL3-shared tomato + NATIVE_LIBS tomato + DEX tomato-dex + ) + + sdl_apk_align(tomato-aligned-apk tomato-unaligned-apk + OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" + ) + sdl_apk_sign(tomato-apk tomato-aligned-apk + KEYSTORE tomato-debug-keystore + ) + + else() + message("FF SdlAndroid module not found") + endif() +endif() + diff --git a/android/app/AndroidManifest.xml b/android/app/AndroidManifest.xml new file mode 100644 index 00000000..5360a3fe --- /dev/null +++ b/android/app/AndroidManifest.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/java/org/libsdl/app/tomato/TomatoActivity.java b/android/app/java/org/libsdl/app/tomato/TomatoActivity.java new file mode 100644 index 00000000..0f983039 --- /dev/null +++ b/android/app/java/org/libsdl/app/tomato/TomatoActivity.java @@ -0,0 +1,18 @@ +package org.libsdl.app.tomato; + +import org.libsdl.app.SDLActivity; + +public class TomatoActivity extends SDLActivity { + protected String[] getLibraries() { + return new String[] { + // "SDL3", // we link statically + // "SDL3_image", + // "SDL3_mixer", + // "SDL3_net", + // "SDL3_ttf", + // "main" + "tomato" + }; + } +} + diff --git a/android/app/res/mipmap-hdpi/ic_launcher.png b/android/app/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..d50bdaae Binary files /dev/null and b/android/app/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/res/mipmap-mdpi/ic_launcher.png b/android/app/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..0a299eb3 Binary files /dev/null and b/android/app/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/res/mipmap-xhdpi/ic_launcher.png b/android/app/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..a336ad5c Binary files /dev/null and b/android/app/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/res/mipmap-xxhdpi/ic_launcher.png b/android/app/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..d423dac2 Binary files /dev/null and b/android/app/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..959c384b Binary files /dev/null and b/android/app/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/res/values/colors.xml b/android/app/res/values/colors.xml new file mode 100644 index 00000000..3ab3e9cb --- /dev/null +++ b/android/app/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/android/app/res/values/strings.xml b/android/app/res/values/strings.xml new file mode 100644 index 00000000..fb573710 --- /dev/null +++ b/android/app/res/values/strings.xml @@ -0,0 +1,3 @@ + + Tomato + diff --git a/android/app/res/values/styles.xml b/android/app/res/values/styles.xml new file mode 100644 index 00000000..22248d50 --- /dev/null +++ b/android/app/res/values/styles.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/external/sdl/CMakeLists.txt b/external/sdl/CMakeLists.txt index f461a7fa..5f7937ec 100644 --- a/external/sdl/CMakeLists.txt +++ b/external/sdl/CMakeLists.txt @@ -6,6 +6,7 @@ if (NOT TARGET SDL3::SDL3) set(SDL_SHARED OFF CACHE INTERNAL "") set(SDL_STATIC ON CACHE INTERNAL "") #TODO: pic ? + set(SDL_DISABLE_ANDROID_JAR OFF CACHE INTERNAL "") FetchContent_Declare(SDL3 GIT_REPOSITORY https://github.com/libsdl-org/SDL @@ -16,6 +17,7 @@ if (NOT TARGET SDL3::SDL3) #GIT_TAG 1103294d33f47ab4c697bb22a9cf27c79c658630 # tip 15-05-2024 #GIT_TAG aacafd62336363077470f678b6217214b3b49473 # tip 28-05-2024 GIT_TAG 5fa9432b7d1c1722de93e1ab46e7a9569a47071e # tip 27-05-2024 - before changes made breaking sdl_image + FIND_PACKAGE_ARGS # for the future ) FetchContent_MakeAvailable(SDL3) diff --git a/src/main.cpp b/src/main.cpp index 89822040..f1ed880f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include "./start_screen.hpp" +#include #include #include #include @@ -23,6 +24,11 @@ int main(int argc, char** argv) { args.push_back(argv[i]); } +#ifdef __ANDROID__ + // change current working dir to internal storage + std::filesystem::current_path(SDL_AndroidGetInternalStoragePath()); +#endif + // setup hints if (SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1") != SDL_TRUE) { std::cerr << "Failed to set '" << SDL_HINT_VIDEO_ALLOW_SCREENSAVER << "' to 1\n"; diff --git a/src/start_screen.cpp b/src/start_screen.cpp index b4f125a4..6e8ac2de 100644 --- a/src/start_screen.cpp +++ b/src/start_screen.cpp @@ -49,6 +49,7 @@ StartScreen::StartScreen(const std::vector& args, SDL_Renderer std::cerr << "TOMATO error: unknown cli arg: '" << args.at(ai) << "'\n"; } } + } Screen* StartScreen::render(float, bool&) { @@ -182,6 +183,7 @@ Screen* StartScreen::render(float, bool&) { } } else { if (ImGui::Button("load", {60, 25})) { + auto new_screen = std::make_unique(std::move(_conf), _renderer, _theme, _tox_profile_path, _password, _user_name, queued_plugin_paths); return new_screen.release(); }