-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[build] Android APK building from command line #278
Comments
Being working on this issue for some days... and it's driving me crazy... everything seems to compile fine but obviously I'm missing some points... Just implemented a custom Makefile to build an Android APK (ARMv7-A CPU architecture) but despite everything seems to be fine and APK is built, I get a Project libraries are built for that architecture ( Also feel that More info: Using latest Android NDK r16-beta standalone toolchain, using GCC. I'm stuck, any help on this issue would be very appreciated... |
@raysan5 AndroidManifest you use has same minimum and target sdk version, target should be latest (26) or at least 25. That should not be related to ABI I think, but it is not correct. |
Hi @gen2brain, thanks for the answer! Checking the documentation, it seems I can just skip the In any case, also tried latest target SDK version and same error. |
Just in case it could be useful, this is the output command line:
Also avoid javac warning passing |
Perhaps you can try to build with just -mtune and -mcpu and without -march. The binary should work on lots of different cpus, something like -mtune=generic-armv7 -mcpu=arm7 maybe, or similar. |
I'm not expert on this, but I found something in the documentation. Maybe you can this option in the Android.mk file: The doc says the default option is armeabi. |
Thanks @gen2brain, just checked it but no Hi @RafaelOliveira, thanks for the answer, Reading latest Android NDK version information, the NDK roadmap and some NDK bugs, it makes me think that maybe some internal things in NDK libs change (specifically in |
Your output goes just to lib/libname.so , can you try to put it in libs/armeabi-v7a/ ? |
Hey @gen2brain! You're right! Changing lib path to Keep working on it... |
Hi @raysan5, Use
|
Thanks @skanti, yeah, already tried
It should output raylib log traces but nothing... All captured traces with
|
After lot of testing and trying I realized that the most simple answer should the correct one... my Got some new ideas to test tomorrow... ;) |
Hi @skanti, after some more testing I managed to get a good trace:
For some reason
Any idea? It seems some configuration/paths problem I'm messing them up... |
Hi @raysan5,
Hope that helps. |
Hi @skanti, thanks for the quick answer:
<meta-data android:name="android.app.lib_name" android:value="raylib_game" /> Actually, I used that same For some reason, Java entry point is not finding the library to load... I'll take a closer look to |
@raysan5 try with libs instead of lib directory. Also, if you have rooted phone you can check what is actually installed in /data/data/com.raylib.game_sample , just adb shell, then su, and list contents of directory, in that dir lib (without s) should exists with your library. |
@gen2brain already tried with Thanks for the I'm documenting myself on all the tools used in the process: |
Some relevant information: https://developer.android.com/ndk/guides/abis.html#aen It seems all folders are correct (also on generated APK) but for some reason shared library is not found... considering creating the Activity Class manually and load library manually... |
After lot of research, that's the closest answer to the problem:
Tried comenting all the code and it seems library is loaded ok. Start working from this point again. |
UPDATE: Last comment was right, for some reason raylib library is not linked properly into final I just created a simple Android C sample copying the basic raylib functions for Android: static void InitWindow(int width, int height, void *state); // Initialize Android activity
static void InitGraphicsDevice(int width, int height); // Initialize graphic device
static void CloseWindow(void); // Close window and unload OpenGL context
static void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing
static void EndDrawing(void); // End canvas drawing and swap buffers (double buffering)
static void SwapBuffers(void); // Copy back buffer to front buffers Launched Now, let's check what happens with library linkage... no errors, no warnings... let's check Thank you very much @gen2brain, @RafaelOliveira and @skanti for your time helping on this issue. |
Congrats @raysan5 :) Quite an awkward error, I would expect that the linker complained in such scenarios |
Just checked Something is not working properly on linkage and I don't know how to look for the problem... :( EDIT: I tried adding the minimum raylib modules to the project: Checking carefully
Investigating a bit further, came to this: Second link offers a tool to clean those warning points but tat tool is only available for Linux OS because it depends on library Quite complex issue... |
Hey Ray, I just built apk on Linux using your Makefile (with a little modifications for my env etc.) and it crashes for me also. This is what I found, from logcat:
And when I access library in shell I get this: So you link to shared openal but libopenal.so is not in apk. I tried to copy libopenal.so from your repo to same dir but that didn't help. Perhaps you can also add SONAME to library, I remember I had to add this for some project where I also had native library. Something like -Wl,-soname,libraylib_game.so . |
Actually, OpenAL is not linked at all:
|
Hey @gen2brain! Thanks for testing! It seems you get some more clear debug info than me! I know, OpenAL is not linked, but it shouldn't be a problem as far as no function is called ever, at least that's the case in windows... but clearly some linked (or not linked) libraries are not working properly... Just uploaded a stripped version of raylib right now here: https://github.com/raysan5/raylib/tree/develop/templates/android_project Please, could you try with that project? It shouldn't require any additional library but it fails the same way... |
Ok, just tested with stripped version and it works for me.
|
Wow! That's great! :D Now, the question is: why it doesn't work on my side??? I keep getting same errors... >_< Well, at least that's a step forward... which version of the Android NDK are you using? GCC or Clang? version? |
NDK version is 14b, the latest build now was with clang, before that it was gcc I think, whatever was in Makefile. Btw. I had to comment ANDROID_* variables in Makefile and export them in my shell. I guess ?= is needed. And there is some error in project_dirs, so I just created dirs manually.
|
ok, I'm using Android NDK r16 beta1, reading changelog more carefully noticed that some of the changes could be involved in the crash (GCC not supported, libc++ as default linkage, unified headers, libandroid_support...). I'll try compiling with r14b tomorrow... About |
Maybe related: https://android.googlesource.com/platform/ndk.git/+/master/docs/UnifiedHeaders.md
|
By coincidence, just checked an old compilation trace using
|
Finally got it working with # Compilers
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-gcc
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
# Compiler flags for arquitecture
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
# Compilation functions attributes options
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC
# Compiler options for the linker
CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes
# Preprocessor macro definitions
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16
# Paths containing required header files
INCLUDES = -I. -Isrc/include -I$(ANDROID_NDK)/sources/android/native_app_glue
# Linker options
LFLAGS = -Wl,-soname,lib$(LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a
LFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings
# Force linking of library module to define symbol
LFLAGS += -u ANativeActivity_onCreate
# Library paths containing required libs
LFLAGS += -L. -Lsrc -Llib -Lsrc/libs
# Define any libraries to link into executable
# if you want to link libraries (libname.so or libname.a), use the -lname
LIBS = -lnative_app_glue -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES -latomic -lc -lm After further investigation (really wanted to know what was crashing the build), tried removing mostly all Well, next step, OpenAL Soft compilation and testing. |
I compile OpenAL like this https://github.com/gen2brain/raylib-go/blob/master/examples/android/example/bootstrap.sh#L50 , with their cmake build system. Static/shared option for OpenAL would be nice. For closed source projects it must be shared I think, not really an expert for licenses, but it is nice to only have one shared library with everything needed. |
Hi @gen2brain! Did OpenAL Soft work on your side? I added Again, I think it's related to some missing library on linkage (some OpenAL Soft dependency that is not included by default). I'm generating CMake build with:
EDIT: Yes, for closed source projects it must be shared, one of the nuances of LGPL... |
Finally, got it working... but using OpenAL static version ( It would be great to know how to add other shader libraries to the APK, in case the user wants to build raylib as a shared library ( EDIT: Checking documentation, adding additional shared libraries ( I'll try this more carefully, maybe some missing compilation/linkage parameter... |
Just kept working on shared libraries usage with no luck... I build I'm getting the same linkage error I was getting at the beginning, it seems some symbol is missing or something fails on linkage but no comprehensive output is provided by logcat... |
Do all shared libraries have SONAME defined? For library that is loaded it can use basename instead, but if that library links to other that do not have SONAME it will not be able to find it. I think behaviour also depends on Android versions, I had similar problems. You can check with SONAME libopenal.so.1` |
Hi @gen2brain! Thank you very much for the information! Just tried recompiling OpenAL Soft defining SONAME but result is still cmake .. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../XCompile-Android.txt -DHOST=arm-linux-androideabi -DCMAKE_C_FLAGS="-s -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes -Wl,-soname,libopenal.so -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16" Also tried including By the way, using static library versions ( |
What about SONAME for libraylib.so and libraylib-game.so ? |
Verified both, they are ok: Also added |
Just for reference,
Do I miss something? I'm not an expert interpreting Still getting those lines on crash:
Those DT entries are related to |
I had a quick flick through but did you make sure
|
Hi @skanti, thanks for the answer!
Yes, the only dependencies are
Yes, actually, it works great using static libraries, only fails when using shared libs.
Yes, all dependencies are placed in the required folder
Didn't try that! Any recommendation for the most appropiate linking order? Current linking order is: LDLIBS = -lnative_app_glue -lraylib -lopenal -llog -landroid -lEGL -lGLESv2 -lOpenSLES -latomic -lc -lm -ldl
|
In Linux you cannot use shared libraries even when they are placed in the same folder, you require this Try to set this variable in your device Quick Disclaimer: What I am suggesting could be utter crap. However, in my years of experiences I had bugs in the most unspeakable places :) The order looks fine. Try to put the base libraries in the front and the dependent-on-dependency ones as least (maybe EDIT: Any particular reason for |
Finally got it working, using static ( Using static libraries was "easy", just link them into <meta-data android:name="android.app.lib_name" android:value="raylib_game" /> If not defined that meta tag, by default, it tries to load Using shared libraries was not that easy, after lot of research, found the answer here. Basically, it says that additional shared libraries required by package com.raylib.game_sample;
public class NativeLoader extends android.app.NativeActivity
{
static
{
System.loadLibrary("openal");
System.loadLibrary("raylib");
System.loadLibrary("raylib_game");
}
} Some changes are required to Additionally, And voilà! raylib working in Android, as static and shared library. |
Keep working on it for a better integration with raylib build pipeline... Planning to create a self-contained |
Implemented in games templates. |
Just studying the possibility to directly build .apk programs from command line... to include with raylib all required tools, curated and packed in a single zip.
A lot of tools are involved in APK generation and they come in different Android packages, more info here.
Here it is a list with some of the command line tools provided: https://developer.android.com/studio/command-line/index.html
Android APK building using ANT
https://stuff.mit.edu/afs/sipb/project/android/docs/tools/building/building-cmdline.html
Android APK building in raw mode (calling all required tools directly)
aapt
programdx
tool to convert Java bytecode to Dalvik bytecode if requiredjarsigner
tool, to generate key usekeytool
(info)zipalign
toolNote that .apk generation tools
aapt
anddx
are included with Android build tools (installed withsdkmanager
). Here some info onaapt
usage: http://elinux.org/Android_aapt.A quite good guide on this process can be found here.
The text was updated successfully, but these errors were encountered: