Wintermute Engine Forum

Wintermute Engine => WME Lite => Topic started by: piere on October 23, 2015, 06:52:11 AM

Title: Android, how to set up project?
Post by: piere on October 23, 2015, 06:52:11 AM
Hello I followed the instructions here: http://res.dead-code.org/doku.php/wmelite:building

But they do not seem to tell me how to set up the Android project itself. Do I use Eclipse or Android Studio? I tried loading it into Android studio and it doesnt seem to want to take the Android source. Any help? Thanks.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 24, 2015, 10:52:15 AM
Hello I followed the instructions here: http://res.dead-code.org/doku.php/wmelite:building

But they do not seem to tell me how to set up the Android project itself. Do I use Eclipse or Android Studio? I tried loading it into Android studio and it doesnt seem to want to take the Android source. Any help? Thanks.

I don't use Android Studio to build, but you might try to generate a project if you like. There should be a wizard that helps you with that. I use the standalone tools to create a project with sth. like that

Code: [Select]
android update project --path=.

and to build I then use ant:

Code: [Select]
ant clean debug

should build a version with your debug developer key, and you can install it to an attached device (or emulator) with

Code: [Select]
ant installd

If you've never worked a lot on the command line, trying to generate an Android Studio project might be the better way to go. I'm not sure you would want to use Eclipse, as this is no longer supported by Google for quite a while now (I wonder whether you'll still find an Eclipse based Android IDE at all).
Title: Re: Android, how to set up project?
Post by: piere on October 24, 2015, 12:00:53 PM
Thanks for the reply. I didnt see any Wizard for Android Studio, I just created a new project and dragged and dropped the WME files in the project files. Changes the Manafest file, etc, but it did not work. So I would use the command line from files already in the WME Android source, or get it form somewhere else? Sorry for the questions, as I am new to Android development.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 24, 2015, 01:27:19 PM
You just need the "android" tool from the SDK, and probably you need to install "ant" separately. If you already downloaded Android Studio, the SDK is already installed (somewhere).
Title: Re: Android, how to set up project?
Post by: piere on October 25, 2015, 01:13:42 AM
Hi again. I am using Ant, and the commands listed in your message. After doing debug, it mentions the build.XML file, but nothing is generating a .apk file. Am I missing something? I am really stupid when it comes to the command line and Android development, so maybe you can explain a very beginners guide? I will be happy to donate to you some money if it works.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 25, 2015, 10:25:18 AM
This should work for you with a recent wmelite checkout:

Code: [Select]
hg status .

in wmelite/android shows that all my local modifications are the native libraries added:

Code: [Select]
daniel@androiduser-Aspire-V3-772:~/wmelite/android$ hg status .
? libs/AdBuddiz-2.4.4.jar
? libs/armeabi-v7a/libSDL2.so
? libs/armeabi-v7a/libbass.so
? libs/armeabi-v7a/libfreeimage.so
? libs/armeabi-v7a/libgnustl_shared.so
? libs/armeabi-v7a/libmain.so
? libs/armeabi/libSDL2.so
? libs/armeabi/libbass.so
? libs/armeabi/libfreeimage.so
? libs/armeabi/libgnustl_shared.so
? libs/armeabi/libmain.so
? libs/x86/libSDL2.so
? libs/x86/libbass.so
? libs/x86/libfreeimage.so
? libs/x86/libgnustl_shared.so
? libs/x86/libmain.so

At first a file called "local.properties" is required:

Code: [Select]
daniel@androiduser-Aspire-V3-772:~/wmelite/android$ android update project --path .
Updated local.properties
Updated file ./proguard-project.txt

Now all should be set for a debug build with ant:

Code: [Select]
daniel@androiduser-Aspire-V3-772:~/wmelite/android$ ant clean debug
Buildfile: /home/daniel/wmelite/android/build.xml

-check-env:
 [checkenv] Android SDK Tools Revision 24.4.0
 [checkenv] Installed at /opt/android/android-sdk-linux

-setup:
     [echo] Project Name: SDLActivity
  [gettype] Project Type: Application

-pre-clean:

clean:
[getlibpath] Library dependencies:
[getlibpath] No Libraries
   [subant] No sub-builds to iterate on

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 24.4.0
 [checkenv] Installed at /opt/android/android-sdk-linux

-setup:
     [echo] Project Name: SDLActivity
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.1.0
     [echo] Resolving Build Target for SDLActivity...
[gettarget] Project Target:   Android 4.0.3
[gettarget] API level:        15
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /home/daniel/wmelite/android/bin
    [mkdir] Created dir: /home/daniel/wmelite/android/bin/res
    [mkdir] Created dir: /home/daniel/wmelite/android/bin/rsObj
    [mkdir] Created dir: /home/daniel/wmelite/android/bin/rsLibs
    [mkdir] Created dir: /home/daniel/wmelite/android/gen
    [mkdir] Created dir: /home/daniel/wmelite/android/bin/classes
    [mkdir] Created dir: /home/daniel/wmelite/android/bin/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for SDLActivity...
[dependency] Ordered libraries:
[dependency]
[dependency] ------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
     [echo] ----------
     [echo] Building Libraries with 'debug'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 5 source files to /home/daniel/wmelite/android/bin/classes
    [javac] Note: /home/daniel/wmelite/android/src/org/libsdl/app/SDLActivity.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.

-post-compile:

-obfuscate:

-dex:
      [dex] input: /home/daniel/wmelite/android/bin/classes
      [dex] input: /opt/android/android-sdk-linux/tools/support/annotations.jar
      [dex] input: /home/daniel/wmelite/android/libs/AdBuddiz-2.4.4.jar
      [dex] Pre-Dexing /opt/android/android-sdk-linux/tools/support/annotations.jar -> annotations-2da80f7fba88282179c6a4e41fc58588.jar
      [dex] Pre-Dexing /home/daniel/wmelite/android/libs/AdBuddiz-2.4.4.jar -> AdBuddiz-2.4.4-be83e5349564857c26edd123b8ec492c.jar
      [dex] Converting compiled files and external libraries into /home/daniel/wmelite/android/bin/classes.dex...
       [dx] Merged dex A (32 defs/39,1KiB) with dex B (2 defs/1,1KiB). Result is 34 defs/46,1KiB. Took 0,1s
       [dx] Merged dex A (34 defs/46,1KiB) with dex B (75 defs/95,4KiB). Result is 109 defs/160,9KiB. Took 0,1s

-crunch:
   [crunch] Crunching PNG Files in source dir: /home/daniel/wmelite/android/res
   [crunch] To destination dir: /home/daniel/wmelite/android/bin/res
   [crunch] Processing image to cache: /home/daniel/wmelite/android/res/drawable-hdpi/ic_launcher.png => /home/daniel/wmelite/android/bin/res/drawable-hdpi/ic_launcher.png
   [crunch]   (processed image to cache entry /home/daniel/wmelite/android/bin/res/drawable-hdpi/ic_launcher.png: 0% size of source)
   [crunch] Processing image to cache: /home/daniel/wmelite/android/res/drawable-mdpi/ic_launcher.png => /home/daniel/wmelite/android/bin/res/drawable-mdpi/ic_launcher.png
   [crunch]   (processed image to cache entry /home/daniel/wmelite/android/bin/res/drawable-mdpi/ic_launcher.png: 0% size of source)
   [crunch] Processing image to cache: /home/daniel/wmelite/android/res/drawable-xhdpi/ic_launcher.png => /home/daniel/wmelite/android/bin/res/drawable-xhdpi/ic_launcher.png
   [crunch]   (processed image to cache entry /home/daniel/wmelite/android/bin/res/drawable-xhdpi/ic_launcher.png: 105% size of source)
   [crunch] Processing image to cache: /home/daniel/wmelite/android/res/drawable-xxhdpi/ic_launcher.png => /home/daniel/wmelite/android/bin/res/drawable-xxhdpi/ic_launcher.png
   [crunch]   (processed image to cache entry /home/daniel/wmelite/android/bin/res/drawable-xxhdpi/ic_launcher.png: 59% size of source)
   [crunch] Crunched 4 PNG files to update cache

-package-resources:
     [aapt] Creating full resource package...

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating SDLActivity-debug-unaligned.apk and signing it with a debug key...

-post-package:

-do-debug:
 [zipalign] Running zip align on final apk...
     [echo] Debug Package: /home/daniel/wmelite/android/bin/SDLActivity-debug.apk
[propertyfile] Creating new property file: /home/daniel/wmelite/android/bin/build.prop
[propertyfile] Updating property file: /home/daniel/wmelite/android/bin/build.prop
[propertyfile] Updating property file: /home/daniel/wmelite/android/bin/build.prop
[propertyfile] Updating property file: /home/daniel/wmelite/android/bin/build.prop

-post-build:

debug:

BUILD SUCCESSFUL
Total time: 21 seconds

I added the complete console output, for you to check at which point it differs at your side. I have not added any game data, so my app would finally not do anything when started. For small game packages, just add game data as assets (renamed to .png, like described in the wiki).

Now you should be able to install the debug build with

Code: [Select]
daniel@androiduser-Aspire-V3-772:~/wmelite/android$ ant installd
Buildfile: /home/daniel/wmelite/android/build.xml

-set-mode-check:

-set-debug-files:

install:
     [echo] Installing /home/daniel/wmelite/android/bin/SDLActivity-debug.apk onto default emulator or device...
     [exec] error: device '(null)' not found
     [exec] - waiting for device -

I do not have a device connected right now, otherwise the app would install (you need to enable developer settings and USB debugging).

Hope it helps.
Title: Re: Android, how to set up project?
Post by: piere on October 25, 2015, 11:28:28 AM
Thanks for the reply, but None of that makes any sense to me. I have never used Android, or command line in my life so I am really confused. Do I move the Ant files into my directory for the WME Android project or do I run it in the Ant directory? Where does the Java directory come into play? So I open the command prompt, then what? Sorry for all the questions and thanks.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 25, 2015, 12:58:01 PM
I can't give you a complete guide on how to setup your system. But basically, you need to install Java and then ant. For Linux, you simply use the package manager of the distribution. For Windows, you can download an .exe file for installing Java. Then you can download and install ant as per the instructions on the ant website (here http://ant.apache.org/manual/install.html#installing are generic install instructions).

Your install was successful, if you open a command prompt, and type "java" without an error message (like "command not found"), and then repeat the same for "ant".

Finally, the Android SDK (whether installed standalone or in combination with Android Studio) should be in your path as well, so that when you type "android", something else than an error message appears (typically the "Android SDK Manager" GUI should appear). If it doesn't, you should add the "tools" subdirectory from the base directory of the Android SDK to your path, then it should work. (I have set my path as follows:
Code: [Select]
export PATH=$PATH:/opt/android/android-sdk-linux/platform-tools/:/opt/android/android-sdk-linux/tools/ to have both "android" and "adb" (you might need that one later) available in Linux.)

