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

[build] Android APK building from command line #278

Closed
raysan5 opened this issue May 8, 2017 · 49 comments
Closed

[build] Android APK building from command line #278

raysan5 opened this issue May 8, 2017 · 49 comments
Assignees
Labels
platform: Android Android platform
Milestone

Comments

@raysan5
Copy link
Owner

raysan5 commented May 8, 2017

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)

  1. Code compilation, standalone toolchain could be used
  2. Executable and assets packaging into .apk (unaligned, unsigned), using aapt program
  3. Use dx tool to convert Java bytecode to Dalvik bytecode if required
  4. Sign APK with a key using jarsigner tool, to generate key use keytool (info)
  5. Aligning and optimizing APK, using zipalign tool

Note that .apk generation tools aapt and dx are included with Android build tools (installed with sdkmanager). Here some info on aapt usage: http://elinux.org/Android_aapt.

A quite good guide on this process can be found here.

@raysan5 raysan5 added the platform: Android Android platform label May 8, 2017
@raysan5 raysan5 added this to the raylib v1.8 milestone Jul 2, 2017
@raysan5
Copy link
Owner Author

raysan5 commented Jul 24, 2017

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

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 INSTALL_FAILED_NO_MATCHING_ABIS error when trying to deploy to my Moto G (XT1032) device.

Project libraries are built for that architecture (-march=armv7-a) and device supports that architecture, so, I feel the issue is somewhere else, maybe on my AndroidManifest.xml options.

Also feel that libraylib.a and libopenal.so are not linked properly into the APK...

More info: Using latest Android NDK r16-beta standalone toolchain, using GCC.

I'm stuck, any help on this issue would be very appreciated...

@gen2brain
Copy link
Contributor

@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.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

Hi @gen2brain, thanks for the answer!

Checking the documentation, it seems I can just skip the android:targetSdkVersion parameter and it should work ok. Actually, when building APK using ndk-build system, target sdk was always set to a lower version than my device and it worked ok.

In any case, also tried latest target SDK version and same error.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

Just in case it could be useful, this is the output command line:

Process started >>>
if not exist temp mkdir temp 
if not exist temp\obj mkdir temp\obj
if not exist temp\src mkdir temp\src
if not exist lib mkdir lib
if not exist temp\bin mkdir temp\bin
C:/android_toolchain_arm_api16/bin/arm-linux-androideabi-gcc -c C:/android-ndk/sources/android/native_app_glue/android_native_app_glue.c -o temp/obj/native_app_glue.o -O2 -s -Wall -std=c99 -DPLATFORM_ANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
C:/android_toolchain_arm_api16/bin/arm-linux-androideabi-ar rcs .//lib/libnative_app_glue.a temp/obj/native_app_glue.o
C:/android_toolchain_arm_api16/bin/arm-linux-androideabi-gcc -c jni/basic_game.c -o temp/obj/basic_game.o -I. -Ijni/include -IC:/android-ndk/sources/android/native_app_glue -O2 -s -Wall -std=c99 -DPLATFORM_ANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 --sysroot=C:/android_toolchain_arm_api16/sysroot -fPIC 
C:/android_toolchain_arm_api16/bin/arm-linux-androideabi-gcc -o lib/libraylib_game.so temp/obj/basic_game.o -shared -I. -Ijni/include -IC:/android-ndk/sources/android/native_app_glue -L. -Ljni/libs -Ljni -Llib -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES -lnative_app_glue
C:/PROGRA~1/Java/jdk1.8.0_144/bin/keytool -genkeypair -validity 1000 -dname "CN=raylib,O=Android,C=JPN" -keystore temp/raylibGame.keystore -storepass raylib -keypass raylib -alias raylibGameKey -keyalg RSA
C:/android-sdk/build-tools/26.0.1/aapt package -f -m -S res -J temp/src -M AndroidManifest.xml -I C:/android-sdk/platforms/android-16/android.jar
C:/PROGRA~1/Java/jdk1.8.0_144/bin/javac -source 1.7 -target 1.7 -d temp/obj -classpath C:/android-sdk/platforms/android-16/android.jar -sourcepath temp/src temp/src/com/raylib/game_sample/R.java
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
C:/android-sdk/build-tools/26.0.1/dx --dex --output=temp/bin/classes.dex temp/obj
C:/android-sdk/build-tools/26.0.1/aapt package -f -m -M AndroidManifest.xml -S res -A assets -I C:/android-sdk/platforms/android-16/android.jar -F temp/bin/raylibGame.unsigned.apk -J temp/bin
fakeLogOpen(/dev/log_crash, O_WRONLY) failed
fakeLogOpen(/dev/log_security, O_WRONLY) failed
fakeLogOpen(/dev/log_security, O_WRONLY) failed
C:/android-sdk/build-tools/26.0.1/aapt add .//temp/bin/raylibGame.unsigned.apk lib/libraylib_game.so
 'lib/libraylib_game.so'...
C:/PROGRA~1/Java/jdk1.8.0_144/bin/jarsigner -keystore temp/raylibGame.keystore -storepass raylib -keypass raylib -signedjar .//temp/bin/raylibGame.signed.apk temp/bin/raylibGame.unsigned.apk raylibGameKey
jar signed.

