Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] al_android_set_apk_file_interface

This thread is locked; no one can reply to it. rss feed Print
[A5] al_android_set_apk_file_interface
Eric Johnson
Member #14,841
January 2013
avatar

Hey there. I'm throwing together a small Android project and have not been able to procure image files from within my compiled APK. Thankfully, I saw that the wiki had some Android-specific code that fit would the bill: al_android_set_apk_file_interface.

I thought all would be well if I included the appropriate file and called the function, but my compiler thought otherwise.

example.cpp#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_android.h> 3 4int main(void) { 5 6 al_init(); 7 8 al_android_set_apk_file_interface(); 9 10 return 0; 11}

The above, when compiled with g++ on Ubuntu 13.04 (using Allegro 5.1.8), returned "undefined reference to `al_android_set_apk_file_interface'". It acknowledges allegro_android.h's existence, but not the function's purpose.

allegro_android.h#SelectExpand
1/* ______ ___ ___ 2 * /\ _ \ /_ \ /_ \ 3 * \ \ \L\ \//\ \ //\ \ __ __ _ __ ___ 4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `/`'__/ __`\ 5 * \ \ /\ \ _\ _ _\ _/\ __//\ \L\ \ \ //\ \L\ \ 6 * \ _\ _/____/____\ ____\ ____ \ _\\ ____/ 7 * /_//_//____//____//____//___L\ /_/ /___/ 8 * /____/ 9 * _/__/ 10 * 11 */ 12 13 14#ifndef A5_ANDROID_ALLEGRO_H 15#define A5_ANDROID_ALLEGRO_H 16 17#ifdef __cplusplus 18 extern "C" { 19#endif 20 21/* 22 * Public android-related API 23 */ 24void al_android_set_apk_file_interface(void); 25const char *al_android_get_os_version(void); 26 27/* XXX decide if this should be public */ 28void _al_android_set_capture_volume_keys(ALLEGRO_DISPLAY *display, bool onoff); 29 30#ifdef __cplusplus 31 } 32#endif 33 34#endif /* A5_ANDROID_ALLEGRO_H */

As you can see, the function exists but lacks a code body. My guess is that it is to be used as an include elsewhere. So then, what should I do to get this function working properly?

I would greatly appreciate your feedback and/or suggestions. Thank you. :)

Edit (13.09.06 at 21:39 PST)
Let's forget g++ for the time being. The code compiled without issue for Android. Here's my new code:

newexample.cpp#SelectExpand
1#include "../inc/thaed.hpp" 2 3ALLEGRO_BITMAP *b; // Our bitmap 4 5// ================================================================================ 6// Execute the application 7// ================================================================================ 8Thaed::Thaed(void) { 9 10 BombuEstablish(160, 90); 11 12 al_android_set_apk_file_interface(); 13 14 // Attempt to procure alexlogo.png from within Android's assets directory 15 b = al_load_bitmap("alexlogo.png"); 16 17 al_set_standard_file_interface(); 18 19 BombuGoToLoop(); 20} 21 22// Later on when it is time to draw... 23 24// ================================================================================ 25// Render objects and their images to the display 26// ================================================================================ 27void Thaed::DrawToDisplay(void) { 28 29 // Only draws if the file was procured. 30 if (b) al_draw_bitmap(b, 100, 100, 0); 31}

Still, it can't locate the image file. Any ideas? :-/

Trent Gamblin
Member #261
April 2000
avatar

It doesn't compile with g++ because it's Android code; you need to use the Android compiler, which you've done now. Why are you using words like procure. Anyway, show more code or debug with ALLEGRO_DEBUG("Some printf style messages\n"); after putting "ALLEGRO_DEBUG_CHANNEL("MyAppName")" at the top of your file after including allegro5.h. Then use adb logcat to view the messages.

Eric Johnson
Member #14,841
January 2013
avatar

Hey Trent. Thanks for the reply.

Yeah, I already figured that one out. And you're right about "procure"; "load" would have been better. Now, how might I include this in my code if I also wanted to compile for Linux?