If these commands are available in your command prompt, the build instructions should work. Just go to the "wmelite/android" directory and type the commands.


Title: Re: Android, how to set up project?
Post by: piere on October 25, 2015, 01:05:10 PM
Ok I typed "java" into the command prompt and it comes up, but "android" and "ant" do not. Do I need to put those directories somewhere specifically? When you mentioned to "add the "tools" subdirectory from the base directory of the Android SDK to your path", I am unsure what you meant by that. Do I enter that code you wrote into command prompt? What does that code do? Sorry I am very confused at that point. I am using Windows by the way if that makes a difference. Thanks.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 25, 2015, 01:34:34 PM
Let me dig out my old windows vista pc, then I'll see how to do this on windows.
Title: Re: Android, how to set up project?
Post by: piere on October 25, 2015, 10:54:18 PM
Thanks you rock  ::rock
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 26, 2015, 07:01:41 AM
Ant installation on Windows (Vista):

Title: Re: Android, how to set up project?
Post by: HCDaniel on October 26, 2015, 07:15:33 AM
Android SDK standalone install on Windows (Vista):

Title: Re: Android, how to set up project?
Post by: piere on October 26, 2015, 10:03:42 AM
Ok thanks, I got all that working now. Everytime I try to build the project though, it keeps saying that there is no Build.xml file. But the xml file is there, so I am thinking it keeps looking in the wrong place for it ??
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 26, 2015, 10:24:07 AM
You have a typo. The class is called "FartBlackJack" but the file has the name "FartBlackack.java". Class name and file name must match.
Title: Re: Android, how to set up project?
Post by: piere on October 26, 2015, 10:35:07 AM
So which should I change then?
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 26, 2015, 10:47:04 AM
No, just change the filename to "FartBlackJack.java" (add the missing capital "J").
Title: Re: Android, how to set up project?
Post by: piere on October 26, 2015, 11:12:35 AM
So I got it all working and added the .apk file, then tested it on my phone. Every time it opens on my phone it says Unfortionetly it has stopped working, so basically it always crashes. I thought it was my game, so I created a sample project in WME and that is crashing too. Any suggestions?
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 26, 2015, 11:26:50 AM
Can you paste the relevant section of your android log? You can capture it by using "adb logcat" on the shell. I need the log of around the time when the game stops working.