Warning: 
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2020-06-22) or after any future revocation date.
C:/android-sdk/build-tools/26.0.1/zipalign -f 4 temp/bin/raylibGame.signed.apk raylibGame.apk
<<< Process finished. (Exit code 0)

Also avoid javac warning passing -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar (it shouldn't be an issue), that way fakeLogOpen() errors don't appear but result is the same, error when trying to install APK.

@gen2brain
Copy link
Contributor

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.

@RafaelOliveira
Copy link

I'm not expert on this, but I found something in the documentation. Maybe you can this option in the Android.mk file:
APP_ABI := armeabi-v7a

The doc says the default option is armeabi.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

Thanks @gen2brain, just checked it but no -mtune values are recognized (tried some) and -mcpu give errors on compilation, also tried no specifing any architecture and let the compiler choose (probably the lowest level arquitecture, basic arm).

Hi @RafaelOliveira, thanks for the answer, APP_ABI := armeabi-v7a is for the ndk-build system, I'm not using it anymore, just replaced it by a custom Makefile... but just for record, I also tried it (with te old ndk-build).

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 android_app_glue) that makes raylib compilation not working properly (I bet it's related to linkage...) but I don't know...

@gen2brain
Copy link
Contributor

Your output goes just to lib/libname.so , can you try to put it in libs/armeabi-v7a/ ?

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

Hey @gen2brain! You're right! Changing lib path to lib/armeabi-v7a/libname.so did the trick! Now at least it let me install the APK in the device... but it doesn't seem to even start...

Keep working on it...

@skanti
Copy link

skanti commented Sep 26, 2017

Hi @raysan5,
are you able to start logcat after deployment (install via adb to device)? Once you have that running, everything else will be much simpler.

Use

COMMAND ${ANDROID_HOME}/platform-tools/adb logcat -c
COMMAND ${ANDROID_HOME}/platform-tools/adb logcat *:W

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

Thanks @skanti, yeah, already tried logcat but unfortunately it doesn't provide much info... it seems application don't even start... :(

raylibGame.apk: 1 file pushed. 4.4 MB/s (2887087 bytes in 0.625s)
	pkg: /data/local/tmp/raylibGame.apk
Success
C:/android-sdk/platform-tools/adb logcat -c
C:/android-sdk/platform-tools/adb -d logcat raylib:V *:S
--------- beginning of main
--------- beginning of system

It should output raylib log traces but nothing... All captured traces with COMMAND ${ANDROID_HOME}/platform-tools/adb logcat *:W belong to other processes:

raylibGame.apk: 1 file pushed. 4.9 MB/s (2887087 bytes in 0.563s)
	pkg: /data/local/tmp/raylibGame.apk
Success
C:/android-sdk/platform-tools/adb logcat -c
C:/android-sdk/platform-tools/adb logcat *:W
--------- beginning of main
W/Quickoffice(10681): Cleanup of storage: done
E/WifiStateMachine(  903): [1,506,432,491,357 ms] noteScanEnd no scan source onTime=0
E/WifiStateMachine(  903): wifi setScanResults statecom.android.server.wifi.WifiStateMachine$DisconnectedState@265e8c00 sup_state=SCANNING debouncing=false mConnectionRequests=1 selection=<none>
--------- beginning of system
W/Quickoffice(10681): Could not load clipboard.
W/Quickoffice(10681): Could not store clipboard.
W/ActivityManager(  903): No permission grants found for com.quickoffice.android
E/NetworkScheduler.SR( 2019): Unrecognised action provided: android.intent.action.PACKAGE_REMOVED
W/WearSignatureVerifier( 4262): No package com.google.android.wearable.app.cn
W/WearSignatureVerifier( 4262): No package com.google.android.wearable.app.cn
W/WearSignatureVerifier( 4262): No package com.google.android.wearable.app.cn
W/WearSignatureVerifier( 4262): No package com.google.android.wearable.app.cn
W/WearSignatureVerifier( 4262): No package com.google.android.wearable.app.cn
E/Finsky  ( 4262): [1] com.google.android.finsky.wear.bl.a(3): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
W/Finsky  ( 4262): [1] com.google.android.finsky.wear.aj.run(9): Dropping command=auto_install due to Gms not connected
W/ResourcesManager(10750): Asset path '/system/framework/com.motorola.motosignature.jar' does not exist or contains no resources.
W/ResourcesManager(10768): Asset path '/system/framework/com.google.android.maps.jar' does not exist or contains no resources.
W/ActivityManager(  903): getRunningAppProcesses: caller 10164 does not hold REAL_GET_TASKS; limiting output
W/linker  (10768): libbreakpad.so: unused DT entry: type 0x6ffffffe arg 0x150c
W/linker  (10768): libbreakpad.so: unused DT entry: type 0x6fffffff arg 0x2
W/linker  (10768): libsigmux.so: unused DT entry: type 0x6ffffffe arg 0x57c
W/linker  (10768): libsigmux.so: unused DT entry: type 0x6fffffff arg 0x1
E/InstagramApplicationForMainProcess(10768): Can't load GNU STL lib
E/InstagramApplicationForMainProcess(10768): java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libcpp_helper.so
E/InstagramApplicationForMainProcess(10768): 	at com.facebook.soloader.t.a(:79064)
E/InstagramApplicationForMainProcess(10768): 	at com.facebook.soloader.t.c(:79093)

@raysan5
Copy link
Owner Author

raysan5 commented Sep 26, 2017

After lot of testing and trying I realized that the most simple answer should the correct one... my NativeActivity is not executing.

Got some new ideas to test tomorrow... ;)

@raysan5
Copy link
Owner Author

raysan5 commented Sep 27, 2017

Hi @skanti, after some more testing I managed to get a good trace:

--------- beginning of crash
E/AndroidRuntime( 3415): FATAL EXCEPTION: main
E/AndroidRuntime( 3415): Process: com.raylib.game_sample, PID: 3415
E/AndroidRuntime( 3415): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raylib.game_sample/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to find native library: raylib_game
E/AndroidRuntime( 3415): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
E/AndroidRuntime( 3415): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
E/AndroidRuntime( 3415): 	at android.app.ActivityThread.access$800(ActivityThread.java:155)
E/AndroidRuntime( 3415): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
E/AndroidRuntime( 3415): 	at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 3415): 	at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 3415): 	at android.app.ActivityThread.main(ActivityThread.java:5343)
E/AndroidRuntime( 3415): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3415): 	at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 3415): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/AndroidRuntime( 3415): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
E/AndroidRuntime( 3415): Caused by: java.lang.IllegalArgumentException: Unable to find native library: raylib_game
E/AndroidRuntime( 3415): 	at android.app.NativeActivity.onCreate(NativeActivity.java:170)
E/AndroidRuntime( 3415): 	at android.app.Activity.performCreate(Activity.java:6010)
E/AndroidRuntime( 3415): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
E/AndroidRuntime( 3415): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
E/AndroidRuntime( 3415): 	... 10 more
W/ActivityManager(  903):   Force finishing activity 1 com.raylib.game_sample/android.app.NativeActivity
W/ActivityManager(  903): Activity pause timeout for ActivityRecord{15273e1f u0 com.raylib.game_sample/android.app.NativeActivity t1685 f}

