How to build an Android APK , step-by-step

Tablets / Phones / Consoles / Ouya

Moderator: ezraanderson

How to build an Android APK , step-by-step

Postby abrandao29 » Mon Feb 06, 2012 7:15 pm

Been trying to to build some of the sample android applications to create an APK so I can install on my device., but have not had any luck..

Currently have installed on my system..
- Eclipse
- Android SDK
- Moai SDK

I cant seem to find in the docs the process to do this??? Any help would be appreciated.
abrandao29
 
Posts: 1
Joined: Mon Feb 06, 2012 7:08 pm

Re: How to build an Android APK , step-by-step

Postby ibisum » Tue Feb 07, 2012 2:12 am

Read the Wiki? http://getmoai.com/wiki/index.php?title ... id_Devices

Its generally pretty easy - you just have to understand that you're bundling two projects into the APK - the 'wrapper Android application' which will run your MOAI app, and the MOAI app sources themselves. You should generally use your development host to develop the MOAI app, and only bundle for Android/iOS/etc when its time to do platform testing .. and the Android project setup is inclined towards that mode of working.

If you have problems after reading the wiki, lets hear about them and we'll help you get through the issue - but be aware that its not difficult, others have done it, and there are threads about bumps in the way already ..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info/
User avatar
ibisum
 
Posts: 1275
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How to build an Android APK , step-by-step

Postby seitenkick » Tue Feb 07, 2012 9:59 am

I am also trying to figure this tutorial out but without success.
I use eclipse and the examples run just fine in eclipse.
I have installed the Android framework into eclipse.

Here I'm not sure how to proceed? Should I create a new Android project in eclipse and somehow import
the Moai-project?

In the tutorial it says --> Select and import the folder 'hosts/eclipse/android-project'. This folder does not exist in my version of the moai sdks?

Thank you
seitenkick
 
Posts: 3
Joined: Tue Feb 07, 2012 2:45 am

Re: How to build an Android APK , step-by-step

Postby bengaard » Thu Feb 09, 2012 3:24 pm

I don't get it either :?

Ok, let's say we'll follow the Wiki as you suggest: http://getmoai.com/wiki/index.php?title ... id_Devices

I have eclipse, android sdk and downloaded the moai sdk. I have build many android apps without problems before.

Now the wiki tells me to import some project that doesn't exist in the moai sdk? Ok, I google around and realize I have to do some something first with some scripts in the ant project? Could someone describe again very simply what exactly I have to do with those scripts and please use some examples for us slow-brained Windows 7 users? Please show me how I get to the point where I can see the spinning cat on my android phone :) Thank you very much.

I tried to figure it out about those scripts and even tried to install some unix bash - that's when I realized I needed help :)

Thank you very much for your help, Moai looks super interesting and I'm well on the way building games with lua, but to build it and see it on my phone is a mystery to me.
bengaard
 
Posts: 2
Joined: Thu Feb 09, 2012 3:10 pm

Re: How to build an Android APK , step-by-step

Postby mikegriffin » Fri Feb 10, 2012 4:24 am

I agree to build for Android is very confusing. The above wiki article is not correct as there is no eclipse project in hosts anymore.

To build on Windows environment you need the following
cygwin (with ar and ranlib installed) - I think these are in the gcc library
ant
android sdk

eclipse (optional)
android ndk (optional if you want to recompile the .so library)

You can then run the edit and run the scripts in the hosts/ant directory which will create you an android project.
mikegriffin
 
Posts: 68
Joined: Thu Feb 02, 2012 12:04 pm

Re: How to build an Android APK , step-by-step

Postby mikegriffin » Fri Feb 10, 2012 4:33 am

Looking at the /hosts/ant/run-host.sh you may have to copy the libmoai.so library from /bin/android/armeabi to /hosts/ant/host-source/libs
mikegriffin
 
Posts: 68
Joined: Thu Feb 02, 2012 12:04 pm

Re: How to build an Android APK , step-by-step

Postby andrew.lundell » Fri Feb 10, 2012 9:33 am

I'm trying to follow these directions. What I can't figure out is how to properly setup my package name.
It works fine if I leave it as com.getmoai.sample, but anything I can think to do to change it breaks the linking with the Moai libraries.

I don't have to actually rebuild the moai libraries from source to change my package name, do I?
@apLundell <-- Follow Me!
andrew.lundell
 
Posts: 67
Joined: Fri Oct 07, 2011 10:07 pm

Re: How to build an Android APK , step-by-step

Postby bengaard » Sat Feb 11, 2012 5:10 pm

I finally got the rotating cat example to work. The hard part for me was to figure out how cygwin works :oops: I would also like to know what the procedure is to change the package name?
bengaard
 
Posts: 2
Joined: Thu Feb 09, 2012 3:10 pm

Re: How to build an Android APK , step-by-step

Postby mikegriffin » Sun Feb 12, 2012 8:02 am

What if you change
package=com.getmoai.samples

in /hosts/ant/run-host.sh
?
mikegriffin
 
Posts: 68
Joined: Thu Feb 02, 2012 12:04 pm

Re: How to build an Android APK , step-by-step

Postby iwimbi » Mon Jun 11, 2012 2:52 pm

i am getting errors:


File not found - .?*
File not found - .?*
File not found - .?*
File not found - .?*
File not found - .?*
File not found - .?*
FIND: Parameter format not correct
File not found - .?*
File not found - .?*
FIND: Parameter format not correct
FIND: Invalid switch
FIND: Invalid switch
File not found - .?*
File not found - .?*
Buildfile: c:\moai-sdk\hosts\ant\build\project\build.xml

BUILD FAILED
c:\moai-sdk\hosts\ant\build\project\build.xml:83: Cannot find c:\moai-sdk\hosts\
ant\build\project\@SDK_ROOT@\tools\ant\build.xml imported from c:\moai-sdk\hosts
\ant\build\project\build.xml

Total time: 0 seconds
Buildfile: c:\moai-sdk\hosts\ant\build\project\build.xml

BUILD FAILED
c:\moai-sdk\hosts\ant\build\project\build.xml:83: Cannot find c:\moai-sdk\hosts\
ant\build\project\@SDK_ROOT@\tools\ant\build.xml imported from c:\moai-sdk\hosts
\ant\build\project\build.xml

Total time: 0 seconds
Buildfile: c:\moai-sdk\hosts\ant\build\project\build.xml

BUILD FAILED
c:\moai-sdk\hosts\ant\build\project\build.xml:83: Cannot find c:\moai-sdk\hosts\
ant\build\project\@SDK_ROOT@\tools\ant\build.xml imported from c:\moai-sdk\hosts
\ant\build\project\build.xml

Total time: 0 seconds
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
error: device not found
- waiting for device -

grrrr what am i doing wrong?!
User avatar
iwimbi
 
Posts: 4
Joined: Mon Jun 11, 2012 2:48 pm

Re: How to build an Android APK , step-by-step

Postby ibisum » Tue Jun 12, 2012 1:03 am

grrrr what am i doing wrong?!


Using Windows to build Android host target. Seriously, its a pain and quite broken.

A better experience, all around, can be had by setting up a Linux VM and building the Android host within that environment - it just plain works. A lot of fuss and nonsense on Windows, versus a little Linux VM that only needs to be used as a build server.

I know thats not the answer you need, so I'll say this: I believe there is a bug in the run-host.bat file with regards to file-glob'ing, which was fixed in the latest beta release - are you using the SDK release, or from git? IMHO, we'd all be far better off using the direct repo sources instead of the SDK release, at least until SDK 1.2 is released (which will include a lot of the fixes that are already in the existing repo..)
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info/
User avatar
ibisum
 
Posts: 1275
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How to build an Android APK , step-by-step

Postby iwimbi » Tue Jun 12, 2012 1:43 pm

lol I knew that using Windows as android host target was wrong from the beginning. But I heard that some people succeeded:)

I was using plain Moai-SDK realease that was quite...hmmm...well not so good. Today I was trying to build a host from source and received several warnings:
Building libmoai.so for arm, armeabi-v7a, android-10
Install : libmoai.so => libs/armeabi-v7a/libmoai.so
File not found - .?*
File not found - .?*
File not found - .?*
File not found - .?*
File not found - .?*
File not found - .?*
FIND: Invalid switch
*************************************************************

* Android host successfully created.

*************************************************************


Host was created but some files were missing from android project?! so I cannot build project from eclipse.

It seems that cygwin cannot find some files from "c:\moai\ant\host-source\" directory.
User avatar
iwimbi
 
Posts: 4
Joined: Mon Jun 11, 2012 2:48 pm

Re: How to build an Android APK , step-by-step

Postby ibisum » Wed Jun 13, 2012 1:27 am

What I think happened is that run-host.sh was built (and runs successfully) on Linux, and then this was 'converted' to a Windows .bat file to be used with the Cygwin tools - but as everyone and their dog seem to have issues with installing/setting up a proper Cygwin/Android NDK relationship, you've got some tools incompatibility. Its probably using the DOS find.exe instead of the Cygwin find.exe, for example .. is Cygwin before C:\WINDOWS in your Path, and so on?

Honestly, if you need to get it sorted - build a Linux VM and go that direction. It just plain works, and you don't have to commit a lot of effort to an unworkable system - plus, having Android builds in a VM means that you don't have a tools dependency on your customized Windows system. A Linux VM building Android hosts is a bit more future-proof ..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info/
User avatar
ibisum
 
Posts: 1275
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How to build an Android APK , step-by-step

Postby telarium » Wed Jun 13, 2012 9:27 am

Yeah, I've been wrestling with this for days now trying to get it working on Windows. I've been following the steps as closely as I can, and I think I'm very close... run-host seemed to create the Eclipse project, which I can import.

However, when I go to run the project in Eclipse, it complains that it's missing moai-sdk\hosts\ant\build\facebook\bin\facebook.jar

So since people seem to be saying that building a Moai Android project in Windows is a nasty process, I tried it on my Mac. Same result. Any idea how I address this? Did I miss a crucial step somewhere?
telarium
 
Posts: 11
Joined: Mon Jun 04, 2012 1:55 pm

Re: How to build an Android APK , step-by-step

Postby ibisum » Wed Jun 13, 2012 10:52 am

I'm not sure what you're going through, but there are two phases to the process - first, generate an Android project with ant/make-host.sh, then take that untitled-project/ directory and use the run-host.sh file to generate an .apk and run it on your test device (or emulator). This should work pretty smoothly 'out of the box' - if not, and you're on OSX, I don't know whats going on. Maybe post a terminal session log or something?
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info/
User avatar
ibisum
 
Posts: 1275
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How to build an Android APK , step-by-step

Postby tenth » Thu Jun 14, 2012 12:22 pm

Well, all right. I switched from Windows to OpenSUSE on the advice in this thread, and have sorted out most of the installation junk so far, but I'm running into this problem now when I run run-host.sh:

BUILD FAILED
../moai-sdk/hosts/ant/build/project/build.xml:83: Cannot find ../android/tools/ant/build.xml imported from ../moai-sdk/hosts/ant/build/project/build.xml

and I don't know how to address it. Any help is appreciated but I have no make-host.sh, so I'm not sure what ibisum is referring to there.

As another question, could someone describe to me how this is supposed to work when it's working? Supposing I want to make a game using only Lua, I write my scripts, put them... somewhere. Run run-host.sh to make the project, open that in Eclipse, and then use the ADT plugin to do my testing? Is that how this is supposed to be going?
tenth
 
Posts: 6
Joined: Thu Jun 14, 2012 10:35 am

Re: How to build an Android APK , step-by-step

Postby ibisum » Fri Jun 15, 2012 12:58 am

The way it works: use your native MOAI host to develop your app (in this case, you'll need to get the Linux host built with the recent cmake files, or use the SDK released binaries for MacOSX and Windows). Get the game working with your native host.

Then, use make-host.sh script to make yourself a copy of the Android MOAI host project, from the built-in template. This is necessary: you need to set your app id, app name, and so on. Point the settings-local.sh file to your Lua sources (also make sure settings-global.sh is configured properly too), and then run the ./run-host.sh script to build the .apk, and run it on your local test device.

This works pretty smoothly - but it appears that there might be a misunderstanding about the purpose of the make-host.sh script. (Its in $MOAI_ROOT/ant/ by the way). You use this script to make a copy of the Android host for your project, then you customize that project for your needs. You can use ant to build from the cmd line (my preferred method) or you can import the files in the build/project folder into an Eclipse project. That folder gets created when you run "run-host.sh" at least once - you need to do that at least once, actually.

So the sequence, in short, looks like this: "cd $MOAI_HOME/ant && ./make-host.sh -p your.package.name && cd untitled-project && ./run-host.sh" .. then move the untitled-project somewhere sane for your needs, and use it to build the Android version of your project when needed.
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info/
User avatar
ibisum
 
Posts: 1275
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How to build an Android APK , step-by-step

Postby tenth » Sat Jun 16, 2012 2:19 pm

Sorry, I'm still having trouble with this. I've switched back to Windows since people say version 1.2 works in Windows, but I don't have a make-host.sh in any subdirectory of moai-sdk. For that matter I don't have a $MOAI_HOME/ant directory, though I'm guessing that you meant $MOAI_HOME/hosts/ant.

I've read through the project setup documentation and it says that I need to use an Android device, which is fine, but in order to do that I need to refer to the setup given in ‘hosts/eclipse/README.txt’ which I don't have (nor any directory named eclipse).

I'm just working off of the binary distribution here, is make-host part of the source distribution? I guess I can answer that question for myself - no it is not. When I run run-host.bat, without using make-host first, I get this error:

BUILD FAILED
D:\moai-sdk\hosts\ant\build\project\build.xml:83: Cannot find D:\android\tools\a
nt\build.xml imported from D:\moai-sdk\hosts\ant\build\project\build.xml

I only got that far by changing the permissions on the host-source directory and changing run-host.sh to carry over those permissions when it copies the files.

Edit: Well, my observant self has noticed that I seem to be stuck in the same place in both Linux and Windows. The wiki implies that make-host.sh isn't necessary if you're using the binary distribution:

http://getmoai.com/wiki/index.php?title ... id_Devices

but that doesn't explain why I'm running into this problem. Is Ant not set up correctly? I think build.xml in the Android SDK directory is supposed to be generated by... something. I'll keep looking.
tenth
 
Posts: 6
Joined: Thu Jun 14, 2012 10:35 am

Re: How to build an Android APK , step-by-step

Postby ibisum » Mon Jun 18, 2012 1:09 am

You're supposed to generate an Android project folder for your app by using the make-host.sh[.bat] script. This script takes the Android template and stuff it with your details - app identifier, etc. If you're not using make-host.sh[.bat] to generate your Android project, then you're going to run into problems - you can't just import the supplied Android template into Eclipse and expect it to work as there are going to be pieces missing from the puzzle. You *must* use make-host.sh[.bat] to generate a proper Android project folder, pointing to your MOAI .lua sources, before any of this will make sense.

In my clone of the moai-dev repo (I'm on OSX and Linux, btw), there is a sub-folder called, simply "ant/". Go to that folder and use the make-host script (whatever it is for you - I've warned you that I think Windows sucks in comparison, so I suggest you double-check that you cannot survive on Linux/OSX before getting involved in the Windows setup process, which is thorny and not as nearly as productive as OX/Linux) to generate the Android project you need, make sure the moai-target file points to the sources you want to include with the Android host, and you should be good to go.

I've been building Android hosts for months, and haven't had any of the serious problems you've encountered, but then again I'm not on Windows.
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info/
User avatar
ibisum
 
Posts: 1275
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: How to build an Android APK , step-by-step

Postby iwimbi » Mon Jun 18, 2012 2:18 am

Ok, I managed finally to build project with make-host script. I added Cygwin path before any windows paths(thanks @ibisum for suggestion). Now I am trying to import project to eclipse and I am getting error about some missing jar librires ( moai-sdk\hosts\ant\build\facebook\bin\facebook.jar) like @telarium. This is a nightmare!!!


@ibisum I give up, I am switching to Ubuntu now, so do you have any tutorial on how to set up MOAI SDK and build apk for Linux? If I can build apk on Linux I will develop and test on Windows and switch to Ubuntu later just to build and compile game.
User avatar
iwimbi
 
Posts: 4
Joined: Mon Jun 11, 2012 2:48 pm

Next

Return to Android

Who is online

Users browsing this forum: No registered users and 0 guests

x