Typical mistakes could be missing native libraries, or missing game data (if you added it in the assets/raw folder, you should update "WMELiteFunctions.java" as described in the wiki).

Maybe it is something else though. The log should tell.
Title: Re: Android, how to set up project?
Post by: piere on October 26, 2015, 11:37:20 AM
Hello, I did that and it just says "waiting for device" then nothing happens, even with my phone plugged in. I private messaged you a link to my project file to check out directly.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 26, 2015, 01:29:57 PM
Unfortunately I can't check your project right now. Sooner or later you will need a working "adb" anyway, so please try to get this one working.

You need to install a driver for your device, apart from the standard functionality of accessing files on the phone storage. Sometimes, Windows will prompt you to do so. Once you have "USB debugging" enabled on your device (in the developer settings), check that a driver for the "adb interface" is installed. If not, try to get the driver from the manufacturer website, or try to force the Google driver (somewhere in the SDK) to be installed instead.

As a bonus, "ant installd" will then automatically install and run your app.
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 27, 2015, 06:55:10 AM
I found this error in the log file:

Code: [Select]
E/AndroidRuntime(11427): FATAL EXCEPTION: main

E/AndroidRuntime(11427): Process: org.CopelandGames.FartBlackjack, PID: 11427

E/AndroidRuntime(11427): java.lang.UnsatisfiedLinkError: Native method not found: org.libsdl.app.SDLActivity.nativeAddHintCallback:(Ljava/lang/String;Lorg/libsdl/app/SDLActivity$SDLHintCallback;)V