For some reason libraylib_game.so library is not found, despite being located in:

raylibGame.apk > lib/armeabi-v7a/libraylib_game.so

Any idea? It seems some configuration/paths problem I'm messing them up...

@skanti
Copy link

skanti commented Sep 27, 2017

Hi @raysan5,
the problem you have right now is an relatively "easy" fix. However, there could be several sources of error.

  1. Check what architecture your target device has, is it ARM7?
  2. Check if your apk has been built properly. That means, unarchive it with some tool e.g. apktool, make sure that in the unarchived apk there is no folder named unknown - if you find a folder with that name, that means something is messed up.
  3. If you are building a native-activity which it seems like, see if the name of your lib matches the <meta-tag android:value> tag of your xml.

Hope that helps.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 27, 2017

Hi @skanti, thanks for the quick answer:

  1. I'm building for arm-v7a and my device MotoG (XT1032) with its CPU ARM Cortex-A7 supports ARMv7-A architecture.
  2. It seems to be build properly, libraylib_game.so is located in lib/armeabi-v7a/ folder, also tried some other locations, just in case: lib/, lib/armeabi/, lib/arm/.

image
3. Lib name in my AndroidManifest.xml seems correct:

<meta-data android:name="android.app.lib_name" android:value="raylib_game" />

Actually, I used that same AndroidManifest.xml configuration in the part with ndk-build system and it worked ok.

For some reason, Java entry point is not finding the library to load... I'll take a closer look to javac process...

@gen2brain
Copy link
Contributor

@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.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 27, 2017

@gen2brain already tried with libs instead of lib, same result, library not found.

Thanks for the adb shell tip, tried it but unfortunately not rooted phone, permission denied.

I'm documenting myself on all the tools used in the process: aapt, javac, dx

@raysan5
Copy link
Owner Author

raysan5 commented Sep 27, 2017

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...

@raysan5
Copy link
Owner Author

raysan5 commented Sep 27, 2017

After lot of research, that's the closest answer to the problem:

This happens due to missing dependencies (or even implementations). You may be getting the "unable to load library: libFoo.so" but the real dependency missing may be libBar.so that is depended by libFoo.so. Or you may simply have declared functions and called them but have no implementation for them.

The problem is due to the way building an so file works. When you build a shared object using gcc, the linking step doesn't truly happen. For example within libFoo.so, you may declare a myFunc() prototype and call it. And you can skip the implementation of myFunc(){}. The gcc will happily build you a .so file. And it will happily end up in the apk. However when it's time to load library, this will break with the "unable to load library" message.

Tried comenting all the code and it seems library is loaded ok. Start working from this point again.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

UPDATE: Last comment was right, for some reason raylib library is not linked properly into final libraylib_game.so library, it's weird because it's passed to linker and output library size seems correct...

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 Makefile, generated APK (only 18KB!!!) and voilà! Android native activity running flawlessly with OpenGL ES 2.0 context initialized!

Now, let's check what happens with library linkage... no errors, no warnings... let's check libraylib_game.so symbols...

Thank you very much @gen2brain, @RafaelOliveira and @skanti for your time helping on this issue.

@skanti
Copy link

skanti commented Sep 28, 2017

Congrats @raysan5 :) Quite an awkward error, I would expect that the linker complained in such scenarios

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

Just checked libraylib_game.so and libraylib.a with nm tool to verify included symbols and also used readelf tool to verify libraries architecture (ARM-V7a), all was correct.

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: core, rlgl and utils; in latest raylib version, just added a bunch of configuration defines to strip raylib to user needs, it came to be very handy right now! Despite compiling all together and verifying symbols, still fails on loading...

Checking carefully logcat output, it seems something breaks just before the crash, I think those are the key output lines for the issue:

W/linker  ( 3866): libraylib_game.so: unused DT entry: type 0x6ffffffe arg 0x4dcc
W/linker  ( 3866): libraylib_game.so: unused DT entry: type 0x6fffffff arg 0x1
--------- beginning of crash

Investigating a bit further, came to this:
https://stackoverflow.com/questions/33206409/unused-dt-entry-type-0x1d-arg
kbox4/source#8

Second link offers a tool to clean those warning points but tat tool is only available for Linux OS because it depends on library sys/mman.h, not available by default on MinGW... it seems there is an implementation for Windows here but haven't tried it...

Quite complex issue...

@gen2brain
Copy link
Contributor

gen2brain commented Sep 28, 2017

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:

linker  : /data/app/com.raylib.game_sample-1/lib/arm/libraylib_game.so: is missing DT_SONAME will use basename as a replacement: "libraylib_game.so"
AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raylib.game_sample/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.raylib.game_sample-1/lib/arm/libraylib_game.so
AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.raylib.game_sample-1/lib/arm/libraylib_game.so

And when I access library in shell I get this:
root@j3xnlte:/data/app/com.raylib.game_sample-1/lib/arm # ./libraylib_game.so CANNOT LINK EXECUTABLE: cannot locate symbol "alcOpenDevice" referenced by "./libraylib_game.so"...

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 .

@gen2brain
Copy link
Contributor

gen2brain commented Sep 28, 2017

Actually, OpenAL is not linked at all:

