Including AAR files in project

Hey there,

First of all I’d like to say I’m really digging Fuse, I was sceptical at first but after toying around with it for a bit I’m convinced. However, I’ve ran into an issue with including external code. I can import my own Java class as a .java file, but now I would like to utilise an external AAR file. How would I go about doing this?

I looked through the documentation but was unable to find anything related to including prebuilt libraries, but should I have missed it a link would be much appreciated. :slight_smile:

Hello!

I don’t think we’ve tried this yet, but for .jar files it should be enough to use e.g. the following in a uxl file:

<Extensions Backend="CPlusPlus" Condition="Android">
    <CopyFile Name="@('relative/path/to/my.jar':Path)" TargetName="@(Java.LibsDirectory)/my.jar" />
</Extensions>

It’s possible this works for .aar files as well.

We’re working on improving our support for including third-party libraries on android and you can expect that it will be easier in the future.

Please let us know if you have any further questions!

Thanks for the quick reply!

However, I’m now unable to compile so I’m probably doing something wrong. When including the raw .java file through the .unoproj Includes the project compiled and logged a string, but I guess since I’m now not explicitely including the .uxl file it is unable to compile?

I hope it’s just something I have forgotten to include and that the fix is relatively simple. I can also create a .jar of the library to see whether that would work, but then I would first need to know whether these steps are correct. :slight_smile:

I’ll include the files I’m using below, minus the MainView as that’s just a button calling the code which works for iOS and local previews

-Project-folder | MainView.ux | mylibrary-release.aar | Message.ccp.uxl | CustomModule.uno | Project-folder.unoproj

Unoproject file:

{
  "RootNamespace":"",
  "Packages": [
        "Fuse.Animations",
        "Fuse.BasicTheme",
        "Fuse.Themes",
        "Fuse.Controls",
        "Fuse.Designer",
        "Fuse.Drawing",
        "Fuse.Drawing.Primitives",
        "Fuse.Effects",
        "Fuse.Elements",
        "Fuse.Entities",
        "Fuse.Gestures",
        "Fuse.Navigation",
        "Fuse.Shapes",
        "Fuse.Scripting",
        "Fuse.Triggers",
        "Fuse.Reactive",
        "Fuse.Android",
        "Fuse.Desktop",
        "Fuse.iOS",
        "Fuse.Vibration",
        "Fuse.UserEvents",
        "FuseCore",
        "Uno.Collections",
        "Uno.Geometry"
  ],
  "Includes": [
    "*",
    "IndoorAtlasModule.uno:SourceFile",
  ]
}

Message.cpp.uxl

<Extensions Backend="CPlusPlus" Condition="Android">
    <CopyFile Name="@('mylibrary-release.aar':Path)" TargetName="@(Java.LibsDirectory)/mylibrary-release.aar" />
</Extensions>

CustomModule.uno

using Uno;
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Uno.Compiler.ExportTargetInterop;

public class CustomModule : NativeModule
{
    public CustomModule()
    {
        AddMember(new NativeFunction("Log", (NativeCallback)Log));
    }

    public static object Log(Context c, object[] args)
    {
        string message = (string)args[0];
        PrivateLog(message);
        return null;
    }

    [Foreign(Language.Java)]
    static extern(ANDROID) void PrivateLog(string msg)
    @{
        // This is the code I would like to run. It's just a simple log to see whether including aars will work.
        nl.rtl.mylibrary.Message.showMessage(msg);
    @}

    static extern(!ANDROID && !iOS) void PrivateLog(string msg)
    {
        debug_log(msg);
    }

    [Foreign(Language.ObjC)]
    static extern(iOS) void PrivateLog(string message)
    @{
        NSLog(@"%@", message);
    @}

}

I’ve talked to @Morten about this. aar is not supported by Uno yet. This is how I started solving it on Facebook-Login: get_android.sh and then

<CopyFile Name="libs/android/classes.jar" TargetName="@(Java.LibsDirectory)/facebook.jar" />
<CopyDirectory Name="libs/android/res" TargetName="@(Java.ProjectDirectory)/main" />

This works, but I got some other problems.

I looked at your project and was able to get at least some steps further but now it seems the library file is not included in the gradle build task when looking through the generated code. Is there some step I’m missing?

All jar files in @(Java.LibsDirectory) should be included in the build (at least in the ant task). Maybe it’s diffrent with gradle which is a bit newer.