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

New to Moai? Get started here with our best tips and tutorials.

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

Postby ibisum » Mon Jun 18, 2012 3:19 am

There is a new thread in the forums about the missing jars - check for it. If I recall its a quick fix, but was a bug in the released Android project template setup. I believe you might be almost there if you get this sorted - the missing jars is a typical Android problem and should be quite easily solvable.

But, I understand you want to start from a 'clean' target and have mis-trust for the Android project as it stands, not being able to build clean from a new checkout. This does suck, and I hope the MOAI dev team get on top of their release quality problems soon (grr...)

As for developing on Ubuntu, I would wait until the linux-cmake patch is integrated in the next week or so. The 1.2 SDK release is quite good, has a lot of important bugfixes, but for some reason the team seem to think that Linux host build support is not a priority (I disagree with them strongly on this point, but that is because I have an Ubuntu Tablet and am targeting an app for release to the Ubuntu App Store as soon as possible, and therefore I am biased..)

If you can't wait, you can get spacepluks' branch of moai-dev 1.1 from here: https://github.com/spacepluk/moai-dev

Off the top of my head, the steps are:

0. mkdir some_work_dir_for_this && cd !$
1. git clone https://github.com/spacepluk/moai-dev
2. cd moai-dev
3. git checkout linux-cmake (or linux-cmake-amd64 if you are using a 64-bit linux)
4. mkdir build && cd build
5. cmake ..
6. make
7. mkdir -p ~/bin/ && find ./ -name "gluthost" -exec cp {} ~/bin/moai-dev-spacepluk \;
8. export PATH=$PATH:~/bin/
9. cd samples/anim/basic && moai-dev-spacepluk ./main.lua
10. cd ../../../ant && ./make-host.sh -a all -p your.package-identifier.whatever
11. (Make *SURE* you've got an Android SDK and NDK installed in your local Ubuntu instance)
11. cd untitled-host && vi settings-global.sh && vi settings-local.sh && ./run-host.sh


Should be enough to get you started, good luck!
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1024
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

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

Postby sgeos » Tue Jun 19, 2012 6:52 am

mikegriffin wrote: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

Presumably this should be noted to the Wiki?

Code: Select all
  1. ~/moai-sdk/hosts/ant$ ./run-host.sh

  2. cp: host-source/project/libs/*: No such file or directory

  3. ~/moai-sdk/hosts/ant$ mkdir host-source/project/libs

  4. ~/moai-sdk/hosts/ant$ cp ../../bin/android/armeabi/libmoai.so host-source/project/libs/

  5. ~/moai-sdk/hosts/ant$ ./run-host.sh

  6. Buildfile: ~/moai-sdk/hosts/ant/build/project/build.xml

  7.  

  8. BUILD FAILED

  9. ~/moai-sdk/hosts/ant/build/project/build.xml:83: Cannot find ~/moai-sdk/hosts/android-sdks/tools/ant/build.xml imported from ~/moai-sdk/hosts/ant/build/project/build.xml

  10.  

  11. Total time: 1 second

  12. ~/moai-sdk/hosts/ant$


Evidently this is still not working.

ibisum wrote:You're supposed to generate an Android project folder for your app by using the make-host.sh[.bat] script. ... If you're not using make-host.sh[.bat] to generate your Android project, then you're going to run into problems

The wiki gives the impression that there is no need to create the host when using the binary Moai SDK. I think I'm using the downloadable Moai SDK 1.1, but the wiki does not appear to have been updated for a few months so I assume the instructions pertain to Moai SDK 1.1.

Did I botch something basic, or is the documentation insufficient (or both)? Should these problems go away if I build from source? I'm developing on Mac OSX and I managed to get my project running on iOS hardware with little fussing around.
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby ibisum » Tue Jun 19, 2012 6:58 am

Personally, I think that MOAI is a lot easier to deal with if you just bite the bullet and build from source.

Also, if you want to get through this, maybe its better if we meet in #moai on irc.freenode.net (I am torpor) and we can help you through it.
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1024
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

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

Postby sgeos » Tue Jun 19, 2012 9:39 am

I went to #moai on irc.freenode.net. The fellow I spoke to was under the impression that you need to use an old version of the Android SDK "because after that they changed the build.xml". He pointed me to r13 for Mac OSX. The problem is that I can not figure out how to add any Android platforms with with revision 13 of the Android SDK Tools. The build still fails for the same reason.

Do I really need to use an old version of the Android SDK Tools? In any case, something is not documented. After I figure this out, the wiki should be updated for the next person.
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby tenth » Tue Jun 19, 2012 9:58 pm

Well I can help you out with the build.xml problem - this is apparently something that is generated by Eclipse. I started up Eclipse, updated (you need to update the ADT plugin (help -> check for updates) as well as the Android SDK), and then restarted Eclipse and suddenly I had a build.xml in the right place. This worked for me in both Linux and Windows.

ibisum: This version of the Moai SDK that you linked from Github is pretty different from the download on the Moai website. Here's the Github ls:

3rdparty
ant
CMakeLists.txt
distribute
docs
README.txt
samples
scons
src
test
version.txt
vs2008
vs2010
xcode

and the ls from the binary distribution:

3rdparty
bin
docs
hosts
include
legal.txt
license.txt
README.txt
release-notes.txt
samples
version.txt

I'm just offering this as an explanation for why sorting this out has been so difficult. I do see the make-host.sh that you've been talking about in the Github version.

I'm going through your steps right now, finding all the prerequisites for the cmake process took a while and make is currently giving me this:

../moai-dev/src/uslscore/USXmlReader.h:7:19: fatal error: expat.h: No such file or directory
compilation terminated.

There are several expat.h files, but not in that directory. I'm wondering if I should just guess...
tenth
 
Posts: 6
Joined: Thu Jun 14, 2012 10:35 am

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

Postby ibisum » Wed Jun 20, 2012 12:40 am

Totally bizaare. FWIW, I always build MOAI from sources. I suggest you do the same ..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1024
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

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

Postby tenth » Wed Jun 20, 2012 1:17 am

Well I'm trying, that isn't exactly going smoothly either... I'll keep working on it. Thanks for the help.
tenth
 
Posts: 6
Joined: Thu Jun 14, 2012 10:35 am

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

Postby sgeos » Wed Jun 20, 2012 7:25 am

I went through the process of building from source on IRC. I managed to build and APK. I do not have hardware of my own and the emulator does not seem to like me, but another developer managed to run a sample I built on hardware. Here are the steps I followed.
Code: Select all
  1. # (install Android SDK and NDK)

  2. # (add SDK and NDK to path; export PATH=$PATH:/(SDK_PATH)/tools:/(SDK_PATH)/platform-tools/:/(NDK_PATH)/)

  3. mkdir ~/moai-source

  4. cd ~/moai-source

  5. git clone https:/ /github.com/moai/moai-dev

  6. git checkout 760b5a8b077e3eb6f2473f1deede317d0725bc3c

  7. cd moai-dev/ant/

  8. ./make-host.sh -p com.mycompany.app.appname

  9. cd untitled-host

  10. vi settings-local.sh

  11. # (configure android_sdk_root and src_dirs)

  12. ./run-host.sh


(That should be https:// on step 5.) The latest version of the repository seems to be broken, so the checkout is needed. To set up the emulator (which did not work for me):
Code: Select all
  1. android avd

  2. emulator -gpu on -avd MyTestDevice


Check that the emulator is running with:
adb devices
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby tenth » Wed Jun 20, 2012 10:55 pm

Thank you sgeos, that got it working. Not on the emulator, but that isn't surprising - they do say that the android emulator isn't supported for lack of OpenGL. The run-host script does output successfully to my phone, however.
tenth
 
Posts: 6
Joined: Thu Jun 14, 2012 10:35 am

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

Postby sgeos » Thu Jun 21, 2012 3:59 am

I just posted my copy of the notes. Thank ibisum. He walked me through the process. It sounds like I need my Android hardware...
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby ibisum » Fri Jun 22, 2012 12:30 am

You *have* to start the emulator with GPU acceleration turned on (thats what '-gpu on' does). If you don't, MOAI won't run. Of course, this assumes that your platform lets you run the Android emulator with acceleration turned on ..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1024
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

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

Postby sgeos » Fri Jun 22, 2012 6:01 am

I managed to run my app on the Android emulator. This is what you need to do:

  • Install Android SDK Tools, Revision 17 or higher
  • Install Android SDK Platform API 15, Revision 3 or higher
  • Start the AVD Manager and create a new AVD
  • Set the Target value of Android 4.0.3 (API Level 15), revision 3 or higher.
  • To have graphics acceleration enabled by default for this AVD, in the Hardware section, click New, select GPU emulation and set the value to Yes.
  • Name the AVD instance and select any other configuration options.
  • Note: Do not select the Snapshot: Enabled option.
  • Click Create AVD to save the emulator configuration.
If you did not enable graphics acceleration by default, you can enable it from the command line with -gpu on.
Code: Select all
  1. $ emulator -avd <avd_name> -gpu on

Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby tenth » Sat Jun 23, 2012 10:08 pm

Thank you, the emulator also works now. This despite the fact that one of the MOAI docs that read at some point said that it wouldn't... ::sigh:: I do appreciate the help but this is just ridiculous. I've been struggling for this long just to get MOAI up and running and now I'm trying to do some of the simplest little things and finding that the documentation is just atrocious.

I'm sure I'll come back to MOAI at some point, but for the moment I guess I'll suck it up and use Corona.
tenth
 
Posts: 6
Joined: Thu Jun 14, 2012 10:35 am

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

Postby sgeos » Sun Jun 24, 2012 1:10 am

tenth wrote:Thank you, the emulator also works now. This despite the fact that one of the MOAI docs that read at some point said that it wouldn't... ::sigh::

You can only run Moai in the emulator using the latest Android platform. I suspect Moai would not run in the emulator when the documentation you read was written.
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby maecky » Sat Jul 21, 2012 5:56 am

I set everything up like you mentioned:

SDK Tools, Revision 20
SDK Platform API 15, Rev. 3

Created an AVD with Target "Android 4.0.3", rev. 3 and set GPU to Yes
Snapshot is not selected.

I had to choose the CPU/ABI, where I selected "ARM (armeabi-v 7a).


When I try to debug, I always get a error message:

Code: Select all
  1.  

  2. 07-21 12:51:44.734: E/EGL_emulation(213): rcMakeCurrent returned EGL_FALSE

  3. 07-21 12:51:44.734: E/EGL_emulation(213): tid 214: eglMakeCurrent(976): error 0x3006 (EGL_BAD_CONTEXT)

  4. 07-21 12:51:44.734: E/libEGL(213): eglMakeCurrent:674 error 3006 (EGL_BAD_CONTEXT)

  5. 07-21 12:51:44.734: E/SurfaceFlinger(213): Couldn't create a working GLES context. check logs. exiting...

  6.  



Has anyone the same problem?
maecky
 
Posts: 13
Joined: Fri Jun 29, 2012 6:22 pm
Location: Graz, Austria

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

Postby sgeos » Sat Jul 21, 2012 8:22 am

What OS are you on? Evidently some people "had to swap out the libGLES.dll and libGLES2v2.dll with the Chrome or Qualcomm versions to get running" on Windows.

Everything works fine on OSX for me, both before and after updating. I currently have the following installed:
  • Android SDK Tools, Revision 20.0.1 (was revision 19 before updating)
  • Android SDK Platform-Tools, Revision 13
  • Android 4.0.3 (API 15), all sub-components except ICS_R1
  • Other Android API levels (probably unimportant)
  • Extras, all sub-components compatible with Mac OSX (probably unimportant)
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

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

Postby maecky » Sat Jul 21, 2012 9:34 am

Thx, for your quick reply!

Oh I forgot, my OS is Windows 7 - 64Bit.
I will have a look at your link.
maecky
 
Posts: 13
Joined: Fri Jun 29, 2012 6:22 pm
Location: Graz, Austria

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

Postby SH_Black_Hole » Sun Jul 22, 2012 5:01 am

hi
i'm new on moai and i run some code and tutorial and now i decide to run my code on android device and i try many time and read many pages but i cant build apk :(
i install Android SDK, Android NDK, Moai SDK, Eclipse, JDK, Cygwin, apache-ant, sublime text, lua for windows, 7-Zip on my system (Windows 7 64) and set ANT_HOME, JAVA_HOME environment variable and add Android ndk, apache-ant\bin, 7-Zip, android-sdk\platform-tools, Lua\5.1, Lua\5.1\clibs to my path variable. finally i install MoaiNao-debug.apk on my device.

when i use sublime for build and run on my device only i see black screen for some second and then device go to main screen and app is still on proccess.

when i run "run-host.bat" from ant folder below message appear :(
run-host.sh: line 40: [: too many arguments
cp: target `ant/build/project/res/drawable-ldpi/icon.png' is not a directory

and when i comment some line related to icon ( line 62 to 76 ) this message show on cmd
run-host.sh: line 40: [: too many arguments
cp: target `ant/build/project/.classpath' is not a directory

I change some path in "sdk-setup.sh", "settings-global.sh" and "settings-local.sh" to point to correct path and "sdk-setup.bat" work great.

now what should i do for make android game and apk?
SH_Black_Hole
 
Posts: 30
Joined: Sun Jul 22, 2012 4:31 am

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

Postby ibisum » Sun Jul 22, 2012 7:21 am

The only bit of advice that I think you can benefit from receiving is this: don't use the SDK .zip release. Download the MOAI SDK from Git sources and use that instead. You will have to use the make-host.sh script to build a template folder, just like you've already done - and it should be quite easy, in fact, in comparison to the Windows experience..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1024
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

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

Postby SH_Black_Hole » Mon Jul 23, 2012 5:16 am

ibisum thanks for your answer. I use Moia sdk from git sources and try it. first problem was should install make package of cygwin and it's not install by default so i install and solve first problem. 2nd problem was NDK_PROJECT_PATH variable and I fixed it by make some batch file that contain setx NDK_PROJECT_PATH "%CD%" command and problem solve. now when i run bash make-host.sh -p com.getmoai.samples i give below error :
I:\Moai\moai-moai-beta-Version-1.1-Revision-2-8-g565c1f3\moai-moai-beta-565c1f3\
ant-Copy\libmoai/jni/Application.mk:7: ArmModeDefined.mk: No such file or direct
ory
I:\Moai\moai-moai-beta-Version-1.1-Revision-2-8-g565c1f3\moai-moai-beta-565c1f3\
ant-Copy\libmoai/jni/Application.mk:8: AppPlatformDefined.mk: No such file or di
rectory
/cygdrive/c/ProgrammingTools/Android/android-ndk-r8b/build/core/prebuilt-library
.mk:64: *** target pattern contains no `%'. Stop.


ArmModeDefined.mk and AppPlatformDefined.mk is in correct path. now how can i fix it?
SH_Black_Hole
 
Posts: 30
Joined: Sun Jul 22, 2012 4:31 am

PreviousNext

Return to New Users

Who is online

Users browsing this forum: No registered users and 0 guests

x