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:
Open our provided project"Nx_UnityLibrary" in Android Studio Bumblebee (2021.1.1) or later.
Convert this project to a Library project:
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>-->
Open the module gradle file, locate next line: apply plugin: 'com.android.application' Change that to: apply plugin: ‘com.android.library’
Build the project, and take the AAR file aside. aar file should be located in: Nx_UnityLibrary\build\outputs\aar
Use above aar file as library:
Open your Native android app.
Add a new module from above aar file File → New Module → Import JAR/AAR Package, and select your aar file.
Make sure that in settings.gradle file there is next line: include ':app', ':your_aar_file_name'
Add a dependency at your main module (app) to this aar: dependencies { compile project(":your_aar_file_name") compile fileTree(dir: 'libs', include: ['*.jar']) ... }
Sync gradle
Solve gradle “Merger” issue if needed:
Follow these steps if you face this error: "Manifest merger failed with multiple error, see logs"
This happens because the merger is trying to use the icon and the theme of the library.
Add following code in your main native application manifest file
adding to manifest tag xmlns: tools="http://schemas.android.com/tools" adding to the application tag tools:replace="android:icon,android:theme"
<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>
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
Comments