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

Missing Android.mk makefile? #107

Open
superfury opened this issue Oct 21, 2024 · 8 comments
Open

Missing Android.mk makefile? #107

superfury opened this issue Oct 21, 2024 · 8 comments

Comments

@superfury
Copy link
Contributor

superfury commented Oct 21, 2024

I noticed that the Android.mk file is missing for SDL3_net, required for compilation?

I've made one based on the old Android.mk and the current SDL3 Android.mk:

LOCAL_PATH := $(call my-dir)

###########################
#
# SDL_net shared library
#
###########################

include $(CLEAR_VARS)

LOCAL_MODULE := SDL3_net

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_SRC_FILES := \
	$(subst $(LOCAL_PATH)/,,) \
	$(wildcard $(LOCAL_PATH)/src/*.c) \

LOCAL_CFLAGS += \
	-Wall -Wextra \
	-Wmissing-prototypes \
	-Wunreachable-code-break \
	-Wunneeded-internal-declaration \
	-Wmissing-variable-declarations \
	-Wfloat-conversion \
	-Wshorten-64-to-32 \
	-Wunreachable-code-return \
	-Wshift-sign-overflow \
	-Wstrict-prototypes \
	-Wkeyword-macro \

# Warnings we haven't fixed (yet)
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-sign-compare

LOCAL_CXXFLAGS += -std=gnu++11

LOCAL_LDLIBS :=

LOCAL_LDFLAGS := -Wl,--no-undefined -Wl,--no-undefined-version -Wl,--version-script=$(LOCAL_PATH)/src/SDL_net.sym

ifeq ($(NDK_DEBUG),1)
    cmd-strip :=
endif

LOCAL_SHARED_LIBRARIES := SDL3 android-ifaddrs

include $(BUILD_SHARED_LIBRARY)

###########################
#
# SDL_net static library
#
###########################

LOCAL_MODULE := SDL3_net_static

LOCAL_MODULE_FILENAME := libSDL3_net

LOCAL_LDLIBS :=

LOCAL_LDFLAGS :=

LOCAL_EXPORT_LDLIBS :=

LOCAL_STATIC_LIBRARIES := SDL3
LOCAL_SHARED_LIBRARIES := android-ifaddrs

include $(BUILD_STATIC_LIBRARY)

I managed to properly compile my app with it under Android Studio on Windows.

Although android-ifaddrs support is required to compile SDL3_net (My created Android port of it: https://github.com/superfury/android-ifaddrs).

@madebr
Copy link
Contributor

madebr commented Oct 22, 2024

Indeed, looks like getifaddrs and freeifaddrs need extra support on Android.
Let's fork the android-ifaddrs repo to libsdl-org's organization, and add it as an external dependency to the CMake and Android.mk project?

https://github.com/madebr/SDL_net/actions/runs/11461755833/job/31891590260#step:11:77

@madebr
Copy link
Contributor

madebr commented Oct 22, 2024

There's something that I don't understand about this.
Building an Android executable fails with undefined reference errors, but building a libSDL3_net.so shared library succeeds, even when adding -Wl,--no-undefined to the link command.
https://github.com/madebr/SDL_net/actions/runs/11461840644/job/31891832207#step:9:138

Assets for SDL3_net release: https://github.com/madebr/SDL_net/actions/runs/11461840644

@superfury
Copy link
Contributor Author

That's weird. Under Android Studio with my Makefile.mk and my fork of android-ifaddrs properly added to the project (in a folder parallel to the SDL3 and SDL3_net folders (which contain their include and src folders, as well as their Android.mk (with SDL3_net being the one listed in my post)), my own app using both properly compiles and runs.
Perhaps an issue in the online toolchain?
My app is using a the Android Studio project from 3.1.1 essentially (although using 3.1.3 prerelease right now), with everything essentially like SDL2 from when 2.0.0 came out (except my project's source being compatible with compiling with newer versions up to 2.26.5 and newer, with 3.1.1 support added as well for SDL3 builds, and #ifdefs for supporting the 3.1.2 and 3.1.3 API changes as well)). The Android Studio project is still the same as back then, except the gradle text files being updated to 3.0 standards (as well as my app's android xml manifest, which is app-specific).

My app itself (using SDL2/SDL3 and optionally SDL2_net/SDL3_net (depending on SDL version) which is detected by installed modules (in my testcase it's SDL3 and SDL3_net, although I usually use SDL2 (2.26.5) and SDL2_net due to audio issues on newer SDL2 versions and SDL3 not being official yet).
It seems to run fine on SDL3 + SDL3_net however (3.1.3 prerelease from the source zip archive with SDL3_net being from the git repository's latest code).
Though I didn't test connecting (using TCP connections) on the latest SDL3_net code yet, the base SDL3 part without active connections seems to run fine with my app. It is listening for calls when instructed by the OS running within my app though (not by default, as it's an emulated modem like Dosbox's, but much improved compared to that one, as well as ISP emulation support added (a PPP/SLIP server, with real Ethernet II (using pcap, not supported on Android yet, but supported on linux/Windows builds) or internal network (Like a loopback adapter essentially. But it allows all conmected clients to talk to each other instead). This loopback-method (instead of regular pcap) is used on the Android builds.
So testing that should be easy: simply put the app's modem into server mode with loopback, then connect to it over the listening TCP port while it's running. It should give a text prompt for username/password (if configured to have any) and protocol to use (if correctly entered and the credentials are correct, it should respond with some textual information (IP addresses or MAC addresses depending on the mode, if available) and then report CONNECTED after which after a small delay it'd start the SLIP or PPP service. PPP allows empty username/password too (instead using that during PPP authentication), otherwise PPP authentication must match the entered authentication. Of course, you can also send a PPP header (and nothing else) to start it immediately when the username prompt appears.
(Thinking about it, it should do that for the protocol prompt as well, when that's the first input, but that's some other problem. Didn't check if I implemented that one yet)

@superfury
Copy link
Contributor Author

superfury commented Oct 22, 2024

Although my android-ifaddrs repo uses the Android.mk building method (with ndk-build Makefile system (Android.mk)), not cmake? Perhaps that's the issue?

@superfury
Copy link
Contributor Author

Just checked with an Android-based telenet client connecting to 127.0.0.1. It properly connects and communicates using SDL_net. So the SDL3_net library using my Android.mk under Android Studio is working properly.

@sezero
Copy link
Contributor

sezero commented Oct 23, 2024

Why can we not embed android-ifaddrs directly (e.g. as a static implementation detail) instead of building it as a shared dependency lib? That would, I believe, eliminate the linkage errors @madebr encountered. Is its license that incompatible with us?

@madebr
Copy link
Contributor

madebr commented Oct 23, 2024

I've not yet tried to run the SDL_net samples on my phone.
Looking at android-ifaddrs' license, we would need to add its license to android inaries we ship. I think that's doable.

@superfury
Copy link
Contributor Author

You can't put the ifaddr headers directly into the include path or (cmake) Makefile, as that would cause conflicts with the ifaddr implementation on other platforms that do natively support it? So you'd need to keep it seperated from the normal SDL3_net headers and build files. So the best way to support it is in a seperated repository for Android only like my supplied Android.mk uses.

And Android.mk is still required (SDL3 itself does still support it from what I can see in it's repository) to compile SDL3_net on non-cmake Android platforms.

Of course Android-ifaddrs' Android.mk might need to be adjusted for the different build scenarios, if that's still needed. So far with my shared libary executable it compiles and runs without issues (SDL3 3.1.3 with SDL3_net directly from this repository's latest commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants