top of page
Writer's pictureNexStead Games

Integrating Our Unity Library (as AAR) into Native Android: A Step-by-Step Guide

This document explains how to include our library consisting of the games into a standard Android application as an AAR library.


Requirement:

  • Android Studio Bumblebee (2021.1.1) or later


STEPS:


  1. Open our provided project"Nx_UnityLibrary" in Android Studio Bumblebee (2021.1.1) or later.

  2. Convert this project to a Library project:

    1. Open the manifest and remove the intent code: <!--<intent-filter>--> <!--<action android:name="android.intent.action.MAIN" />--> <!--<category android:name="android.intent.category.LAUNCHER"/>--> <!--<category android:name="android.intent.category.LEANBACK_LAUNCHER" />--> <!--</intent-filter>-->

    2. Open the module gradle file, locate next line: apply plugin: 'com.android.application' Change that to: apply plugin: ‘com.android.library’

    3. Build the project, and take the AAR file aside. aar file should be located in: Nx_UnityLibrary\build\outputs\aar

  3. Use above aar file as library:

    1. Open your Native android app.

    2. Add a new module from above aar file File → New Module → Import JAR/AAR Package, and select your aar file.

    3. Make sure that in settings.gradle file there is next line: include ':app', ':your_aar_file_name'

    4. Add a dependency at your main module (app) to this aar: dependencies { compile project(":your_aar_file_name") compile fileTree(dir: 'libs', include: ['*.jar']) ... }

    5. Sync gradle

  4. Solve gradle “Merger” issue if needed:

    1. Follow these steps if you face this error: "Manifest merger failed with multiple error, see logs"

    2. This happens because the merger is trying to use the icon and the theme of the library.

    3. Add following code in your main native application manifest file

      1. adding to manifest tag xmlns: tools="http://schemas.android.com/tools" adding to the application tag tools:replace="android:icon,android:theme"

      2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.yourpackage.name"> <application android:allowBackup="true" tools:replace="android:icon,android:theme" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" ... </application> </manifest>

      3. Build your project again



Here is how the Import screen looks, File → New Module → Import JAR/AAR Package



If everything succeeds, you should see unityLibrary module added in Android view


53 views0 comments

Recent Posts

See All

Comments


Commenting has been turned off.
bottom of page