# /opt/android-toolchain-arm7/bin/arm-linux-androideabi-readelf --dynamic ./libraylib_game.so | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [liblog.so]
 0x00000001 (NEEDED)                     Shared library: [libandroid.so]
 0x00000001 (NEEDED)                     Shared library: [libEGL.so]
 0x00000001 (NEEDED)                     Shared library: [libGLESv2.so]
 0x00000001 (NEEDED)                     Shared library: [libOpenSLES.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

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...

@gen2brain
Copy link
Contributor

Ok, just tested with stripped version and it works for me.

09-28 17:27:19.746 25036 25050 I raylib  : INFO: Initializing raylib (v1.8.0)
09-28 17:27:19.746 25036 25050 I raylib  : INFO: LANDSCAPE window orientation
09-28 17:27:19.746 25036 25050 W raylib  : WARNING: Window set to landscape mode
09-28 17:27:19.746 25036 25050 I raylib  : INFO: Android app initialized successfully
09-28 17:27:19.747 25036 25050 I raylib  : INFO: APP_CMD_START
09-28 17:27:19.747 25036 25050 I raylib  : INFO: APP_CMD_RESUME
09-28 17:27:19.765 25036 25050 I raylib  : INFO: APP_CMD_INIT_WINDOW
09-28 17:27:19.771 25036 25050 I raylib  : INFO: UPSCALING: Required screen size: 800 x 450 -> Display size: 1280 x 720
09-28 17:27:19.778 25036 25050 I raylib  : INFO: Display device initialized successfully
09-28 17:27:19.778 25036 25050 I raylib  : INFO: Display size: 1280 x 720
09-28 17:27:19.778 25036 25050 I raylib  : INFO: Render size: 800 x 450
09-28 17:27:19.778 25036 25050 I raylib  : INFO: Screen size: 800 x 450
09-28 17:27:19.778 25036 25050 I raylib  : INFO: Viewport offsets: 0, 0
09-28 17:27:19.778 25036 25050 I raylib  : INFO: GPU: Vendor:   ARM
09-28 17:27:19.778 25036 25050 I raylib  : INFO: GPU: Renderer: Mali-400 MP
09-28 17:27:19.778 25036 25050 I raylib  : INFO: GPU: Version:  OpenGL ES 2.0
09-28 17:27:19.778 25036 25050 I raylib  : INFO: GPU: GLSL:     OpenGL ES GLSL ES 1.00
09-28 17:27:19.778 25036 25050 I raylib  : INFO: Number of supported extensions: 28
09-28 17:27:19.778 25036 25050 I raylib  : INFO: [EXTENSION] VAO extension detected, VAO functions initialized successfully
09-28 17:27:19.778 25036 25050 I raylib  : INFO: [EXTENSION] NPOT textures extension detected, full NPOT textures supported
09-28 17:27:19.778 25036 25050 I raylib  : INFO: [EXTENSION] ETC1 compressed textures supported
09-28 17:27:19.779 25036 25050 I raylib  : INFO: [TEX ID 1] Texture created successfully (1x1)
09-28 17:27:19.779 25036 25050 I raylib  : INFO: [TEX ID 1] Base white texture loaded successfully
09-28 17:27:19.786 25036 25050 I raylib  : INFO: [VSHDR ID 1] Vertex shader compiled successfully
09-28 17:27:19.787 25036 25050 I raylib  : INFO: [FSHDR ID 2] Fragment shader compiled successfully
09-28 17:27:19.788 25036 25050 I raylib  : INFO: [SHDR ID 3] Shader program loaded successfully
09-28 17:27:19.788 25036 25050 I raylib  : INFO: [SHDR ID 3] Default shader loaded successfully
09-28 17:27:19.790 25036 25050 I raylib  : INFO: [CPU] Default buffers initialized successfully (lines, triangles, quads)
09-28 17:27:19.791 25036 25050 I raylib  : INFO: [VAO ID 1] Default buffers VAO initialized successfully (lines)
09-28 17:27:19.791 25036 25050 I raylib  : INFO: [VAO ID 2] Default buffers VAO initialized successfully (triangles)
09-28 17:27:19.792 25036 25050 I raylib  : INFO: [VAO ID 3] Default buffers VAO initialized successfully (quads)
09-28 17:27:19.792 25036 25050 I raylib  : INFO: OpenGL default states initialized successfully
09-28 17:27:19.793 25036 25050 I raylib  : INFO: APP_CMD_GAINED_FOCUS
09-28 17:27:19.793 25036 25050 I raylib  : INFO: Target time per frame: 16.667 milliseconds

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

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?

@gen2brain
Copy link
Contributor

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.

# make
if not exist temp mkdir temp 
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [Makefile:78: project_dirs] Error 1

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

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 ANDROID_* variables, maybe they are already defined in your environment or maybe problem is related to slash (/) dir separator... something similar with mkdir, maybe permissions or not able to create directory trees (I think it requires -p arg) or the space at the end of that line...

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

Maybe related: https://android.googlesource.com/platform/ndk.git/+/master/docs/UnifiedHeaders.md

Standalone toolchains using GCC are not supported out of the box. To use GCC, pass -D__ANDROID_API__=$API when compiling. Note: this is not something we will be fixing.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 28, 2017

By coincidence, just checked an old compilation trace using ndk-build system (clang, arm64-v8a), it seems they are using a couple of extra compilation parameters...

[arm64-v8a] Compile        : raylib_game <= basic_game.c
clang.exe   -MMD -MP -MF 
            ./obj/local/arm64-v8a/objs/raylib_game/basic_game.o.d 
            -gcc-toolchain C:/android-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 
            -target aarch64-none-linux-android 
            -ffunction-sections 
            -funwind-tables 
            -fstack-protector-strong 
            -fpic 
            -Wno-invalid-command-line-argument 
            -Wno-unused-command-line-argument 
            -no-canonical-prefixes 
            -g 
            -O2 
            -DNDEBUG 
            -Ijni 
            -Ijni/include 
            -Iinclude 
            -IC:/android-ndk/sources/android/native_app_glue
            -DANDROID 
            -Wall 
            -std=c99 
            -DPLATFORM_ANDROID 
            -D__ANDROID_API__=21 
            -Wa,--noexecstack 
            -Wformat 
            -Werror=format-security
            --sysroot C:/android-ndk/sysroot 
            -isystem C:/android-ndk/sysroot/usr/include/aarch64-linux-android 
            -c jni/basic_game.c 
            -o ./obj/local/arm64-v8a/objs/raylib_game/basic_game.o

[arm64-v8a] SharedLibrary  : libraylib_game.so
clang++.exe -Wl,-soname,libraylib_game.so 
            -shared 
            --sysroot=C:/android-ndk/platforms/android-21/arch-arm64 
            ./obj/local/arm64-v8a/objs/raylib_game/basic_game.o 
            jni/libs/libraylib.a 
            ./obj/local/arm64-v8a/libandroid_native_app_glue.a 
            -latomic 
            -Wl,--exclude-libs,libatomic.a 
            ./obj/local/arm64-v8a/libopenal.so 
            -gcc-toolchain C:/android-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 
            -target aarch64-none-linux-android 
            -no-canonical-prefixes 
            -u ANativeActivity_onCreate 
            -Wl,--build-id 
            -Wl,--no-undefined 
            -Wl,-z,noexecstack 
            -Wl,-z,relro 
            -Wl,-z,now 
            -Wl,--warn-shared-textrel 
            -Wl,--fatal-warnings 
            -LC:/android-ndk/platforms/android-21/arch-arm64/usr/lib 
            -llog -landroid -lEGL -lGLESv2 -lOpenSLES -llog -landroid -lc -lm 
            -o ./obj/local/arm64-v8a/libraylib_game.so

@raysan5
Copy link
Owner Author

raysan5 commented Sep 29, 2017

Finally got it working with Android NDK r16 beta1, just added a bunch of flags for compilation and linkage:

# 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 CFLAGS and LFLAGS, and the only real problem was not including -lm math library on linkage (-latomic and -lc could be skipped).

Well, next step, OpenAL Soft compilation and testing.

@gen2brain
Copy link
Contributor

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.

@raysan5
Copy link
Owner Author

raysan5 commented Sep 29, 2017

Hi @gen2brain! Did OpenAL Soft work on your side?

I added -lopenal to compilation linkage and copied libopenal.so into lib/armeabi-v7a for package generation... but program crashes at runtime (using original raylib game sample).

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:

C:\openal-soft\build>cmake .. -G"MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../XCompile-Android.txt -DHOST=arm-linux-androideabi -DCMAKE_C_FLAGS="-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 -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16"

EDIT: Yes, for closed source projects it must be shared, one of the nuances of LGPL...

@raysan5
Copy link
Owner Author

raysan5 commented Sep 29, 2017

Finally, got it working... but using OpenAL static version (libopenal.a).

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 (libraylib.so).

EDIT: Checking documentation, adding additional shared libraries (libopenal.so, libraylib.so) to APK to be used by main shared library (libraylib_game.so) shouldn't be a problem; just placing the additional libraries into lib/armeabi-v7a directory and link to them on libraylib_game.so generation should be enough... but it didn't work...

I'll try this more carefully, maybe some missing compilation/linkage parameter...

@raysan5
Copy link
Owner Author

raysan5 commented Oct 3, 2017

Just kept working on shared libraries usage with no luck...

I build libraylib.so, libopenal.so and libraylib-game.so, linking the two first libraries into third one but it doesn't work... don't understand why... :(

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...

@gen2brain
Copy link
Contributor

gen2brain commented Oct 3, 2017

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
`# /opt/android-toolchain-arm7/bin/arm-linux-androideabi-objdump -p libopenal.so | grep SONAME

SONAME libopenal.so.1`

@raysan5
Copy link
Owner Author

raysan5 commented Oct 3, 2017

Hi @gen2brain! Thank you very much for the information! Just tried recompiling OpenAL Soft defining SONAME but result is still libopenal.so.1. Used following cmake line:

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 libopenal.so.1 in APK but it doesn't work... maybe it's an issue with Android version...

By the way, using static library versions (libraylib.a, libopenal.a, libnative_app_glue.a) it works great...

@gen2brain
Copy link
Contributor

What about SONAME for libraylib.so and libraylib-game.so ?

@raysan5
Copy link
Owner Author

raysan5 commented Oct 3, 2017

What about SONAME for libraylib.so and libraylib-game.so ?

Verified both, they are ok: libraylib.so, libraylib-game.so

Also added -ldl to linkage and tried everything again...

@raysan5
Copy link
Owner Author

raysan5 commented Oct 4, 2017

Just for reference, objdump info on the libraries... everything seems correct but still not working...

libopenal.so:

C:\GitHub\raylib\templates\android_project\lib\armeabi-v7a>C:\android_toolchain_arm_api16\bin\arm-linux-androideabi-objdump.exe -p libopenal.so

libopenal.so:     file format elf32-littlearm

Program Header:
0x70000001 off    0x000c5d7c vaddr 0x000c5d7c paddr 0x000c5d7c align 2**2
         filesz 0x000011f8 memsz 0x000011f8 flags r--
    LOAD off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**16
         filesz 0x000c700c memsz 0x000c700c flags r-x
    LOAD off    0x000d07dc vaddr 0x000d07dc paddr 0x000d07dc align 2**16
         filesz 0x000018c4 memsz 0x000019f4 flags rw-
 DYNAMIC off    0x000d1c20 vaddr 0x000d1c20 paddr 0x000d1c20 align 2**2
         filesz 0x00000110 memsz 0x00000110 flags rw-
    NOTE off    0x000c6f74 vaddr 0x000c6f74 paddr 0x000c6f74 align 2**2
         filesz 0x00000098 memsz 0x00000098 flags r--
   STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4
         filesz 0x00000000 memsz 0x00000000 flags rw-
   RELRO off    0x000d07dc vaddr 0x000d07dc paddr 0x000d07dc align 2**0
         filesz 0x00001824 memsz 0x00001824 flags r--

Dynamic Section:
  NEEDED               libOpenSLES.so
  NEEDED               libdl.so
  NEEDED               libm.so
  NEEDED               liblog.so
  NEEDED               libc.so
  SONAME               libopenal.so
  SYMBOLIC             0x00000000
  INIT_ARRAY           0x000d07dc
  INIT_ARRAYSZ         0x00000008
  FINI_ARRAY           0x000d07e4
  FINI_ARRAYSZ         0x0000000c
  HASH                 0x00000114
  STRTAB               0x00002694
  SYMTAB               0x00000be4
  STRSZ                0x000017cc
  SYMENT               0x00000010
  PLTGOT               0x000d1d30
  PLTRELSZ             0x000003a8
  PLTREL               0x00000011
  JMPREL               0x00006198
  REL                  0x00004218
  RELSZ                0x00001f80
  RELENT               0x00000008
  BIND_NOW             0x00000000
  FLAGS_1              0x00000001
  VERNEED              0x000041b8
  VERNEEDNUM           0x00000003
  VERSYM               0x00003e60
  RELCOUNT             0x000003e7

Version References:
  required from libdl.so:
    0x00050d63 0x00 04 LIBC
  required from libm.so:
    0x00050d63 0x00 03 LIBC
  required from libc.so:
    0x00050d63 0x00 02 LIBC
private flags = 5000202: [Version5 EABI] [soft-float ABI] [has entry point]

libraylib.so:

C:\GitHub\raylib\templates\android_project\lib\armeabi-v7a>C:\android_toolchain_arm_api16\bin\arm-linux-androideabi-objdump.exe -p libraylib.so

libraylib.so:     file format elf32-littlearm

Program Header:
0x70000001 off    0x00056360 vaddr 0x00056360 paddr 0x00056360 align 2**2
         filesz 0x00001368 memsz 0x00001368 flags r--
    LOAD off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**16
         filesz 0x00057760 memsz 0x00057760 flags r-x
    LOAD off    0x00060b00 vaddr 0x00060b00 paddr 0x00060b00 align 2**16
         filesz 0x00000808 memsz 0x00001d6c flags rw-
 DYNAMIC off    0x00060b3c vaddr 0x00060b3c paddr 0x00060b3c align 2**2
         filesz 0x00000130 memsz 0x00000130 flags rw-
    NOTE off    0x00000134 vaddr 0x00000134 paddr 0x00000134 align 2**2
         filesz 0x00000024 memsz 0x00000024 flags r--
    NOTE off    0x000576c8 vaddr 0x000576c8 paddr 0x000576c8 align 2**2
         filesz 0x00000098 memsz 0x00000098 flags r--
   STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4
         filesz 0x00000000 memsz 0x00000000 flags rw-
   RELRO off    0x00060b00 vaddr 0x00060b00 paddr 0x00060b00 align 2**0
         filesz 0x00000500 memsz 0x00000500 flags r--

Dynamic Section:
  NEEDED               libopenal.so
  NEEDED               liblog.so
  NEEDED               libandroid.so
  NEEDED               libEGL.so
  NEEDED               libGLESv2.so
  NEEDED               libOpenSLES.so
  NEEDED               libc.so
  NEEDED               libm.so
  NEEDED               libdl.so
  SONAME               libraylib.so
  SYMBOLIC             0x00000000
  INIT_ARRAY           0x00060b00
  INIT_ARRAYSZ         0x00000004
  FINI_ARRAY           0x00060b04
  FINI_ARRAYSZ         0x00000008
  HASH                 0x00000158
  STRTAB               0x000048e0
  SYMTAB               0x00001630
  STRSZ                0x00003374
  SYMENT               0x00000010
  PLTGOT               0x00060c6c
  PLTRELSZ             0x000006e8
  PLTREL               0x00000011
  JMPREL               0x0000838c
  REL                  0x000082ec
  RELSZ                0x000000a0
  RELENT               0x00000008
  BIND_NOW             0x00000000
  FLAGS_1              0x00000001
  VERNEED              0x000082ac
  VERNEEDNUM           0x00000002
  VERSYM               0x00007c54
  RELCOUNT             0x00000012

Version References:
  required from libc.so:
    0x00050d63 0x00 03 LIBC
  required from libm.so:
    0x00050d63 0x00 02 LIBC
private flags = 5000202: [Version5 EABI] [soft-float ABI] [has entry point]

libraylib_game.so:

C:\GitHub\raylib\templates\android_project\lib\armeabi-v7a>C:\android_toolchain_arm_api16\bin\arm-linux-androideabi-objdump.exe -p libraylib_game.so

libraylib_game.so:     file format elf32-littlearm

Program Header:
0x70000001 off    0x00003a64 vaddr 0x00003a64 paddr 0x00003a64 align 2**2
         filesz 0x00000100 memsz 0x00000100 flags r--
    LOAD off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**16
         filesz 0x00003bfc memsz 0x00003bfc flags r-x
    LOAD off    0x00010d84 vaddr 0x00010d84 paddr 0x00010d84 align 2**16
         filesz 0x00000280 memsz 0x00000280 flags rw-
 DYNAMIC off    0x00010d90 vaddr 0x00010d90 paddr 0x00010d90 align 2**2
         filesz 0x00000138 memsz 0x00000138 flags rw-
    NOTE off    0x00000134 vaddr 0x00000134 paddr 0x00000134 align 2**2
         filesz 0x00000024 memsz 0x00000024 flags r--
    NOTE off    0x00003b64 vaddr 0x00003b64 paddr 0x00003b64 align 2**2
         filesz 0x00000098 memsz 0x00000098 flags r--
   STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4
         filesz 0x00000000 memsz 0x00000000 flags rw-
   RELRO off    0x00010d84 vaddr 0x00010d84 paddr 0x00010d84 align 2**0
         filesz 0x0000027c memsz 0x0000027c flags r--

Dynamic Section:
  NEEDED               libraylib.so
  NEEDED               libopenal.so
  NEEDED               liblog.so
  NEEDED               libandroid.so
  NEEDED               libEGL.so
  NEEDED               libGLESv2.so
  NEEDED               libOpenSLES.so
  NEEDED               libc.so
  NEEDED               libm.so
  NEEDED               libdl.so
  SONAME               libraylib_game.so
  SYMBOLIC             0x00000000
  INIT_ARRAY           0x00010d84
  INIT_ARRAYSZ         0x00000004
  FINI_ARRAY           0x00010d88
  FINI_ARRAYSZ         0x00000008
  HASH                 0x00000158
  STRTAB               0x000009b0
  SYMTAB               0x000003e0
  STRSZ                0x000006be
  SYMENT               0x00000010
  PLTGOT               0x00010ec8
  PLTRELSZ             0x00000250
  PLTREL               0x00000011
  JMPREL               0x00001158
  REL                  0x00001148
  RELSZ                0x00000010
  RELENT               0x00000008
  BIND_NOW             0x00000000
  FLAGS_1              0x00000001
  VERNEED              0x00001128
  VERNEEDNUM           0x00000001
  VERSYM               0x0000106e
  RELCOUNT             0x00000001

Version References:
  required from libc.so:
    0x00050d63 0x00 02 LIBC
private flags = 5000202: [Version5 EABI] [soft-float ABI] [has entry point]

Do I miss something? I'm not an expert interpreting objdump info, maybe someone could spot some issue...

Still getting those lines on crash:

W/linker  (23038): libraylib_game.so: unused DT entry: type 0x6ffffffe arg 0x1128
W/linker  (23038): libraylib_game.so: unused DT entry: type 0x6fffffff arg 0x1

Those DT entries are related to VERNEED and VERNEEDNUM...

@skanti
Copy link

skanti commented Oct 4, 2017

I had a quick flick through but did you make sure

  • the dependencies are compiled for arm?
  • different linking order
  • tried out with static libraries
  • placed all dependencies in the apk

@raysan5
Copy link
Owner Author

raysan5 commented Oct 4, 2017

Hi @skanti, thanks for the answer!

the dependencies are compiled for arm?

Yes, the only dependencies are libraylib.so, libopenal.so and libnative_app_glue.a, all of them have been compiled for ARM-v7a using -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 compilation parameters.

tried out with static libraries

Yes, actually, it works great using static libraries, only fails when using shared libs.

placed all dependencies in the apk

Yes, all dependencies are placed in the required folder lib/armeabi-v7a

different linking order

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

@skanti
Copy link

skanti commented Oct 4, 2017

In Linux you cannot use shared libraries even when they are placed in the same folder, you require this LD_LIBRARY_PATH variable to be set for look-up. I can imagine for android it is not any different - it's Unix based after all.

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 openal later?)

EDIT: Any particular reason for -mfloat-abi=softfp -mfpu=vfpv3-d16? Not that it matters but just curious...

@raysan5
Copy link
Owner Author

raysan5 commented Oct 4, 2017

Hi @skanti, I'm going to check the LD_LIBRARY_PATH... how can I set it in my device? I think it should be something that comes defined within the APK... but I'm investigating a bit on that line...

Also trying reordering libs.

About compilation parameters, just read it here.

@raysan5
Copy link
Owner Author

raysan5 commented Oct 9, 2017

Finally got it working, using static (libraylib.a, libopenal.a) and also shared (libraylib.so, libopenal.so) libraries. Those are the only library dependencies for a raylib Android game (a part of standard C lib).

Using static libraries was "easy", just link them into libraylib_game.so and that library is automatically loaded by the android.app.NativeActivity class, library name can be defined in AndroidManifest.xml using the meta tag:

<meta-data android:name="android.app.lib_name" android:value="raylib_game" />

If not defined that meta tag, by default, it tries to load libmain.so. More info here.

Using shared libraries was not that easy, after lot of research, found the answer here. Basically, it says that additional shared libraries required by NativeActivity need to be loaded manually before main shared library. Proposed solution is extending NativeActivity class (NativeLoader.java):

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 AndroidManifest.xml, setting activity to NativeLoader and removing android:hasCode="false" value on application tag.

Additionally, NativeLoader.java needs to be added to command line javac compilation.

And voilà! raylib working in Android, as static and shared library.

@raysan5 raysan5 self-assigned this Oct 10, 2017
@raysan5
Copy link
Owner Author

raysan5 commented Oct 11, 2017

Keep working on it for a better integration with raylib build pipeline...

Planning to create a self-contained Makefile able to create a full Android project tree structure just from some C source files and resources folder.

@raysan5 raysan5 removed the help needed - please! I need help with this issue label Oct 11, 2017
@raysan5
Copy link
Owner Author

raysan5 commented Oct 14, 2017

Implemented in games templates.

@raysan5 raysan5 closed this as completed Oct 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Android Android platform
Projects
None yet
Development

No branches or pull requests

4 participants