Page 1 of 7

Building an Android .apk -file

PostPosted: Thu Dec 29, 2011 11:02 pm
by lcl
Hello everyone,
I just got my first Android test running and I am now going to teach
you how it happens, be careful and follow the steps exactly.

Remember that the current version of geandroid is still unfinished and that the port is not ready and not optimized, so no one should actually use this for trying to make an actual game for Google Play store, but instead just for testing their game on their phone, which is still quite enjoyable :D

THIS TUTORIAL IS FOR WINDOWS, I don't know how it works on other platforms.
Steps 1 - 5 have to be done only on the first time building an .apk. Later on you can start from the step 6.

1) Download and extract GE Android, which you'll find here:
Code: Select all
http://www.mediafire.com/download/n2tyrtw999hy1o5/geandroid.zip

(Note that you have to be signed in to the game-editor.net for having the access to the file!)

2) Download and install Android SDK, you'll find it here:
Code: Select all
http://developer.android.com/sdk/index.html

Choose the one that's recommended. If it tells you to get Java SE Development Kit (JDK), get it.
Don't install it to Program Files (x86), because windows will not let it download what it has to download.

3) Download Apache Ant from here:
Code: Select all
http://www.softpedia.com/get/Programming/Other-Programming-Files/Apache-Ant.shtml

Extract the file.

4) Write a similar bat -file in Notepad or some other program:
(EDIT: If you have downloaded geandroid after 1.5.2014, your geandroid folder will already have a setup.bat -file. You can either modify it, or delete it and create a new one. You can't use the old one without modifying it, because it's configured for my computer.)
Code: Select all
set ANT_HOME=c:\apache-ant-1.8.2
set CLASSPATH=C:\jdk1.7.0_01\lib
set JAVA_HOME=c:\jdk1.7.0_01
set PATH=%path%;%ANT_HOME%\bin
set PATH=%path%;c:\android-sdk\tools

So, set ANT_HOME to be the path to the folder named exactly apache-ant-1.8.2. So, if you got a folder named apache-ant-1.8.2-bin, that's not the right one, in that folder there is a subfolder, which has the right name, be careful!
And for the CLASSPATH, you'll have to search where it has installed your JDK, and the lib-folder. It's most likely in C:\Program Files\Java\jdk1.7.0_02\lib
JAVA_HOME is the folder where you can find the lib-folder, so most likely: C:\Program FIles\Java\jdk1.7.0_02
The next line you can leave as it is.
And the last line, replace the c:\android-sdk\tools with your android-sdk tools folders location.

Save the file with the name setup.bat and in your geandroid -folder.

5) Open SDK manager.exe. (You can find it from the folder where you have installed the Android SDK.) Now select the selection box for 'Tools' and click 'Install packages'.
Then select some of the Androids (I selected 2.3.3, because that's what akr mentioned in game-editor.net), and click 'Install packages'.

6) Now copy your GE file (exported as .dat) and place it to geandroid\assets
Your file has to be named as geplayer.dat! (This may change to game-editor.dat!)

7) Search Command Prompt from your computer, it can be in: Start menu -> All Programs -> Accessories -> Command Prompt
(You can also just type "cmd" (without quotes) to the windows start menu search box and press enter, or press Windows key+R to open the "Run" dialog, and then write "cmd" (without quotes) there and press enter.)
Open it and type:
Code: Select all
cd C:\Downloads\geandroid

Replace the location with the location of your geandroid folder!
And press enter.

8) Now type:
Code: Select all
setup.bat

And press enter.

9) Now type:
Code: Select all
android update project -t 1 -p .

And press enter.
Write exactly as above, even a little mistake, and it gives you an error!

10) Now type:
Code: Select all
ant debug

And press enter.
It takes few seconds and then it should show the following text:
BUILD SUCCESSFUL

11) Now go to your geandroid -folder -> bin and there you should see a list of files named as: GEActivity... Search the one named as GEActivity-debug.apk and copy that to your phone.

12) Search the file from your phone (for that I suggest Astro File Manager. Just search Astro from the Android market), install it and...
ENJOY! :D

I hope this tutorial is good and tells you what to do accurately enough.
If you need help, just ask, and me or someone else will help you!

At last I want to say..
It may be demanding, but it's really rewarding too! :)


CUSTOMIZING YOUR APK: (NEW!)
With the help of ayushpal I have found some neat ways of customizing the app's properties.

Changing the application's name:
Go to geandroid -> res -> values and open the strings.xml with Notepad. You'll see this:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">ge</string>
</resources>

Replace 'ge' with the name of your app.

Changing the application's orientation
Go to geandroid-folder and open the AndroidManifest.xml with Notepad. With a little searching you will find this:
Code: Select all
android:screenOrientation="landscape"

Replace 'landscape' with 'portrait' in order to change the orientation.

Changing the application's icon
Go to geandroid -> res. There you will see six folders, three of which being:
drawable-hdpi
drawable-ldpi
drawable-mdpi.
In every folder there is a file named 'icon.png', replace it with your icon file.
The icon in the hdpi folder has to be 72 x 72 pixels, the ldpi one has to be 48 x 48, and the mdpi one has to be 36 x 36.

Go to geandroid -> bin -> res, and repeat the same actions.

Re: Building an Android .apk -file

PostPosted: Fri Dec 30, 2011 4:40 pm
by Jagmaster
Thank you so much man, I was completely lost before these tutorials (yours and akr's)
One thing that I should mention, but I think it was stated else ware, If you're on Win7 you Must not install Android Sdk in C:\Program Files (x86)\ because the security settings won't allow you to download the packages. Any other directory works.

With this being said, don't load any GE games to this directory either or the Save game files won't be created either.

Thanks again, +1 goes to lcl and Andreas.

Re: Building an Android .apk -file

PostPosted: Mon Jan 02, 2012 10:25 pm
by lcl
Thanks Jagmaster!

Oh, and yeah, I had trouble with the SDK, I had to give full rights for all to the sdk folder.
Got to add that to the tutorial. Thanks for pointing it out! :)

Re: Building an Android .apk -file

PostPosted: Fri Jan 06, 2012 4:56 pm
by VertigoKeyz
I am getting hung up on step 10. Instead of "BUILD SUCCESSFUL", I get "Error: Expected verb after global parameters but found 'debug' instead".

Any ideas on where my problem could be?

Re: Building an Android .apk -file

PostPosted: Fri Jan 06, 2012 6:43 pm
by Leif
Good !

Am i right that we are talkin about "game-in -one-file" ?
And what if game uses SaveVArs or LoadVArs functions? How to attach files with vars ?

Re: Building an Android .apk -file

PostPosted: Fri Jan 06, 2012 7:22 pm
by skydereign
You can use saveVars and loadVars. The game in one file just refers to you using LoadGame, so only one game file.

Re: Building an Android .apk -file

PostPosted: Sat Jan 07, 2012 7:37 am
by lcl
@VertigoKeys: I'm sorry man, my bad, it's not 'android debug' but 'ant debug'.
I'm terribly sorry about this. Tell me if it works now :)
(I'm going to edit the tutorial now.)

Re: Building an Android .apk -file

PostPosted: Sat Jan 07, 2012 5:06 pm
by Leif
With "ant debug" it works )) Answer was http://game-editor.net/index.php/downlo ... ngine-beta ))

Some findings:

1. Exported 800x480 game ( usual .dat export not for ipod )

- something with resolution.800x480 looks bigger - more than 800x480 and does not fit to screen;
- pressing touchkeys (except HOME) on my Galaxy S makes application restart.

2. Exported 480x320 game ( .dat export for ipod )
- vertical size stretches from 320 to 480 (full screen height), horizontal stretches accordingly (i think to 720)- not to full screen width- and empty vertical strip stays near right side of the screen;
- lowered performance (FPS worse then on ipod 3, for which game is made )
- troubles with transparency of objects;
- pressing touchkeys (except HOME) on my Galaxy S makes no effect on application ! )))).

