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

Specify libs location

Discussion in 'Android' started by padworx, Sep 14, 2011.

  1. padworx

    padworx

    Joined:
    Mar 22, 2011
    Posts:
    27
    When the user installs an APK built with Unity, He/She could use '$adb install xxx.apk' to install this app to “/data/app” partition and the library packed in this APK will be moved to “/data/data/{package name}/lib/xxx.so”.

    We are attempting to pack an app into our system image. The APK will be placed in “/system/app”. To do so, we also need to pull out libraries from APK and put them into “/system/lib“

    It seems Unity hard-codes the target library path to “/data/data/{package name}/lib/xxx.so” (as per installed apps). But for built-in app (not installed app), its library should be in “/system/lib/xxx.so”

    So what I'm asking is how to change the library path

    Ex : System.loadLibrary(“xxx”) but not System.loadLibrary(“/data/data/{package name}/lib/xxx.so”)

    Then system should automatically find the specific library from “/system/lib” or “/data/data/{package name}/lib” regardless of whether it is a built-in app or an installed app.
     
  2. DanTreble

    DanTreble

    Joined:
    Aug 31, 2010
    Posts:
    590
    That has to be in their java wrapper right? Couldn't you decompile the java and hack that yourself? :)
     
  3. padworx

    padworx

    Joined:
    Mar 22, 2011
    Posts:
    27
    Thanks for the suggestion! Didnt think I could get away with that but decompiling the java was surprisingly easy =)
     
  4. padworx

    padworx

    Joined:
    Mar 22, 2011
    Posts:
    27
    Hi,

    Made some progress. There are two missing libraries, libunity.so and libmono.so

    I started by removing the libs from /system/lib and running the app. Here is the error:

    IllegalArgumentException: Unable to find native library: mono

    Next, I pushed the libs back to /system/lib and tried again:

    IllegalArgumentException: Unable to find native library: unity

    So the UnityPlayer is able to find libmono but not libunity, even though they are both in the proper directory.

    Decompiling the class.dex contained in the APK revealed only this non-specific function call:


    A few other tidbits...this is the manifest.mf contained in the APK. It appears to contain references to the libs:

     
  5. padworx

    padworx

    Joined:
    Mar 22, 2011
    Posts:
    27
    Based on the information given here http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html

    the manifest.mf is part of the security system built around signing the apk...so that is a dead end.

    In UnityPlayer.java I will try changing the System.LoadLibrary(xxx.so) to System.Load(xxx.so)...hopefully then system will automatically find the specific library from “/system/lib” or “/data/data/{package name}/lib”

    Ex : System.load(“xxx”) but not System.loadLibrary(“/data/data/{package name}/lib/xxx.so”)

    I'm not sure how to rebuild the decompiled jar file back into a .class, then I must repack the APK? Suggestions?
     
    Last edited: Sep 15, 2011
  6. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Hi padworx,

    Since I have had a lot of people referring to this thread, I'm posting a reply even though you probably moved on by now.

    The unity player uses System.loadLibrary("libunity.so"), and not System.load("/<path>/libunity.so"). And if you put the libraries into /system/lib th e UnitPlayer will succeed loading both libs. However, the problem seems to be with the NativeActivity implementation. According to AOSP it always prepend the library path with ApplicationInfo.nativeLibraryDir.
    http://androidxref.com/4.2.2_r1/xref/frameworks/base/core/java/android/app/NativeActivity.java#172

    I'm currently trying to figure out how this is supposed to be setup using the NativeActivity path, but if you are in a hurry you can try switching to the regular java activity - just move the MAIN intent to UnityPlayerActivity. This will give some additional input latency but depending on the game you have that may be fine.
     
  7. vgamer

    vgamer

    Joined:
    Sep 3, 2012
    Posts:
    2
    Did you guys came up with a solution ? Im trying to do the same thing, no luck so far.
     
  8. McKrackeN

    McKrackeN

    Joined:
    Oct 28, 2009
    Posts:
    51
    Hey ppl!

    I re-bump this thread cause we're having the same issue and don't know what to do. Any walkaround?

    Thanks!
     
  9. FHRaph

    FHRaph

    Joined:
    Dec 21, 2012
    Posts:
    1
    Is there an solution to this issue?

    It seems like it is simply impossible to install Unity APKs as system applications. I've tried pushing the libs (libmono and libunity) to system/lib but that doesn't work. Can it be done?

    - Raph -
     
  10. KraToSo

    KraToSo

    Joined:
    Feb 27, 2013
    Posts:
    3
    I am having the same issue, did any of you guys find a solution to this?

    -ravi
     
  11. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Adding one more voice with the same problem here!
     
  12. vicviper0926

    vicviper0926

    Joined:
    Feb 2, 2013
    Posts:
    2
    One more voice from korea!!
     
  13. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    I ended up placing the shared lib's in a certain directory (In my case, we used the StreamingAssets dir), and using the .net functions to set that specific directory as the current working directory before calling the DLLImport that requires shared libs. When doing this, the dll we loaded was able to look in the working directory for its dependents, and it worked from there.

    Updating is a bit of a pain, but if installing to the SDCARD you can workaround it with some simple scripting. if not installing to the SDCARD, have root ;)

    (From foggy memory of a prototype project a couple months back, if you need more details yell and I can dig up the specifics.)
     
  14. eezSZI

    eezSZI

    Joined:
    Nov 16, 2012
    Posts:
    121