Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How did Shadowgun reduced APK to 6 MB?

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

  1. srikanth.basappa

    srikanth.basappa

    Joined:
    Feb 16, 2012
    Posts:
    6
    Floky awesome job! I feel the tool is priceless.

    At this point I feel it should work fine for folks not using other plugins or rather plugins which uses the R.java class. I am still having issues with the new build. Currently the app crashes with an error saying the R.layout.installer_main doesn't exist :-o. I know this is because of other plugins used in the app.

    Thanks.
     
  2. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Hi there,
    At this point the builder should work just fine with many android plugins that don't try to embed their own R.java class into their JAR plugin file. For Unity this is wrong. I will soon release a simple solution to allow 3rd party android plugins to export their jar without the need for embedding their R.java class and at the same time allow them to load their UI xml layouts without problems.

    I can better help you if you send me a PM with the Installer Eclipse project so I can see how you configured it, also the Plugins/Android/ folder from your Unity project or at least the list of files from it.

    Cheers!
     
  3. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Didn't manage to test with Unity 3.5. I've heard they changed a lot of things in the background when they're building for Android now. If this is true, most likely the tool will fail. But I'm on it. I will start testing on Unity 3.5 as soon as possible and get back with a feedback here.
     
  4. srikanth.basappa

    srikanth.basappa

    Joined:
    Feb 16, 2012
    Posts:
    6
    IT WORKS!!!

    Floky,
    I finally got it work. It dowloaded the gameData.apk and runs just fine. It should now work with any number other plugins in the Android folder.

    Here is what I did, I copied over the contents from the res folder in the EclipseTemplate project to Plugins/Android/res folder. Now when Unity builds the R.java there is now conflicts and it can find the install_main layout etc.

    Thanks a ton for all the support!
     
  5. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Awesome! Glad it's working for you!

    Wait wait wait! :D Something is weird then! This means that you didn't set the "res" folder path when the tool first starts and asks you to browse and select the Installer "res" folder. The tool automatically copies the "res" folder from your Installer Eclipse project when you start building! :)

    You applied a hacky solution but I suggest you press the "Installer Res Path" button in the tool BEFORE pressing "Start Build", select the "res" folder from your Installer project and the tool should copy the "res" folder where it needs it. :) It would really help me to see if it works ok for you if you correctly setup the "res" path in the builder tool.
    You shouldn't need to manually copy the Installer "res" folder. :)

    Please check this when you have some time and give me a feedback so I can see if it's maybe a possible hidden bug in the tool so I can fix it.

    Thanks a lot for your feedback!
     
    Last edited: Feb 21, 2012
  6. C4MProdDev

    C4MProdDev

    Joined:
    Jul 9, 2009
    Posts:
    107
    Hi floky.
    First of all, thanks for your tool. If I can manage to make it work, it will be the best thing ever ^^
    The problem is that I successfully do all step of the read me or what you said last here, but when running the installer on device, the application crash even the first time and I have this :
    Code (csharp):
    1. 02-21 16:43:33.336: D/dalvikvm(6956): Trying to load lib /mnt/asec/com.myCompagny.myGame-2/lib/libmono.so 0x41331ce8
    2. 02-21 16:43:33.339: D/dalvikvm(6956): Added shared lib /mnt/asec/com.myCompagny.myGame-2/lib/libmono.so 0x41331ce8
    3. 02-21 16:43:33.351: E/linker(6956): ERROR: Library '/assets/libs/armeabi-v7a/libmono.so' not found
    4. 02-21 16:43:33.351: W/dalvikvm(6956): JNI_OnLoad returned bad version (0) in /mnt/asec/com.myCompagny.myGame-2/lib/libmono.so 0x41331ce8
    5. 02-21 16:43:33.379: D/AndroidRuntime(6956): Shutting down VM
    6. 02-21 16:43:33.379: W/dalvikvm(6956): threadid=1: thread exiting with uncaught exception (group=0x40a411f8)
    7. 02-21 16:43:33.390: E/AndroidRuntime(6956): FATAL EXCEPTION: main
    8. 02-21 16:43:33.390: E/AndroidRuntime(6956): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myCompagny.myGame/com.unity3d.player.UnityPlayerActivity}: java.lang.RuntimeException: unable to link library
    I know I use a lot of plugin (Flurry, MoPub, TapJoy and open feint). They're all from Prime31 exept Openfeint witch is the official one.
    I hope it's not because of them and it's just something wrong from what I done.

    From the error log, do you know where it could be from plz?
     
  7. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    These type of errors have too many possible factors. Most common issues are caused by mistakes in the AndroidManifest.xml setup.
    If you have troubles in making the tool work please try to build the demo project I provided by setting up the Installer Eclipse project and exporting the Installer plugin in the demo Unity project you will find in the package. You will see in the Unity project that there already is an installer plugin called "unityInstaller.jar" (in Assets/Editor/Plugins/Android/).

    You can also build the project as is first so you can see if the Installer starts correctly on the device but it won't be able to download the game data file because you have to setup your download link in the Installer template project and re-export the Installer plugin overwriting the one already in the demo project (unityInstaller.jar).

    As a general rule of thumb: if you have issues making the tool work in your game project, try to first set it up in a separate simple and clean Unity project because it's easier to keep track of the mistakes.

    Using the tool requires some basic knowledge of how to use an Eclipse Android project, about setting up the AndroidManifest.xml and exporting to a jar file.

    So, try building and making the demo Unity project from my package to work first. Also double check the instructions of the tool. ;)

    As I said above to srikanth.basappa , to better debug your problem and help you I will need the AndroidManifest.xml from the Unity project, an archive with the contents of the Plugins/Android/ folder (or at least a list of the files inside of it), the Installer Eclipse project you tried making the tool to work with and the bundle name of the Unity project.

    Cheers!
     
    Last edited: Feb 21, 2012
  8. srikanth.basappa

    srikanth.basappa

    Joined:
    Feb 16, 2012
    Posts:
    6
    Hey Floky,
    Sorry everything is working fine now. Yes I did mess up while setting the res path. I set the Plugins/Assets/Android/res instead of the res folder in the installerTemplate(minor detail doh!).

    After that it seems to be working fine with other plugins. Until this after when I added push library. To be specific the following line below:
    <permission android:name="com.blah.blah.permission.C2D_MESSAGE" android:protectionLevel="normal" />

    Now crashes the app with the following errors:
    02-23 16:16:09.107: E/AndroidRuntime(5139): FATAL EXCEPTION: main
    02-23 16:16:09.107: E/AndroidRuntime(5139): java.lang.NoClassDefFoundError: com.blah.blah.R$layout
    02-23 16:16:09.107: E/AndroidRuntime(5139): at com.userCustom.installer.InstallerActivity.onInstallerInit(InstallerActivity.java:84)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at com.flk.installer.InstallerBaseActivity.installerInit(InstallerBaseActivity.java:181)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at com.flk.installer.InstallerBaseActivity.handleMessage(InstallerBaseActivity.java:215)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at android.os.Handler.dispatchMessage(Handler.java:95)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at android.os.Looper.loop(Looper.java:137)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at android.app.ActivityThread.main(ActivityThread.java:4424)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at java.lang.reflect.Method.invokeNative(Native Method)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at java.lang.reflect.Method.invoke(Method.java:511)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    02-23 16:16:09.107: E/AndroidRuntime(5139): at dalvik.system.NativeStart.main(Native Method)

    If the remove that line in the manifest it works! So weird, trying to figure out this issue now.

    Fylen's issues totally relates to him missing the InstallerActivity and the LaunchAcivity in the AndroidManifest. This was the first problem I had.

    thanks.
     
  9. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Hi there. Glad it's working for you. Well...was working. :)
    Now it seems to be another mistake regarding the unity bundle name: "com.blah.blah".
    The most obvious error in the log is:
    Which I think it's caused by not having anymore (for some reason) the android package name of the Installer Eclipse project to be the same as your unity project bundle name. This usually causes issues because the Installer can't find the android sdk generated R class anymore at runtime or any other inner classes from it (like "layout").

    In the next android builder tool version this Installer <-> android R class dependency will be automatically handled so users won't have to worry about this minor setting anymore.

    Please tell me if this helped.
     
    Last edited: Feb 24, 2012
  10. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    Floky, when I import the folder UnityInstaller I receive this error:
    [2012-02-27 14:59:04 - Installer] Project has no project.properties file! Edit the project properties to set one.
     
  11. buffonomics

    buffonomics

    Joined:
    Jun 10, 2009
    Posts:
    59
    Hey Spartan, I haven't gotten around to downloading the Installer yet myself, but even I have a feeling that this is NOT how it's supposed to be used.

    Intuition tells me you should be opening that with eclipse or whatever you use for NORMAL, unity-less, android dev. I don't think it was ever meant to be a unity plugin, but as a wrapper [or linker] around [to] your Unity exported APKs as an easy way to deal with market size limits. I would recommend doing some readup on this thread to better understand what the tool is meant to address.

    Cheers m8.

    EDIT: Sorry I assumed you were somehow trying to import that into the Unity IDE. Ignore this then.
     
    Last edited: Feb 27, 2012
  12. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Hi Spartan,

    I'd check to make sure that the android SDK that it is linking to is the one that you have installed. If not, go into Java Build Path (right click on the project folder in eclipse) and add the appropriate SDK that you have installed on your machine.

    Also in the same "properties" window from right-clicking on the Java Build Path, set the project build target to the SDK that you have installed on your machine.

    I've only done preliminary stuff with this installer, but it really looks like the real deal and a life saver (used it to do a test deployment of the included match game). I still need to upgrade to 3.5, but I'm having serious doubts as I may lose this awesome tool to do my next android deployment. :(
     
    Last edited: Feb 27, 2012
  13. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    That's not the Installer Eclipse project folder. Look for InstallerTemplateProject. Read the instructions carefully. :)
     
  14. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Regarding the Unity 3.5. I'm already on it. Just downloaded it and in the next few days i'm doing some tests and we'll get back to you guys with some feedback regarding any compatibility issues.
    If there's something wrong i will make it compatible with 3.5 also.
     
  15. Eric-Laberge

    Eric-Laberge

    Joined:
    Jan 20, 2011
    Posts:
    26
    Hello!

    I've taken the time to try your solution, and it looks very promising!

    Two things I've stumbled upon:
    1- I can't figure out how to use my app icon, it defaults to the green android one :-/

    2- I have an intro video in the StreamingAssets folder and it doesn't seem to work out of the box when the game data is split (using iPhoneUtils.PlayMovie), while it plays correctly on the whole bundle.

    Also, how secure is the standalone data bundle? Could someone download the .apk from the public server and have the whole game?

    Edit:
    Yeah, I read the whole thread this morning and I think my brain was processing too much data... The security issues kinda slept...
     
    Last edited: Feb 27, 2012
  16. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    The security matter has already been discussed. Please search previous posts. But to make a long story short: the security is about the same as the one offered by Android Market. Security can be improved and you are welcome to do so. :)

    Regarding the app icon, theres nothing special to do but set it in Unity correctly and it should work. Unless you discovered a bug from my tool and i missed it. But so far I couldn't reproduce it.
    Anyone else has this problem?

    Regarding the StreamingAssets folder it is something interesting... This depends on how Unity is searching for the StreamingAssets path. I'll have to look into it and get back to you with a feedback.
     
    Last edited: Feb 27, 2012
  17. Eric-Laberge

    Eric-Laberge

    Joined:
    Jan 20, 2011
    Posts:
    26
    I found the problem in the AndroidManifest.xml file.
    By adding the
    android:icon="@drawable/app_icon" attribute
    to the <application> tag, the icon came back :)

    I'm on Unity Pro 3.4.2
     
  18. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Yep, all android applications have to specify the "icon" attribute in the manifest xml file. You can check the AndroidManifest.xml used in the Unity Sample project included in the tool package so you have a working manifest xml example.
    One issue solved! :)

    I'll investigate as soon as I can the StreamingAssets issue and reply back here.
     
  19. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    Hi Floky,

    After importing EclipseInstallerTemplateProject on Eclipse, when I try to export the JAR file I get the following error:

    The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
     
  20. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Hi spartan,

    I'm really sorry but I don't have the free time on my hands to help you step by step to figure out how to work with an Eclipse project.
    Like I said in a previous post, using this android builder tool requires at least the basic knowledge of working/configuring an Eclipse android project and of course some basic Java and Android SDK knowlegde so you can customize the installer the way you want.
    I mean no disrespect, really, but I just don't have the free time. Please google for issues related to Eclipse Android project setup, about Android SDK and Java build path setup before asking for help at each step of the process.
    If you encounter technical issues with the tool or have found a bug related to it I'm more than happy to help you as soon as I have the time.

    Thank you for your understanding.
     
  21. jhhoward

    jhhoward

    Joined:
    Mar 2, 2012
    Posts:
    6
    Hi Floky,

    Firstly, great job on writing this installer system. We have been struggling to find a way to upload to the Android Marketplace for months and a rare bug in Unity's asset bundle system has prevented us from making much progress with asset bundles.

    The installer system works almost perfectly, but with one exception. Our game is required to support the Sony Xperia Play, which has a special touchpad on the device, used for controlling the character. Unity fully supports this and we haven't had any problems until now. When the installer is used, the touchpad stops working.

    I dug a little deeper and noticed that the generic AndroidManifest.xml created by unity uses "com.unity3d.player.UnityPlayerProxyActivity" as the main activity. I modified the 'UnityLauncherActivity' to be a subclass of 'UnityPlayerProxyActivity' instead of 'UnityPlayerActivity' but now the game crashes when it tries to start (after the installation is complete)

    Here is what the results look like on the logcat:

    D/Installer(12307): onGameCanStart() called!
    D/Installer(12307): Loading game from: /mnt/sdcard/Android/data/com.tastypoisongames.prpg/files/gameData.apk
    D/Installer(12307): Closing the Installer activity...
    I/ActivityManager( 189): Starting: Intent { cmp=com.tastypoisongames.prpg/com.flk.unityLauncher.UnityLauncherActivity } from pid 12307
    I/ActivityManager( 189): Starting: Intent { flg=0x10000 cmp=com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity } from pid 12307
    D/dalvikvm(12307): Trying to load lib /mnt/asec/com.tastypoisongames.prpg-1/lib/libmono.so 0x2afc7fa0
    D/dalvikvm(12307): Added shared lib /mnt/asec/com.tastypoisongames.prpg-1/lib/libmono.so 0x2afc7fa0
    E/linker (12307): ERROR: Library '/assets/libs/armeabi-v7a/libmono.so' not found
    W/dalvikvm(12307): JNI_OnLoad returned bad version (0) in /mnt/asec/com.tastypoisongames.prpg-1/lib/libmono.so 0x2afc7fa0
    D/AndroidRuntime(12307): Shutting down VM
    W/dalvikvm(12307): threadid=1: thread exiting with uncaught exception (group=0x2aac8560)
    E/AndroidRuntime(12307): FATAL EXCEPTION: main
    E/AndroidRuntime(12307): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity}: java.lang.RuntimeException: unable to link library
    E/AndroidRuntime(12307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1630)
    E/AndroidRuntime(12307): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1646)
    E/AndroidRuntime(12307): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
    E/AndroidRuntime(12307): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:936)
    E/AndroidRuntime(12307): at android.os.Handler.dispatchMessage(Handler.java:99)
    E/AndroidRuntime(12307): at android.os.Looper.loop(Looper.java:123)
    E/AndroidRuntime(12307): at android.app.ActivityThread.main(ActivityThread.java:3652)
    E/AndroidRuntime(12307): at java.lang.reflect.Method.invokeNative(Native Method)
    E/AndroidRuntime(12307): at java.lang.reflect.Method.invoke(Method.java:507)
    E/AndroidRuntime(12307): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    E/AndroidRuntime(12307): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    E/AndroidRuntime(12307): at dalvik.system.NativeStart.main(Native Method)
    E/AndroidRuntime(12307): Caused by: java.lang.RuntimeException: unable to link library
    E/AndroidRuntime(12307): at java.lang.Runtime.nativeLoad(Native Method)
    E/AndroidRuntime(12307): at java.lang.Runtime.loadLibrary(Runtime.java:432)
    E/AndroidRuntime(12307): at java.lang.System.loadLibrary(System.java:554)
    E/AndroidRuntime(12307): at com.unity3d.player.UnityPlayer.<init>(Unknown Source)
    E/AndroidRuntime(12307): at com.unity3d.player.UnityPlayerNativeActivity.onCreate(Unknown Source)
    E/AndroidRuntime(12307): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    E/AndroidRuntime(12307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1594)
    E/AndroidRuntime(12307): ... 11 more
    W/ActivityManager( 189): Force finishing activity com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity
    W/ActivityManager( 189): Activity pause timeout for HistoryRecord{2b2edb58 com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity}​

    So it looks like it can't find the libmono.so which is needed for the UnityPlayerNativeActivity. I think that the native activity is needed to access the touchpad.

    So next I tried copying in the assets/libs folder and the assets/bin/Data/Managed folder into the installer apk file. These two folders contain the libmono.so, libunity.so and mscorlib.dll respectively. This bumps up the size of the apk quite a bit which isn't ideal but still remains under 10MB

    Now the game gets a little further but still dies and I'm a little stumped. Here is the logcat:

    D/Installer(12420): onGameCanStart() called!
    D/Installer(12420): Loading game from: /mnt/sdcard/Android/data/com.tastypoisongames.prpg/files/gameData.apk
    D/Installer(12420): Closing the Installer activity...
    I/ActivityManager( 189): Starting: Intent { cmp=com.tastypoisongames.prpg/com.flk.unityLauncher.UnityLauncherActivity } from pid 12420
    I/ActivityManager( 189): Starting: Intent { flg=0x10000 cmp=com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity } from pid 12420
    D/dalvikvm(12420): Trying to load lib /mnt/asec/com.tastypoisongames.prpg-1/lib/libmono.so 0x2afc6338
    D/dalvikvm(12420): Added shared lib /mnt/asec/com.tastypoisongames.prpg-1/lib/libmono.so 0x2afc6338
    D/proxy (12420): Added shared lib /assets/libs/armeabi-v7a/libmono.so 0x43a19b40
    D/proxy (12420): No JNI_OnLoad found in /assets/libs/armeabi-v7a/libmono.so 0x43a19b40
    D/dalvikvm(12420): Trying to load lib /mnt/asec/com.tastypoisongames.prpg-1/lib/libunity.so 0x2afc6338
    D/dalvikvm(12420): Added shared lib /mnt/asec/com.tastypoisongames.prpg-1/lib/libunity.so 0x2afc6338
    D/proxy (12420): Added shared lib /assets/libs/armeabi-v7a/libunity.so 0x43b0f4f0
    D/dalvikvm(12420): GC_EXTERNAL_ALLOC freed 241K, 52% free 2679K/5511K, external 1682K/2130K, paused 23ms
    D/dalvikvm(12420): GC_FOR_MALLOC freed 52K, 46% free 3427K/6343K, external 2483K/3101K, paused 14ms
    I/dalvikvm-heap(12420): Grow heap (frag case) to 9.299MB for 1048592-byte allocation
    D/dalvikvm(12420): GC_FOR_MALLOC freed 0K, 41% free 4451K/7431K, external 2483K/3101K, paused 14ms
    I/AKMD2 ( 122): akmd2 : Compass Opened.
    D/DASH - select( 189): sensors_select_callback: select canceled by request
    D/DASH - select( 189): sensors_select_callback: select canceled by request
    D/DASH - select( 189): sensors_select_callback: select canceled by request
    D/libEGL (12420): loaded /system/lib/egl/libGLES_android.so
    D/libEGL (12420): loaded /system/lib/egl/libEGL_adreno200.so
    D/libEGL (12420): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
    D/libEGL (12420): loaded /system/lib/egl/libGLESv2_adreno200.so
    D/Unity (12420): Creating OpenGL ES 1.x context (RGB16 565 16/0)
    I/ActivityManager( 189): Displayed com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity: +1s350ms (total +1s949ms)
    I/com.sonyericsson.semcsuite.app.PSSuiteActivity(11940): onStop
    I/com.sonyericsson.semcsuite.data.PackageDataSource(11940): Dataset is invalidated
    D/DASH - select( 189): sensors_select_callback: select canceled by request
    E/InputDispatcher( 189): channel '2b2f9de8 com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
    E/InputDispatcher( 189): channel '2b2f9de8 com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
    I/ActivityManager( 189): Process com.tastypoisongames.prpg (pid 12420) has died.
    I/WindowManager( 189): WIN DEATH: Window{2b3408e8 SurfaceView paused=false}
    D/Zygote ( 111): Process 12420 exited cleanly (1)
    I/WindowManager( 189): WIN DEATH: Window{2b2f9de8 com.tastypoisongames.prpg/com.unity3d.player.UnityPlayerNativeActivity paused=false}​

    It looks like this line is the problem:
    D/proxy (12420): No JNI_OnLoad found in /assets/libs/armeabi-v7a/libmono.so 0x43a19b40

    My knowledge of Android isn't great so perhaps I'm missing something here. Can you think of a way to successfully subclass the UnityPlayerProxyActivity so that we can get native code support?

    Your help would be greatly appreciated!

    James
     
  22. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Hi James,

    Thanks for your feedback. It's very detailed and it will be very helpful.
    I don't have an XPeria Play to test on so that's why I probably missed that but I will try to fix this issue this weekend and get back to you.
     
  23. matrix211v1

    matrix211v1

    Joined:
    Jan 20, 2009
    Posts:
    193
    Before I even try this, does anyone know if this works with the "StreamingAssets" directory? I got 20 files in there at 80mb total.
     
  24. yahodahan

    yahodahan

    Joined:
    Apr 26, 2009
    Posts:
    1,380
    Just found this, wanted to give a huge +1 to you for all the work! This will be a lifesaver for many Unity folks :D

    Can't wait to give it a shot...when I'm not at work ;)
     
  25. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Currently no, it doesn't work correctly with the StreamingAssets folder. It seems a user found an issue in this process that fails when trying to load a movie from the StreamingAssets folder.
    I'm still investigating this matter because this seems to be a rock in the road from inside Unity that doesn't allow me to override the StreamingAssets folder path too.

    Because this tool splits all unity content into 2 separate APK files, although i'm telling Unity to search for it's resources from another APK file, it seems that the PlayMovie(...) method is ignoring the overridden game data assets path.
    Still searching for a solution.

    The easiest solution that will work is if I don't move the streaming assets data file that unity generates and leave it in the Installer APK, I think it should work but it will make the installer APK big again.
     
    Last edited: Mar 5, 2012
  26. Chris-Clark

    Chris-Clark

    Joined:
    Jan 16, 2012
    Posts:
    130
    Hey floky,

    I've been following this thread since the beginning. I don't have a need for it yet, but what you've done is amazing and I will definitely use it in the future.

    Thought I'd let you know that Google finally got around to doing the 'extra' files support they promised. Check it out.
    http://android-developers.blogspot.com/2012/03/android-apps-break-50mb-barrier.html

    If you were to figure out how to support that with this tool you've created, that would be something I'd pay a lot of money for. If you do do it, and release it free that's awesome for everyone, just want to let you know there is a major demand for it.

    Integrating it with the data files on the Android Market's servers would be just amazing. I just hope that their method actually works with your method on Unity.
     
  27. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Thank you for your kind words! This is truly a great piece of news! Google finally managed to hold on to their end of the promisse. :)

    So this means a lot of changes and cool things my friends. I will start modifying the builder tool as soon as possible.
    This MUST be supported! :) Brace yourselves cause we're going for a cool ride! :)
     
  28. jhhoward

    jhhoward

    Joined:
    Mar 2, 2012
    Posts:
    6
    This is certainly great news about Google finally coming through with their data hosting. We were worrying that we would have to pay for our own hosting and anyone pirating our game would put extra stress (and cost) on our servers.

    Floky, I'm not entirely sure but the problem you were describing with playing movies might be the same problem that we are having with launching the UnityPlayerNativeActivity. If we could override the data paths for the native activity and movie activity classes then perhaps we could also get the movie streaming / native touchpad working.

    Did you find time to try subclassing your UnityLauncherActivity from the UnityPlayerProxyActivity class yet?

    James
     
  29. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Yes James! Really sorry got caught up in more work and forgot to reply to you. I also tried subclassing the UnityPlayerProxyActivity class and it's definitely an issue.
    The issue seems to actually be with the way the Proxy activity is made. Overriding the engine assets path for the proxy activity is not overriding the native player activity. It seems it's been overlooked by Unity maybe because they didn't see this useful at the time.

    I also have possible fix that I'm working at for this and I think I can fix the proxy activity issue. I'm continuing some tests for this tonight and as soon as see that it's fixable I will tell you guys tonight.

    The streaming assets path issue is different. Too many details to share right now but as soon as I fix the proxy activity I will further look into that too because the proxy activity is much more important at the moment.
     
  30. jhhoward

    jhhoward

    Joined:
    Mar 2, 2012
    Posts:
    6
    Hi again Floky,

    I managed to get the path redirection working on the UnityPlayerNativeActivity, so now the touchpad works!

    I actually used a java decompiler to see what the UnityPlayerProxyActivity actually does internally. It actually checks to see which version of Android your device is using and then launches an appropriate activity. If your device is SDK 9 or greater (Gingerbread and above) then it will use the UnityPlayerNativeActivity, otherwise it will just use UnityPlayerActivity. I read somewhere in Unity's docs that there are some advantages to the native activity with better input response latency, but this feature is only available to Gingerbread and later.

    So it seems the Xperia touchpad is only supported through the native interface. I made another class based on your UnityLauncherActivity, which I called UnityLauncherNativeActivity. It is essentially the same but subclasses the UnityPlayerNativeActivity class instead of the UnityPlayerActivity class.

    Then in the InstallerActivity.onGameCanStart() function I have changed the code to launch the appropriate activity. You also must ensure that you fix up the manifest so that the activity can be started properly. The addition to my manifest looks a bit like this:

    <activity
    android:label="@string/app_name"
    android:name="com.flk.unityLauncher.UnityLauncherActivity"
    android:screenOrientation="landscape"
    android:configChanges="keyboard|keyboardHidden|orientation">
    </activity>

    <activity android:label="@string/app_name"
    android:name="com.flk.unityLauncher.UnityLauncherNativeActivity"
    android:screenOrientation="landscape"
    android:configChanges="keyboard|keyboardHidden|orientation">
    <meta-data android:name="android.app.lib_name" android:value="unity" />
    </activity>

    If you want any extra details, maybe I can get in contact with you via email? It would certainly seem a benefit to have this functionality in the next release of your installer system for anyone else having the same problem :)

    I also wired in Google's LVL system into our version of the installer to check for a valid license before doing a download, although I'm not sure how useful/effective the LVL actually is.

    James
     
  31. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    YES ! I knew it! :) Thanks for confirming this James! Now I don't have to test this theory when I get home.
    I suspected that is the issue because I also found the java sources of the native activity in the Unity App package in the PlaybackEngines folder.
    Thank you for your precious feedback! ;) Keep in touch!

    Can you please confirm if the StreamingAssets folder movies can be played in your case?
     
    Last edited: Mar 6, 2012
  32. jhhoward

    jhhoward

    Joined:
    Mar 2, 2012
    Posts:
    6
    Heh, I didn't even realise that those java source files were included.

    I haven't tried playing a movie from the StreamingAssets folder yet so I can't confirm if it will work. I poked around with the decompiled version of UnityPlayer.class and there is a method called showVideoPlayer() which starts the VideoPlayer activity. It looks like it might be a bit more tricky to get this to work. It might work if we did this:
    - Make a subclass of the VideoPlayer activity class with an override on getPackageCodePath()
    - Make a subclass of the UnityPlayer class with an override on showVideoPlayer() which creates our new version of the VideoPlayer class
    - Modify our UnityLauncherActivity / UnityLauncherNativeActivity onCreate() methods to instantiate our new version of the UnityPlayer class

    It's certainly a bit more work, and it could be a bit messy if say, Unity 3.5 has a slightly different way of handling video processing.
    I'm also not sure if it's necessarily possible to override the showVideoPlayer() method either.

    We have a short splash screen video before the game starts which is currently disabled on our Android build. Since its quite small we might just have to put it in the installer apk instead of the game data one.

    Are you planning on looking into integrating Google's app data storage system? It seems like an obvious path to take now that it is possible to store game data on their servers.

    James
     
  33. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273

    Yeah it's a bit tricky to fix the StreamingAssets issue. I'm gonna look over your suggestion tonight. Can't do that right now.

    Yes I'm planning to support the Google's app data storage system. This will mean to change the core of my Installer to use their installer library and also the builder tool. But it's a bit more tricky cause I need to read some more about it because a developer usually requires to build more than 2 game data files (each for each type of GPU). And google supports only max 2 data files. Gonna have to try and
    find a way to batch a bunch of game data files generated with the tool, together in a zip file somehow and extract at run-time from Google servers only the one i need. Don't have other solutions yet.

    Anyway this will require some serious modifications and right now I first need to fix the unity proxy and streamming assets issues because these are independent from the Google app storage system.
     
    Last edited: Mar 6, 2012
  34. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I'm really glad you guys are looking into this. I'm getting desperate to get this solution implemented for release of our Android update. I'm not an Android guru, but I spend some time looking at the developer documentation. If we "do it the android way" and create multiple APKs and upload them based on the various opengl compression formats we should have multiple expansion APKs per APK we upload, as documented in the "Rules and Limitations" section here.
    In regards to the streaming assets folder. I feel that the video player in Unity is incredibly lacking (no volume control, problems with audio not pausing when the device is paused) and the community might benefit from creation of another more robust VideoPlayer activity that can be started. However, if that's too though, we could download the videos in the expansion pack, uncompress the file and save the files into the persistent data path. Then in Unity we would need to use a file:// URL to play the videos when using the PlayFullScreenVideo path.
     
  35. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    The VideoPlayer clearly has acceptable workarounds. It's not the major issue. But like I said in an earlier post, making the necessary modifications to make this solution to work correctly with the google android app storage system is not something that can be done over night.

    The biggest issue that still concerns me with all this is all this process with uploading multiple APK files offered by Google but then again there is a limitation of only 2 game data files up to 2GB each one. I'm so confused at the moment.
    The thing is that their idea of uploading multiple APK files is NOT the way to go as a game developer that wants to target multiple devices with different GPUs. For Google, uploading multiple APK files actually means cloning your projects for each type of APK you want to build, and maintaining something like this is NOT good:
    What I want to understand so I can have a clear idea of how to approach all this is: does Google offer the 2 x max.2GB data files per uploaded APK (if you choose to uploade multiple APK files)? If yes, then I already have a mega awesome idea of how all of this can elegantly and painless approached. If not, then...I'm still reading on their entire mixed up and messed up process.
     
    Last edited: Mar 6, 2012
  36. Chris-Clark

    Chris-Clark

    Joined:
    Jan 16, 2012
    Posts:
    130
  37. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I think the reason Google initially recommend having multiple project files is that for most developers the primary reason that people want separate APKs is one for phones and one for tablets. If developing that way, it makes sense to have a project file for resources related to the phone and resources related to the tablet as they usually require different UIs.

    The "alternatively" is what we are going to want to do. In the Unity build process we are probably going to need to create builds for different installer APKs, data APKs, and unique AndroidManifest.xml for each of the texture settings (<supports-gl-texture>).

    From what I understand of the Rules and Limitations quoted by TheClarkster we can have 2 data resources PER installer APK we upload in a multipack application entry on the Marketplace.
     
    Last edited: Mar 6, 2012
  38. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Yep, that's what I understand too. Also found this:
    Ok I'm going to have to plan this carefully. Here's a priority list preview:
    1) Fix the StreamingAssets folder issue that can't be used because the Unity movie player fails to access the overriden game data file path
    2) The current tool version (1.0b) fails when trying to use the UnityProxyPlayerActivity which is required for some games (this is as good as solved, just need to integrate it in the tool)
    3) Fix compatibility issues with Unity 3.5.

    While all this will be coming along, I will carefully plan an approach for Googles new app storage solution because it's not going to be a minor modification to support it and it will require some good testing.
     
    Last edited: Mar 6, 2012
  39. ratrodstudio

    ratrodstudio

    Joined:
    Apr 3, 2009
    Posts:
    96
    Google just announced the support of APK expansion files!
    http://developer.android.com/guide/market/expansion-files.html

    APK expansion files
    For applications that exceed the 50MB size limit, now you can attach two expansion files up to 2GB of data each in addition to the 50MB APK.

     
    Last edited: Mar 8, 2012
  40. jhhoward

    jhhoward

    Joined:
    Mar 2, 2012
    Posts:
    6
    Do you know what compatibility issues there are with Unity 3.5? I've yet to try it out yet but most of our projects are being migrated to 3.5 and once the unity project has been converted, there's no way back!
     
  41. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Not to taken as gospel, but Unity is looking into supporting the Android expansion files natively (yay!) however, we should probably expect that in the next Unity version.
     
  42. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Oh boy that would be AWESOME! It would make my life much easier! :))
     
  43. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    I'm getting some build errors when I try it with Unity 3.5. Not sure what's causing it yet. But I'm on it as we speak. Hopefully gonna fix them by this weekend and launch the next version.
     
  44. j-robichaud

    j-robichaud

    Joined:
    Aug 26, 2010
    Posts:
    40
    Did you get this information from an official source?
     
  45. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I asked as a secondary question in a support email begging them to help out here. However, a customer support person most likely isn't in full possession of the facts, so we should probably not get excited by this. The amount of work that would be required to setup the Unity player activity to actively download and do the LVL checks on the app is going to be a lot of work that currently isn't implemented. The "next version" I would probably expect it in the next major version meaning 4.0 if at all.
     
    Last edited: Mar 7, 2012
  46. jtbentley

    jtbentley

    Joined:
    Jun 30, 2009
    Posts:
    1,397
    It would be awesome if Unity supported this natively. We're presently implementing the system for a project, it's certainly a non-trivial thing to do.
     
  47. j-robichaud

    j-robichaud

    Joined:
    Aug 26, 2010
    Posts:
    40
    Useful but low priority feature suggestion for automated build system support (without user inputs):

    Basically it would be to output a config prior the build that AndroidBuilder.jar will digest during the PostProcessBuildPlayer.

    Parameters:
    1. Eclipser installer res path.
    2. The options (Debuggable Build, Sign with DebugKey)
    3. Sign app if "PlayerSettings.Android.keystoreName" is not empty.
    4. The app signing parameters. Can be accessed from Unity3d:
      1. PlayerSettings.Android.keystoreName
      2. PlayerSettings.Android.keystorePass
      3. PlayerSettings.Android.keyaliasName
      4. PlayerSettings.Android.keyaliasPass
    5. Close AndroidBuilder automatically when finished (even with failure).
     
  48. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Yep, something like this can be done, but like you said it's a low priority feature at the moment. :)
    Thank you for your feedback!
     
  49. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    So after doing some tests there didn't to be any problems at all with converting to 3.5. All I did was import the new classes.jar file from the Unity.app bundle and I don't even know if that was necessary.

    I'm trying to come up with a streaming assets solution, and I'm testing out a different video playback engine rather than the Unity one to see if that works any better.
     
  50. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Nice work Ferazel! Thanks again for your help and feedback!

    I've fixed some minor problems that can occur in certain random situations when unity 3.5 for some reason keeps some files from the Temp/StagingArea open and because of this they can't be moved accordingly by the tool, thus crashing it. I've just managed to reproduce this a couple of times but it's been safelly handled.
    All in all Unity 3.5 seems to be more than compatible with the tool but the issue with the StreamingAssets is annoying.
     
    Last edited: Mar 8, 2012