Re: Building an Android .apk -file

PostPosted: Sat Jan 07, 2012 6:44 pm
by skydereign
As it stands, we won't be able to target every device exactly as we planned. One disadvantage to android is that it uses screen size ranges. This is fine if you are making a normal app, but since games (especially gE games that don't directly use android's own features) can't manipulate the graphics to adjust in size, we either have to use the scaling feature (which wasn't working very well in my tests) or center the game and have black bars. There is a third possibility in which you make the game for the largest screen in the screen range and if akr can get a function or something to tell use the real screen size we can make games for the largest, and scale down the HUD to fit the actual screen. I believe akr mentioned something about supporting suspend, so from that I gather the keys not working is being worked on/going to be fixed. And this android version is not optimized so there should be a visible increase in performance.

You can stop it from scaling the game (or trying to do) by changing the minSdkVersion in the android manifest file.

Re: Building an Android .apk -file

PostPosted: Tue Jan 10, 2012 3:21 am
by Clokio
Thanks, it's much simplier that I tought,

Re: Building an Android .apk -file

PostPosted: Wed Jan 11, 2012 1:50 pm
by Leif
skydereign wrote:You can stop it from scaling the game (or trying to do) by changing the minSdkVersion in the android manifest file.


I tried to change minSdkVersion from 5 to 1,10,100. No effect. It scales 800x480 screen to great dimentions. Are there any other ways prevent scaling?

However It's great. Now I can see my game on favorite platform ))))

Re: Building an Android .apk -file

PostPosted: Fri Jan 13, 2012 3:26 pm
by akr
I am happy to hear that from you Leif. :)

Re: Building an Android .apk -file

PostPosted: Mon Jan 16, 2012 11:22 am
by Leif
Well, finally i've got a solution. I think, it's not optimal, but it works (for now)

In "geandroid" folder edit AndroidManifest.xml^
1. replace " android:minSdkVersion="5" " for " android:targetSdkVersion="10" "
2. remove
Code: Select all
 <supports-screens android:largeScreens="false" android:smallScreens="false" android:normalScreens="true" android:anyDensity="false" />


and - my 800x480 screen looks as it needed ! )))
Transparency does not work properly, it can't read variables from files, but in other cases - it works ! )))

Re: Building an Android .apk -file

PostPosted: Mon Jan 16, 2012 6:41 pm
by akr
Leif thanks for letting me know the problems with transparency and saving vars. Will have a look.

Pls not that moving the minSDK version to a greater value and dropping the other definitions will drop the compatibility mode 480x320.

Now each device will show your screen fullsize and you will get the resolution from your current device metrics.

I wasnt able to handle this in my tests. But I would be glad to hear that this is a way we could go further down.

andreas

Re: Building an Android .apk -file

PostPosted: Tue Jan 24, 2012 5:51 am
by Nykos
hello everyone. Finaly got my device back so I was able to try android beta. I did several builds of different games. All of them are 480 x 320 exported in ios dat files. Some of them worked , not all of them but some did, so i'm very happy. The telephine is samsung nexus S.

Now i found some things:
I did several builds of the same game. They were all from the same ged, i just changed some things in the ged file and re-exported in dat file. But the android build did not work every time. Sometimes, the game run smoothly, and sometimes the screen just stays black and the game doesn't launch.

Then, in a fruit ninja styled game i did, i have white rounds created in place of the ninja slice. They are created by a combination of mousedown events on some actor, a variable and finaly created by a draw actor event.
It works perfectly on iphone and on windows. But it refuses to work on android. Mousebuttondown works ingame cause my pause button and menu work. But slicing does not.

I will try other things today and keep you updated if I find something else. Any news about when definitive version of GE Android will be out ? And the new one for Iphone?