Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Android and iOS ports available for testing  (Read 338676 times)

0 Members and 1 Guest are viewing this topic.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: Android and iOS ports available for testing
« Reply #375 on: June 05, 2015, 08:31:51 am »
Is it possible to use more than one Java VM in the app? I don't know why. =) Well, I think that static "JavaEnvironment" is good enough if there is only one JVM.
« Last Edit: June 05, 2015, 08:39:40 am by ChronicRat »

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Android and iOS ports available for testing
« Reply #376 on: June 07, 2015, 10:08:46 am »
I've built SFML for Android and I get a "Failed to activate window's context" error when I launch the "android" example inside my Nexus 7 2013. Do you have an idea about what's wrong ?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Android and iOS ports available for testing
« Reply #377 on: June 07, 2015, 10:15:08 am »
That "error" is completely fine. Right now you should get it a few times till your app is actually shown on screen. If your app doesn't show up, gets stuck or crashes, the issue is mostl ikely some other line in your logcat output.

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Android and iOS ports available for testing
« Reply #378 on: June 07, 2015, 10:25:38 am »
Thanks for your answer. Nothing shows on the screen (except the app title and the default background color). But I see an error coming from the "canary.wav". So I removed the lines playing the sound and it works perfectly.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Android and iOS ports available for testing
« Reply #379 on: June 07, 2015, 11:52:29 am »
It's a bug with sound loading in 2.3, see a few pages ago. There's a branch and pull request on GitHub if you'd like to try a fix.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: Android and iOS ports available for testing
« Reply #380 on: July 22, 2015, 01:19:28 pm »
Btw, to get unicode (non-english, while it's impossible in pure NDK) value use Java:
public class AppActivity extends NativeActivity
{
        // transfer unicode value to C++
        public static native void UnicodeValueCPP(int value);

        // we are using this to catch non-ascii chars (yes, it is impossible in NDK)
        @Override
        public boolean dispatchKeyEvent(KeyEvent event)
        {
                String chars = event.getCharacters();

                if (chars != null && !chars.isEmpty())
                {
                        UnicodeValueCPP(chars.codePointAt(0));
                }
                return super.dispatchKeyEvent(event);
        }
};
 
You just need to change in manifest file android.app.NativeActivity to .AppActivity.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Android and iOS ports available for testing
« Reply #381 on: July 22, 2015, 03:54:19 pm »
Yeah, well, only problem, there's no Java code in SFML (it's a 100% native activity). Not sure this event can somehow be overridden.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: Android and iOS ports available for testing
« Reply #382 on: July 22, 2015, 04:10:34 pm »
But SFML has NativeActivty. This method overrides it. Be sure, I tested it before posting here. =) You have to create subfolder 'src/com/company/application', AppActivity.java there - and it will work. Especially it can be easily done with nVidia AndroidWorks.
upd: Well, I'm not 100% sure about String method 'codeAtPoint', but the string value of getCharacters is absolutly correct - it contains unicode char of pressed key.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Android and iOS ports available for testing
« Reply #383 on: July 22, 2015, 05:59:27 pm »
Okay, so you can still override those despite explicitly using the native activity? That's interesting, although an ugly workaround. Maybe it's possible to inject the code at runtime. :)

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: Android and iOS ports available for testing
« Reply #384 on: July 22, 2015, 09:24:11 pm »
Maybe it's possible to inject the code at runtime. :)
I think it's possible.
https://community.oracle.com/thread/2298550
« Last Edit: July 24, 2015, 10:07:43 am by ChronicRat »

zmertens

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Android and iOS ports available for testing
« Reply #385 on: August 02, 2015, 01:29:10 am »
I'm interested in learning how to set up the SFML for Android build. I'm using the tutorial from the wiki and I ran into an error while running cmake:

(click to show/hide)

I checked and double checked my PATH variables to see that they pointed to the Android SDK directories and NDK. My directories are set up like /example/SFML/ and then /example/SFML-build-mobile and I am using CMake-GUI.
I have been able to run SDL's sample android project so I 'm sure ndk-build is working at least for that project.

I'm using CMake 2.8.12.2, Linux Mint 17.2, and I'm building off the SFML master branch (26fc872844) if that helps any.

-- An idea just popped into my head, do I need a specific Android SDK API level? I only have 18 and 21 or 22 right now.
The truth will set you free but first it will piss you off.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Android and iOS ports available for testing
« Reply #386 on: August 02, 2015, 09:45:41 am »
CMake won't check your PATH environment variable for cross-compiling (bad things might happen!). Instead you have to set ANDROID_NDK to point there (or pass it as a CMake variable).

zmertens

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Android and iOS ports available for testing
« Reply #387 on: August 02, 2015, 09:41:55 pm »
Well, I got it all figured it out and I got the example program running on my phone using Android Studio (My phone is a LGL41C with Android version 4.4.2). I had to create the project manually in Android Studio which was not hard at all since I had played around with the NDK already. I couldn't import the SFML android example though because Gradle couldn't be configured from the project, so I just copied everything over by hand. I also added the JNI stuff to my app build.gradle file so it looks like this:

(click to show/hide)

I followed information from this Stack Overflow Q

I couldn't hear any sound from the example but I was able to move the icon around with my hand. I hope to play around with it more later on.

I am getting spammed about an error: "Failed to activate window's context" which I think I have seen mentioned here already several times and not to worry about it.

Last, I have a quick CMake question. Is there some way I can use CMake-GUI to build the libraries (armeabi, mips, etc)? I tried to by adding the variables that I normally would use from command line and it couldn't seem to figure out I wanted Android and not desktop SFML, so I'm probably not adding the right variables. I had no issues using the command line CMake from the example after following Mario's suggestion above.

The truth will set you free but first it will piss you off.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Android and iOS ports available for testing
« Reply #388 on: August 03, 2015, 12:07:13 am »
I'm usually using a small batch file to build and install all architectures at once, I'm sure you can use that to figure out the correct parameters:

@echo off
set ANDROID_NDK=E:/Android/NDK
set ANDROID_SDK=E:/Android
for /D %%D in (*.) do (cd %%D && (mingw32-make install || (cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../../../cmake/toolchains/android.toolchain.cmake -DANDROID_ABI=%%D -DANDROID_API_MIN=9 -DCMAKE_BUILD_TYPE=Release -DANDROID_STL=c++_shared ../../.. && mingw32-make install)) && cd ..)

This obviously only works for Windows, but you can do similar things on other systems.

What this does is compiling all architectures identified by the name of the sub folders right next to this script. E.g. to build "armeabi" and "x86" I just create two folders with those names and run it.

Kori

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Android and iOS ports available for testing
« Reply #389 on: October 13, 2015, 10:48:00 am »
Excellent work, until now everything works fine. Only i don't know how to hide navigation bar (this on bottom) on tablet devices. Anyone help?