E/AndroidRuntime(11427): at org.libsdl.app.SDLActivity.nativeAddHintCallback(Native Method)

E/AndroidRuntime(11427): at org.libsdl.app.SDLActivity.onCreate(SDLActivity.java:189)

E/AndroidRuntime(11427): at android.app.Activity.performCreate(Activity.java:5585)

E/AndroidRuntime(11427): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)

E/AndroidRuntime(11427): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)

E/AndroidRuntime(11427): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)

E/AndroidRuntime(11427): at android.app.ActivityThread.access$900(ActivityThread.java:170)

E/AndroidRuntime(11427): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)

E/AndroidRuntime(11427): at android.os.Handler.dispatchMessage(Handler.java:102)

E/AndroidRuntime(11427): at android.os.Looper.loop(Looper.java:146)

E/AndroidRuntime(11427): at android.app.ActivityThread.main(ActivityThread.java:5635)

E/AndroidRuntime(11427): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime(11427): at java.lang.reflect.Method.invoke(Method.java:515)

E/AndroidRuntime(11427): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)

E/AndroidRuntime(11427): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)

E/AndroidRuntime(11427): at dalvik.system.NativeStart.main(Native Method)

This looks like a mismatch of native libraries and the SDLActivity Java class. Now that I think about it, you were probably using the dependency package on bitbucket, which is out of date. I need to update and test the original WME on Android again (was only working on my branch lately). I hope I'll find the time to do that in the coming days.
Title: Re: Android, how to set up project?
Post by: piere on October 27, 2015, 07:04:46 AM
Is there any way I can use a different package to make it work?
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 27, 2015, 07:32:20 AM
You could use my branch, but that would mean compiling all native libraries from source. With a working Android NDK install (and Cygwin for Windows) this is doable, but probably quite a hassle if you haven't done it before.
Title: Re: Android, how to set up project?
Post by: piere on October 27, 2015, 07:42:18 AM
Can I pay you to compile it for  me?
Title: Re: Android, how to set up project?
Post by: HCDaniel on October 27, 2015, 07:54:00 AM
It's not about money. I don't have a lot of time at the moment (working on releasing a game this week). Let's see if everything works well, then I can spend some more time on wmelite soon.
Title: Re: Android, how to set up project?
Post by: HCDaniel on November 01, 2015, 11:16:40 AM
I have updated the dependencies package and the repo on bitbucket (original wmelite project). Your game template now works for me. Please update repo and dependencies, then you can try it out.
Title: Re: Android, how to set up project?
Post by: piere on November 06, 2015, 10:32:45 AM
Hey, I am using the new dep files you upload. Now when I try to do ant debug, I get the following error:

(http://img.ctrlv.in/img/15/11/06/563c737b23920.jpg)
Title: Re: Android, how to set up project?
Post by: HCDaniel on November 06, 2015, 01:09:13 PM
Hmm, that is really strange. The dependencies package only replaces the files in the "libs" folder, the "AndroidManifest.xml" should remain untouched.

Also pretty strange is how the "AndroidManifest.xml" ended up in your "bin" folder.

Can you try an "ant clean" before "ant debug"?
Title: Re: Android, how to set up project?
Post by: piere on November 07, 2015, 09:48:31 AM
Yes I did that. No change :( Any Way I can get you to compile the final apk for me?
Title: Re: Android, how to set up project?
Post by: HCDaniel on November 07, 2015, 01:45:21 PM
Yes I did that. No change :( Any Way I can get you to compile the final apk for me?

Can you check whether you have any local modifications to files - modifications which "do not look correct"? ("hg diff" would tell, resp. the appropriate TortoiseHG command)

Certainly I could build a debug .apk for you - just send me your .dcp file(s) and tell me the app's canonical name (like "com.mydomain.mygame.MyGameTitle"). This would be fine for your local tests (as it would be signed with my "debug key").

To finally publish an app, you need to sign it with your "release key", and that is one you better keep secret ;-) So in the end we need to get the toolchain working for you, even if I can help you out in the meantime.
Title: Re: Android, how to set up project?
Post by: piere on November 07, 2015, 02:03:25 PM
Thanks I will get my .apk ready. What is the best resolution to make the game in Wintermute to look best on Android?
Title: Re: Android, how to set up project?
Post by: HCDaniel on November 07, 2015, 03:06:51 PM
That I can't really tell. Android devices come in a variety of (native) resolutions. Whatever looks good on one device, might look bad on another. You need to check several devices. The Android emulator allows to configure screen size and resolution (not sure if 100% freely, but you have several options), so you can check there as well.

For our project we historically decided for 1024x600. That looks good on a variety of devices, independent of their native resolution (wmelite will scale the picture to fullscreen, keeping only the acpect ratio - thus a ratio of around 16:9 should be used to keep the black bars at the side of the screen small).

More important was the use of the "pixelperfect" rendering option in the "settings.xml", as we could not afford inaccuracies of graphics when they were all individually scaled when being drawn. That option is on one hand very memory intensive (you need a back buffer of your graphics in original resolution and depth in memory additionally), but avoids scaling artifacts between individual graphics. It depends on how you arrange your graphics, whether you actually need this option. It should be kept off if not necessary.
Title: Re: Android, how to set up project?
Post by: piere on November 09, 2015, 12:38:45 AM
I have the APK ready. Any way you can sign it for me? I still can't get anything working on my side.
Title: Re: Android, how to set up project?
Post by: HCDaniel on November 09, 2015, 01:32:13 PM
Just send me your .dcp files (I assume that's what you meant) and the desired canonical name of your app, then I can send you a "debug APK" for testing.
Title: Re: Android, how to set up project?
Post by: piere on November 13, 2015, 09:59:33 AM
Sent you a private message :)