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

Hardcoded data.unity3d path inside libunity.so

Discussion in 'Android' started by bavbavbavbav, Sep 29, 2017.

  1. bavbavbavbav

    bavbavbavbav

    Joined:
    Sep 29, 2017
    Posts:
    1
    Hello,
    I'm trying to combine two Unity projects inside one Android application. Here is what I did step-by-step:
    1. Create first Unity project named Project01, add a cube on scene and exported it as a Gradle project;
    2. Within build.gradle file I've changed apply plugin: 'com.android.application' to 'com.android.library' and removed 'applicationId' configuration due to make an .aar archive instead of an .apk file. Also I've commented 'unity.build-id' inside of AndroidManifest.xml to avoid later manifest merge conflicts;
    3. Run 'gradle assembleDebug' produced desired Project01-debug.aar archive;
    4. Then I repeated steps 1-3 for the second project named Project02 with a capsule on scene;
    5. So now I have two .aar files each containing separate Unity project;
    6. Then I've created Android Studio project to combine them together;
    7. Add both .aar archives as modules into android project (File > New > New Module... > Import .JAR/.AAR Package);
    8. Add dependencies on both of them (File > Project Structure... > Dependencies) to get access to UnityPlayerActivity classes contained in each module;
    9. Then I created simple layout with two buttons: click on first one initiates startActivity with intent containing project01.UnityPlayerActivity.class, click on second one do the same but with project02.UnityPlayerActivity.class;
    10. I expected that I will see a cube after I clicked on first button, and a capsule on clicking on a second button;
    11. I was wrong :)
    The thing is that gradle while compiling resulting .apk merges assets of both modules. In case of two modules have an asset with the same name (path), gradle will get it from the module with higher priority. Priorities defines by order in list of dependencies (File > Project Structure... > Dependencies).

    So... I realized that Gradle projects exported from Unity differ mostly by src/main/assets/bin/Data/data.unity3d file (other files are almost the same from project to project). I think that is where all Unity scenes are contained in some binary format.

    Anyway, since in both modules (Project01 and Project02) that file has the same name, only one of them is included in resulting .apk. And therefore only cube or capsule will be seen from both UnityPlayerActivity'es.

    I've tried to rename data.unity3d file (for example to 'data.bla') and got an error 'Player data archive not found at <path_to_data.unity3d>, using local filesystem'. That means that filename is hardcoded somewhere. Searching through directory gives 'Player data archive not found at `%s`, using local filesystem' string inside libunity.so. So logging was produced by native code. Also I've found hardcoded 'data.unity3d' string withing libunity.so, but this may be coincidence.


    Now I'm wondering is it possible to make UnityPlayer to play some scene (I mean project) other than data.unity3d? Maybe there is a way to specify .unity3d file for libunity library? What can Unity developers say on this? Does anyone faced the same problem?