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

Android manifest for native plugin (.so) ignored while building .apk

Discussion in 'Android' started by chino_noris, Jan 27, 2020.

  1. chino_noris

    chino_noris

    Joined:
    Feb 1, 2019
    Posts:
    5
    I'm using Unity 2019.2.15f.

    According to this page, when building an apk, the following happens:

    1. Unity takes the main Android Manifest.
    2. Unity finds all the Android Manifests of your plug-ins (AARs and Android Libraries)
    3. Manifests from plug-ins are merged into the main Manifest using Google’s manifmerger class.


    Steps 2-3 are not happening for me; my manifest appears to be ignored.

    My plugin is built from C++ code and compiled into a .so. The folder structure is as follows:
    /Assets/MyFancyLibrary/Plugins/Android/myfancylibrary.so (native code)
    /Assets/MyFancyLibrary/Plugins/Android/AndroidManifest.xml (manifest)

    With this structure, the AndroidManifest.xml is ignored at build time. I can write garbage in it and no error is triggered.

    From what I could test, the only way for my AndroidManifest.xml to not be ignored is to place it in the special folder /Assets/Plugins/Android (at which point, my manifest overrides the default form Unity from step 1) and everything works. This is not ideal though, because I want to be able to distribute my library, as well as building multiple libraries and pick and chose between them. I therefore need the manifest merging to properly work.

    Any suggestion?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    Your library has to either be built as AAR or it has to be and Android Library Project (correct format).
    Unfortunately, I don't remember when support for new project format was added, it might be only in 2019.3.
    For your case the best is probably to create AAR.
     
  3. chino_noris

    chino_noris

    Joined:
    Feb 1, 2019
    Posts:
    5
    Thanks, that's good to know.

    Is there official documentation about this?
     
  4. chino_noris

    chino_noris

    Joined:
    Feb 1, 2019
    Posts:
    5
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
  6. chino_noris

    chino_noris

    Joined:
    Feb 1, 2019
    Posts:
    5
    Just fyi, I packaged the manifest into a .aar and the merge worked correctly.

    It's a bit inconvenient though; I think it would be fair for Unity to check the content of any instance of /Assets/.../Plugins/Android/ and check if AndroidManifests.xml are found.