Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feature Request Make android code(.java/.kt) in `Android Library Project` can use Unity's android classes

Discussion in 'Android' started by JokeMaker, Nov 8, 2022.

  1. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    We find a very useful solution for extend Unity's functionality on Android. It is that we can import `Android Library Project` into Unity project with a folder named `*.androidlib`. That is great!
    But it has some restrictions. One is that:
    If I want to use classes in unity-classes.jar or just extend `UnityPlayerActivity`, I CANT!
    Due to library `unityLibrary` includes `MyCustomLib.androidlib`, we can use classes in `MyCustomLib.androidlib` when code is in `unityLibrary`, but we cant use classes in `unityLibrary` when code is in `MyCustomLib.androidlib`.

    BTW, I actually know another solution that we place my android codes into any other folders in my Unity project other than `Android Library Project` folder.
    I just want my android assets in a consistent status.
    That's all.
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Just in case, you can put java files directly into Unity project (without using .androidlib) and those will end up in unityLibrary folder, so in case you want to provide your own activity, you simply have:
    * java file in the Unity project
    * set main manifest template pointing to activity name from your java class which has access to unity-classes.jar too
     
  3. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    I actually know this solution.
    But my true request is `Consistent Design` for android extension.
    Above all, just a suggestion.
    Nice Day!
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    So currently, the way it's done - unityLibrary depends on *.androidlib modules, but your request would to have *.androidlib module which would depend on unityLibrary module instead ?
     
  5. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    Maybe, there could be an option to change this behaviour?:p
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Yes, just thinking how to make it user friendly, in any case, we logged this case internally. Thank you for suggestion!
     
  7. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    Glad to hear that.
    Nice Day!
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Small Update: Starting 2023.3.0a10, there will be an option in inspector for .androidlib to specify if any builtin modules depend on .androidlib. So for the case above, it will be possible to disable unityLibrary dependency on .androidlib, and instead make .androidlib depend on unityLibrary module.
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637