someexample.cpp#SelectExpand
1if (compiling_for_android) { 2 3 // Use Android-specific code since we're compiling for Android 4 al_android_set_apk_file_interface(); 5} 6else { 7 8 // Compiling for general OS (Windows, Mac, Linux) 9 some_function_to_set_the_path_for_desktops(); 10}

I'm going to try out the Android example first. I already compiled and installed it on my OUYA with ease, but I have no way of seeing the debug messages yet. Running adb devices doesn't show my OUYA, so I don't know what's the matter there. Some say you need the Google USB Driver installed from the Android SDK Manager, but I am on Ubuntu 13.04 and those drivers aren't Linux compatible.

When building Monster RPG 2 for OUYA, how did you do it? Did you use adb wirelessly or connect your machine to OUYA via USB cable? Also, which OS did you use to do so?

I may have to go out and purchase an appropriate cable soon to pull this off. What do you suggest?

Trent Gamblin
Member #261
April 2000
avatar

#ifdef ALLEGRO_ANDROID
// android code here
#else
// other code here
#endif

I use a USB cable since the OUYA is right on my desk.

Eric Johnson
Member #14,841
January 2013
avatar

Ha, how simple of a solution. Thanks, Trent.

Okay, I'll have to buy a cable then. What OS did you port for OUYA on? Just curious.

Trent Gamblin
Member #261
April 2000
avatar

Windows 7.

Eric Johnson
Member #14,841
January 2013
avatar

Oh, all right. I had some worries about compatibility with Linux, but good news: I'm now connected to my OUYA via USB cable! :D

Okay. Here's what the example debug message says about alexlogo.png:

Quote:

I/allegro ( 1161): bitmap W 1176: bitmap_io.c:243 al_load_bitmap_flags [ 0.07439] No handler for bitmap extensions .png - therefore not trying to load alexlogo.png.
I/allegro ( 1161): main D 1176: test.c:88 main [ 0.07441] failed to load alexlogo.png

Fairly self-explanatory; it doesn't have libpng, which I find to be weird. So now we know that is the issue. Does this mean I'll have to compile libpng for Android alongside the Android example: main.c?

Edit (13.09.08 at 21:38 PST)
I downloaded and built libpng for Android, which resulted in a libpng.a file. I threw this file into $HOME/android-toolchain/sysroot/usr/lib and include. I then recompiled the example project to and installed it on my OUYA. The log reveals that it still can not load the png file though; same message as above. What would you suggest I do?

Trent Gamblin
Member #261
April 2000
avatar

Rebuilds Allegro now that you have libpng installed. Link to libpng in your Android project.

Eric Johnson
Member #14,841
January 2013
avatar

I will try that, but first: how come it will load PNG files if executed from Ubuntu, but not from OUYA? I thought libpng was built alongside Allegro by default (thus I said "it doesn't have libpng, which I find to be weird."). Was I incorrect here?

Now then, in order to pull this off, all I would need to do now is build Allegro normally...

terminal log#SelectExpand
1cd $HOME/allegro 2mkdir build 3cd build 4sudo cmake .. 5sudo make 6sudo make install

Then build for Android thereafter?

pseudo log#SelectExpand
1ANDROID_NDK_TOOLCHAIN_ROOT=$HOME/android-toolchain /home/eric/android-ndk/ndk-build 2$HOME/android-sdk/tools/android update project . p --target android-18 3ant debug

Does that look about right?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

No - libpng comes separately, but is natively implemented on some platforms, but not Android apparently or at least not the OUYA. But if you delete CMakeCache.txt and rerun cmake it should find the installed libpng and install it into allegro's image addon.

Eric Johnson
Member #14,841
January 2013
avatar

Aah, okay. That makes sense. I have installed libpng-dev and zlib1g-dev. Will these suffice for libpng support once I build Allegro again?

Thomas Fjellstrom
Member #476
June 2000
avatar

only if you built them for android.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Eric Johnson
Member #14,841
January 2013
avatar

Check it out. I stumbled across this link for libpng for Android. I went into its folder and ran the following:

terminal log#SelectExpand
1./build.sh // This made a libpng.a file in ./obj/local/armeabi/ 2 3// Copy libpng.a to Android NDK directory 4cp ./obj/local/armeabi/libpng.a $HOME/android-ndk/platforms/android-18/arch-arm/usr/lib/libpng.a

I then added LOCAL_LDLIBS += -lpng to Application.mk. I threw it onto OUYA and ran adb logcat, but it still returns the same error. I'll keep looking into this.

Trent Gamblin
Member #261
April 2000
avatar

Please, for God's sake try to figure out some of these minor snags for yourself. Don't come back until you've figured it out. Learn to learn.

Arthur Kalliokoski
Second in Command
February 2005
avatar

try to figure out some of these minor snags for yourself. Don't come back until you've figured it out. Learn to learn.

Googling is OK, though. Indeed, it's encouraged.

They all watch too much MSNBC... they get ideas.

Eric Johnson
Member #14,841
January 2013
avatar

Please, for God's sake try to figure out some of these minor snags for yourself. Don't come back until you've figured it out. Learn to learn.

Please accept my sincere apology for my obtuse nature. It has been this year alone in which I've made the switch to UNIX-like systems and have made an effort to learn C++ and many other things. I am fairly new to these technologies and to Android. I have learned many things already on my own. I ask for assistance here specifically because I couldn't find sufficient information elsewhere.

Googling is OK, though. Indeed, it's encouraged.

I perform search queries quite often, actually. The primary reason I ask here is because some of the users here are especially knowledgeable when it comes to Allegro on Android devices.

Anyway, I tried a bitmap and it worked alright. Actually, the bitmap file was significantly smaller than the png one. Using al_convert_mask_to_alpha() on an 8x9 bitmap didn't work out so well on OUYA (it removed the entire image instead of the magic pink color), so that may just be a bug. It worked on 16x18 bitmaps though.I am going to opt for bmp files for the time being.

I'm going to set this as "resolved" soon enough. Feel free to add onto this until then.

Go to: