Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

How did Shadowgun reduced APK to 6 MB?

Discussion in 'Android' started by floky, Nov 9, 2011.

  1. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Hi guys,

    Currently there is a general issue affecting Android development using Unity: the final APK size.
    The Android Market app downloads APK's first in the phone storage memory. If the APK is larger than the phone storage memory it fails to install the APK.

    We need a general and easy way of doing an installer for the Android apps.
    I noticed the Shadowgun APK is only 6 MB.

    Can someone explain maybe how they managed that?

    Let's say I've made an iPhone game that has 550MB and then I decide to port it to Android.
    Is there a quick way of making a small installer that will download my 550MB game without needing to separate my game assets into asset bundles thus forcing me to modify the game code also to manage those asset bundles and load them differently. (it's very painful to change a lot of code using Resources.Load(...) to make it load assets from various asset bundles not to mention you also have to release them manually at certain points)

    All this hassle compromises the initial purpose of using Unity to easily port a big iPhone game to Android.
    =================================================================


    Edit:

    The tool has moved to a new fresh forum thread while also preparing for a new next big step (it's a surprise, but it will still take a while :D)
    http://forum.unity3d.com/threads/129042-Android-Builder-Tool?p=871925#post871925
     
    Last edited: Mar 23, 2012
  2. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    I've found an interesting approach that some people are trying here:
    http://www.anddev.org/other-coding-...ns-from-within-another-application-t6909.html

    The idea is to somehow build your final game APK with Unity and use another APK as the installer to download and manually install the game APK on the user's phone. But I have some big doubts that Android Market allows this because of security reasons.

    Both APK's would need to be signed but only the installer APK would need to be uploaded to the Android Market. Hmm...trying to wrap my head around this concept. Something doesn't feel right. Not to mention that the user will end up with 2 apps on his/her device: the installer and the installed game APK (if everything works).

    Does anyone know some details about how Shadowgun handled this process?
     
  3. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,342
    I'd like to know how to optimize the file size also- my game MiG Hunt is 12.3 mb which is kind of big if you ask me, but I have seen other games that are less in quality of graphics , but with a 20+ mb file size.

    So is this basically just how you design the game??? Instead of using particle systems should I just use sprites???
     
  4. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    The problem here is not about optimizing final game package size. It's actually about finding an easy and robust way of externalizing game resources to create a partial app that will act as an installer for Android. (because on iOS this isn't accepted anyway)
    Asset Bundles is a solution to this but trust me, it's a pain because everywhere you use Resources.Load( ...) to load an asset in the iOS game, you need to replace it with a custom asset bundle loader to obtain that asset. And all the initial stable code you had written for the iOS game is shot to hell. You basically end up with two different code bases: one for iOS and one for Android.

    In your case it's not necessarily the particle systems that pump up the app size. :) Could be the sounds or textures size. And no it's not a design rule.
     
  5. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    No one else interested in this subject? :(
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    everything was said on the matter: create an installer that downloads the real game - defacto standard on android as long as its market is as bad as it is (only one limit, 50mb, for any way of downloading ie also 3G).

    On iOS you don't need it.

    Generally if you want smaller build sizes get iOS / Android Pro so you can use stripping that on its own saves you up to 10mb on the code end
     
  7. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Thanks for the answer dreamora. You are right. The only solution is to create an installer.

    I was also trying through this post to stimulate people to discuss about an easy way to implement this installer and at the same time to be generic and independent of the code of the game.
    As I said in one of the posts above: to eliminate the need to refactor your entire iOS written code if you later decide to launch for Android (for various reasons), because of using AssetBundles that requires a different code flow to load assets with WWW requests.

    I've continued searching about this subject and I will post what I find in the next post.
    Maybe we can cook up a generic Android installer that can be easily adapted to any Unity project.
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,532
    Or just keep it small. Personally, I'll stick to iOS until google raise the size of APK, unless something is a really big hit.
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Raising the size of APK won't happen.
    the problem is that google tries to solve the problems from the ass side of the donkey.

    they raised the APK to overcome the limitation but keeping it small enough for 3G, not getting that the thing they have to do is going a 2 split way like apple, a 3g limitation and no wifi limitation ...
     
  10. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    I found this forum post about installing and running an APK from another running APK.
    http://www.anddev.org/other-coding-...ns-from-within-another-application-t6909.html

    It seems to work, I will definitely try it myself on the device.
    This solution would be awesome if it's legally accepted by the Android Market. Imagine that a native APK installer application can be implemented that would download your real game APK built with Unity and just install it on the user's device on the SD card! And the user would just have to buy and install this installer app. You could have your game size even at 500MB.

    Can erique or someone from the Android Developer side confirm if the solution posted at the above link is legally accepted by Android Market?
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can not install program code on the SD card anyway. you can only transfer the raw data over to it.

    and there are games in the 500mb+ range, that start a downloader to get the real game at 300mb ... thats standard practise on android market for many many months now ... sims is 280mb for example, modern combat over 300mb etc
     
  12. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Exactly! As dreamora said:raising the apk limit won't happen any time soon.
    I'm just trying to give a solution to this comunity regarding this problem.

    But the problem is not only on the android market side! But also on the devices!
    For example most Samsung Android devices have a download cache limit of only 30 MB! Which is pretty small for today's Infinity Blade type mobile games.
    Another post on the samsung devices issue:
    http://www.google.com/support/forum/p/Android Market/thread?tid=52a4aac43e5e3b6c&hl=en

    So, returning to the problem. Sorry for explaining wrong my above post dreamora when i said about installing another apk on the SD card. I meant to say that the method found could allow to download the actual game package in the installer's Documents directory and install the apk from there using the methods from that link i posted. The app code is definatelly going to be installed on the phone memory but the game data from the APK is going to be installed on the SD card if it's manifest specifies it.

    If both APK's are signed but only the installer APK is uploaded to the Market and the other APK(the game built with unity) is uploaded on a predefined server, would Google allow it?

    I'm starting to hold on with my teeth on this type of solution. :))
     
    Last edited: Nov 16, 2011
  13. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    It would be awesome if erique could share an opinion about the above described approach.
     
  14. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Ok guys! So far so good...A news update about the progress.

    I've implemented a test installer that does the things described above:
    1) Download another APK (the actual game) on the SD card from a remote address
    2) Auto-start the OS package installer that installs the game
    3) Returns back to the installer and notifies it that everything has completed and the downloaded APK is deleted from SD card.

    Everything seems to be working fine in the simulator and on a Samsung Galaxy S device.
    There is still a very big security issue that will need to be addressed regarding the game APK being downloaded by the installer. Because it's downloaded on the SD card in the path returned by Environment.getExternalStorageDirectory. I don't see what will stop a user to easily fetch the game APK and distribute it on torrents.
    I know that any game can be cracked but this is a bit like offering the game APK on a silver platter.
    But I guess a security scheme can be implemented by anyone. :)

    I will continue to post updates on this subject in the next few days.
    I still didn't manage to find out if this flow is accepted by Google on the Android Market. If anyone out there knows for sure please tell me the restrictions so I can search a way around them.

    As soon as I decouple the installer steps into neatly commented java methods I will post the code I have so far.

    The plan would be to bridge the decoupled installer steps that must execute natively on Android with the Unity engine through a small plugin so that anyone could just easily make their own custom Installer graphical interface with animations and background music in Unity and just ignore the java back-end.
     
  15. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    27,532
    The user will pirate your game if the user wants to, regardless. I don't see how they couldn't. Downloading the content will need to be done via CDN simply because dedicated server bandwidth would get fairly saturated.

    If this remote downloading is something that can solve piracy in any way, my interest in the android platform would rise pretty quickly.
     
    Last edited: Nov 17, 2011
  16. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    You are right. This is a downside on the developer part. This is something that only Google can help with by offering the required storage that's anyway offered for the apps.
    This solution first comes in handy for companies that have their own CDN or some kind of subscription for a CDN provider.

    I strongly believe that through this method, not only you will be able to easier port your game from iOS to Android while keeping the resource management intact (without changing everything to asset bundles), but it will also allow for a more flexible way of implementing an anti-piracy system from the developer side. This is because you have more control on what happens before you install, while you install and after you install your game.
     
    Last edited: Nov 17, 2011
  17. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    Actually if you use streamed scene asset bundles you won't need any changes to your resource management, that's what I've done in a recent game and it works nicely. (https://market.android.com/details?id=com.glu.gladiator) (This initial size is only due to some videos they added at game startup)

    Basically you use dependency management (Push/Pop asset dependencies) and put all your assets and scenes into bundles. Then you create a simple player with just one scene that load all the bundles in the same order you packed then, then you should switch to the first scene you packed as a bundle.
     
  18. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Capyvara, I am aware of every possible solution involving asset bundles. But this solution does not scale to any game.
    The assets number involved in the above posted game seems to be fairly reasonable. There are many games, small to mid sized games, that can scale very well to just using scene asset bundles. You have all your resources already connected in pre-defined scenes and you build the scene asset bundles.

    But think of what happens if you have a game with tons of textures that can be present in any of the game scenes and lots of texts and tons of sounds due to the game supporting up to 9 languages (which involves multiple textures for localizing some texts, multiple fonts, multi-language sounds etc.)?
    You will have quite a pumped up "Resources" folder in your project that is very nicely managed by the engine as it is. And as I said you will need quite a big shared assets bundle to create and load into memory in this case. :)

    I've worked on projects like these using Unity (no, not a MMO :D ) and still am and it's not pretty when you have a stable resource management offered by the engine when building on iOS but when going to the Android you need to explode everything into asset bundles and manage them so you don't overflow the memory as it happened many times.

    I'm pretty sure many developers/companies that had to port their projects to the Android at some point feel the same way. ;)

    Edit:
    By the way Capyvara, I don't see the game on the Market when searching it with a Samsung Galaxy S. :(
     
    Last edited: Nov 17, 2011
  19. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    I personally like the assets bundle system but I see it to be more usefull when your game is actually designed to stream assets dynamically to add some extra content to it or for in-app purchases or other stuff. Not when you have a 200MB game designed to have the resources locally and you then have to externalize your 190MB of assets just because Google has designed their Market system from the "ass side of the donkey" as dreamora said in an earlier post. :)
     
  20. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    I think that the problem with this additional APK approach is that probably Google will not support it on market, at least I don't know of any application that used this approach. But I didn't found any place telling that google explicitly forbids it, so there's still hope.

    About my game, my reasoning was to achieve executable and data separation, Google has plans to provide hosting for up to two 2gb files together with the APK (http://www.androidpolice.com/2011/0...p-size-limit-to-4gb-tweaks-the-return-policy/), but they don't mention big size apk's.

    To give you an idea, our game has more than 3k assets (textures, animations, models, scriptableobjects), thanks to compression technologies we could keep the final compressed data under 200mb, but the repository is more than 10gb. We added asset bundles support in the last two months of the project and it scaled well.

    But I do agree that even not requiring a lot of changes in the project, it was a lot of work, we had to do a custom build pipeline, create the bundle loading and updating system, and so on.
     
  21. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Thank you for your feedback Capyvara. It really helps.
    Exactly my friend. Like you said, it involves a fair amount of extra work that kind of beats the initial purpose of Unity: code once and deploy everywhere. :D

    I also have a backup plan to just use only one APK but it's still in the works.
    I'll keep you guys updated!
     
  22. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    So as a conclusion to the first approach of making a generic installer using 2 apps:
    1) One being an Installer that is uploaded on the Android Market
    2) The second one being the actual signed game APK being uploaded on a separate server

    This kind of fails because the user will have to enable the "Unknown sources" option on the Android device so he can allow the Installer to install the second APK (the game APK) downloaded from a Non-Market server.

    Not many clients will accept this solution if they want to have their game as an official Android Market game.

    But I will post the first Installer Test project code anyway just in case it helps someone out there.
     

    Attached Files:

    Last edited: Nov 22, 2011
  23. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    I am working on a second possible solution of doing this.
    This will involve only one APK with 2 activities.
    The first activity will download the missing assets and the second one is the default Unity activity that starts the engine.

    Basically I am trying remove the Data folder from the Unity game APK, compress it to a zip and that will stay on a separate server.
    Then repackage and re-sign the game APK that will contain the 2 activities mentioned above.
    Every time the Installer activity will start to check if the Data folder has been downloaded on the SD card. If not, download the zip file, unzip it and there will be the Unity Data folder with all the game scripts and resources.

    The question here is HOW to tell Unity to look somewhere else for the Data folder, instead of the current APK.
    On the iOS you can easily do this before initializing the engine with a function inside the AppController.mm called UnityInitApplication(const char * dataFolderPath)
    But I can't find a way to call this function on the Android UnityPlayer.

    If anyone out there can help with this issue please give any feedback.
    I feel that this solution is going to be the BEST out there instead of using AssetBundles.

    Another thread related to this Unity "Data" folder issue is posted here:
    http://forum.unity3d.com/threads/112703-Override-Unity-Data-folder-path
     
  24. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Last edited: Nov 22, 2011
  25. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Tried the suggestion from colargol and although it seemed to be the logical solution to the missing puzzle piece, something doesn't work as expected. Unity is not loading libmono.so library. :(

    I'll keep investigating some more.
     
    Last edited: Nov 23, 2011
  26. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Found and solved the issue with colargol's suggestion. It works perfectly for what I need.

    I am starting to implement the new custom activity that will download a second APK and will just contain the engine assets and libs. It's not going to be an executable/installable APK. Then the custom activity will just initialize the Unity engine with the path to that APK so it will look for it's libs and assets inside the archive. (tested it and it works)

    So this is going to be awesome. Porting an iOS project to Android will mean to just plug this custom activity that will act as an installer and launcher at the same time. Resources.Load( ) won't have to be refactored to load AssetBundles for big projects anymore!

    As soon as I finish it I will upload the code here. ;)
     
  27. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    131
    Hey Floky, any updates on this project? Sounds amazing!
     
  28. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Yep. Fiinished implementing the entire process:extendable android installer/downloader and unity postprocess build script to automate the building by splitting the unity assets in a separate APK and the android installer and unity launcher in another APK.

    I've been busy with the bugs-fixing phase.
    But the bottom line is: we can now port iOS Unity projects without refactoring the resource management code or being forced to switch to AssetBundles.

    Thanks again for everybody that supported me on this. As soon as I finish bug-fixing and writing a small documentation I will upload everything here as open-source.
     
  29. swiftest

    swiftest

    Joined:
    Apr 30, 2009
    Posts:
    75
    Floky, can't wait to see your solution. Our game is 110 MB, and it's been frustrating trying to solve this in the "Unity" way without having to refactor everything into asset bundles.

    Rant: Why hasn't Unity responded? I'm shocked that the members have had to solve this without any input from Unity especially considering there are other big Unity games that invariably had to deal with this problem like Shadowgun. Why are we forced to reinvent the wheel here?
     
  30. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Hi swiftest,

    Still have to solve some minor issues so I have a stable enough version for production.
    Thanks to the company I work at (Mobility Games, Romania) I am allowed to implement all this at work and make it public for the community as open-source.
    As a progress overview I can tell you that we can now build a 250 MB app for the Android without touching Unity the code with just one click (like Unity was meant to do things). The minor issues are on the Android generic Installer side that has to take care of all the necessary steps to look locally for the APK with the assets, download it and take care of all the problems that can appear when suddenly the external storage SD card is not present anymore when the game is started and stuff like this that can happen on the Android.
    Also the Installer will be able to detect the Android GPU / Chipset type and download the corresponding assets if you built the game optimized for multiple Android devices (for Snapdragon, Tegra 2, PowerVR etc.).

    But I think that in maximum 2 weeks the project will be ready for upload.

    I personally understand the Unity team for not concentrating on this Android issue right now because it's pretty much Goggle's fault for having set those stupid download cache limitations from the beginning. Unity now has bigger and much more important features to think about for the engine right now (Unity 3.5 just around the corner). The Android porting limitation is something more of a side-effect from Google's stupid design decisions.

    If there is something generic enough Unity could help with, it would be to let us have more control upon the Android build phases, so we can have more custom control over the build steps of the final APK not just the post-build phase.

    Shadowgun also had to deal with this problem but they didn't come up with a generic solution for this. They've implemented their code using AssetBundles and they've split their assets into several bundles...about 70MB each I think. The problem with Asset Bundles is that you have to load it entirely into memory to load assets from it and Shadowgun crashes from the start because of low memory on devices like Samsung Galaxy S1. (i've tested it and looked at the logs)
     
    Last edited: Dec 4, 2011
  31. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    131
    Sounds fantastic Floky! I really look forward to seeing your final result and learning from it.
    I can understand the stance from the Unity team. It's not their fault, but rather Googles limitations, unfortunate for us.

    Just a quick question: When the installer downloads the assets APK, does it download it from the marketplace where Google allows you to upload 2gb "data files"? Or would you need to externally host these files?

    Thanks for the great work again.
     
  32. lyh1

    lyh1

    Joined:
    Jun 30, 2010
    Posts:
    92
  33. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    131
    Google lets you upload 2x 2gb data files for free in the market place.
     
  34. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    This system allows you to store the data APK files wherever you want (as long as you can download them back :) ).

    I keep reading on the net that Google already offers an option to store data files up to 2 x 2GB. But please can someone help me with some more info on this? I can't seem to find this kind of option anywhere in their Market control panel or an API to support it so we can manually access our game's data files.
    Also there is no mention about what format will these data files have: one big non-installable APK (like I've done here in this system) or just a plain archive with multiple files and no AndroidManifest.xml or stuff like that?
    For example on their support page it says nothing about the option to upload 2GB data file separately: http://www.google.com/support/androidmarket/developer/bin/answer.py?hl=en&answer=113469
     
    Last edited: Dec 5, 2011
  35. Dan Fury

    Dan Fury

    Joined:
    Jul 18, 2010
    Posts:
    158
    They announced it in May at Google I/O and said it would be ready in June, since then nothing happened.
     
  36. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    470
    Our app was extensively coded for Resources.Load and Resources.UnloadUnusedAssets. The conversion to Android was not easy at all. We ended up using the AssetBundle approach for all of our dynamic textures in the game. Unfortunately, there are just a lot of these assets and the speed of obtaining a texture from an AssetBundle is significantly slower than obtaining it from the resource manifest.

    What we ended up doing was creating a Resources wrapper class and forwarded all of our load requests to this wrapper and on Android the wrapper handles these loads completely differently than on the other platforms. I wish that Unity made it easier to externalize the resources directory on Android as that would have made downloading the assets file a lot easier. Instead we ended up creating an asset bundle for EVERY dynamic texture (because our game didn't have a strong coupling of what images could be loaded at what time).

    Edit: Also those that are saying 50MB you should REALLY be saying 30 MB is your max because Samsung phones have a restricted download size that is even greater than the standard Android .apk size.
     
  37. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Yep. We did the same thing. And not only it was slower but the memory fragmentation was also bigger and the game stability suffered a lot.

    That's correct. It was mentioned in one of the earlier posts on this thread.
    Hopefully this system will solve all these problems in an acceptably easy way. ;)

    That's what I thought...the bastards. :)
     
    Last edited: Dec 5, 2011
  38. elindie

    elindie

    Joined:
    Aug 23, 2011
    Posts:
    7
    Hey Floky,

    Just wanted to thank you for all the work you're doing on this. Is there anyway I can offer my help? I'm building my own app loader at the moment but if I can assist in a solution for the community I feel that would be a better use of my time.

    - Brandon
     
    Last edited: Dec 8, 2011
  39. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Hi Brandon,

    Thank you very much for your support. At the moment I'm pretty stressed with a deadline involving this Android build system I'm talking about on this thread and I can't afford the time to involve external developers on it right now on the last mile of the development. Especially considering that the custom build system is already working great so far. But thank you again for your support.

    Although, you can still help us with some research for a feature that we're trying to nail down for the Installer part of this system. We're trying to find an easy way to query the Android OS for some device information like: GPU model and GPU vendor of a device. From a simple Android Activity how can we query the OS for some hardware info like this one?
    We're currently testing an implementation based on low-level GL calls to find this info (http://www.opengl.org/wiki/GlGetString) but it's pretty stupid not be able to use a special SDK API to determine this.
    Using the GL requires to initialize a GL rendering context in the current Activity which messes up the Activity layout just to be able to execute some low-level GL calls to get this kind of info.
    If you can find anything that you've tested and saw that it's working then please open a thread about it on this forum and post your solution and also post a link here for us too. :)

    I wish you the best of luck with it and I will PM you as soon as I upload this project online for the community as open-source so anybody can contribute to it to make it even better or to just learn from it.

    This build system involves a generic Eclipse Installer Template project that can be very easily extended and customized to your hearts desire and a nice tool that is automatically called by a Unity post-process build script to auto-split the Unity final game APK into:
    1) an Installer using your customized installer as a jar plugin (from the Eclipse project)
    2) and another archive containing all the game data assets from Unity (not converting anything into AssetBundles and the archive is NOT a separate installable application)
    All this without touching your Unity code.
    Finally, you place your game data archive on the server you desire. (maybe even on one of Google's servers when they will finally release this kind of upload option...one day) and you install the Installer on the device. The Installer will start with your customized UI interface and it will download the game data archive after which it will start the game.

    So the system works, we just have to implement a way for the Installer to determine what GPU model the device uses to be able to have multiple game asset archives optimized for different GPUs and the Installer will download the right one. Also we still have some bugs we need to fix but so far so good.
     
    Last edited: Dec 9, 2011
  40. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    News about this system: we have tested it on the Market and it works perfect.
    No requirements to activate "Unknown sources" option on the users device, no AssetBundles, no need to code your own Installer to download game assets!

    We also managed to implement in the built-in Installer a way to detect the device GPU at run-time giving the option to download assets optimized for a specific device.

    We still have some bugs to crush and documentation to update and very soon the build system will be uploaded for the community.
     
  41. syslord2k2

    syslord2k2

    Joined:
    Apr 12, 2011
    Posts:
    23
    I just finished uploading our apk to the Android Market (Giana Sisters), here is my approach:

    I created an Android Application like the one described here

    I added an activity that created a GLSurfaceView to query GL Extensions String and pass it to the Downloader Activity that simply has a text stating that additional content has to be downloaded and a button that starts an AsyncTask to download a file depending on the available GL Texture Compression and the screen size.

    I then set a flag at the end of the download that showed that the download has finished successfully and started the UnityplayerActivity while overriding the getPackageCodePath() method to point it to the downloaded apk file.

    On every start of the app it checks if the downloaded file exists and the downloaded flag is set and then starts the app, if either of these returns false it shows the download dialog again.

    The last thing i did was to overwrite onPause() in my activities to close down the ProgressDialog showing the DownloadProgress, cancel the AsyncTask, delete the partial downloaded file and call finish() to make sure the app would not proceed to download in the background and trying to start the game when it is finished.

    For the downloaded apk i set another activity as main activity that simply shows a text stating that this apk does not contain executable code.

    Error handling catches:

    NoSuchMethodException (for getExternalFilesDir() with api level 8 or lower), it than creates the file with this path:

    Code (csharp):
    1. Environment.getExternalStorageDirectory().toString()  +"/Android/data/"+getPackageName()+"/files/myapk.apk"
    Connection Loss
    No Connection available on Button click
    SD Card Not Mounted (ExternalFilesDir unavailable)

    I would think that there are more elegant ways to do this but i did not touch a single line of Unity Code and the whole thing is now up and running in Android Market within one week since i started, so far this works exactly as i wanted it to be.
     
  42. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Thanks for the detailed feedback syslord2k2. That's great!

    On the Installer Android coding side, that's pretty much the same steps we've done. The difference is that we invested a little more time to make a generic system without even needing to integrate your Unity project with Eclipse. We've managed to make an automated "drop in any UnityProject" tool that will automatically split your built APK into 2 separate APKs, the second one with the assets being un-installable.

    We will post this online for anyone to customize the installer and make use of this tool very soon.
     
  43. syslord2k2

    syslord2k2

    Joined:
    Apr 12, 2011
    Posts:
    23
    S***, would i have known that i would have saved myself the last week :/
     
  44. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    I don't know why you say that. I think that you invested your time in something that worked more than ok in the end (like you said) and at the same time provided you with a great learning experience. :) What's 1 extra week of development? :)
     
  45. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    Thanks for looking into this floky!
     
  46. sampson3333

    sampson3333

    Joined:
    Jul 17, 2009
    Posts:
    9
    My application is more than 50M, how to upload? My application is 115MB
     
  47. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    Any news on the project? :)
     
  48. floky

    floky

    Joined:
    Oct 6, 2010
    Posts:
    260
    Yep! The project will be uploaded this week. Though I can't say which day exactly. :)
    Stay tuned. :)
     
  49. myprabath01

    myprabath01

    Joined:
    Sep 15, 2011
    Posts:
    33
    Excited about your tool. Gr8 Work Buddy.
     
  50. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    Hope to see this tool soon :)
     
unityunity