Help about android AAR Library

I recently switched to Unity 2021.2.3f1 and when I try to build I get this error.

“Exception: OBSOLETE - Providing Android resources in Assets/Plugins/Android/assets was removed, please move your resources to an AAR or an Android Library. See “AAR plug-ins and Android Libraries” section of the Manual for more details.”

I looked it up and came across this

That briefly explains what AAR are and That I need to create one to import in my project.
Then there is a link to the android studio page on how to create an android Library.

Can I just open android studio and create an android library from a new android studio project and import it into my unity project?

I would prefer to create a library from my unity project directly, how can I do that?

If I try to export the project(to open it in Android studio) I still get the same error.

1 Like

Actually, if your concern is only about files within assets folder and nothing else (considering you don’t have any other code referencing its resouce id’s), you can simply copy the contents of assets folder to Streaming Assets.

Why? → Because, the contents of Streaming assets are copied to assets folder finally once the final executable is built.

Else(Most likely), Can you try this once and let me know if it works?

Steps to create a quick android project

  1. Create a new folder named yourModuleName.androidlib in Assets/Plugins/Android
  2. Create AndroidManifest.xml in the above folder and update with your contents
  3. Create project.properties file with below contents and save it.
target=android-31
android.library=true
  1. Copy your assets folder to yourModuleName.androidlib

Now Unity auto merges the your file and you are free from unity updates which is more flexible!
Added a sample androidlib folder for your reference.

7688665–961864–test.androidlib.zip (2.79 KB)

3 Likes

I think putting files in Android Library which is a folder with extension .androidlib in Unity project might be an easier option for you.

I could get this to work. so frustrating. Why change these things that have been working for years?

3 Likes

Exception: OBSOLETE - Providing Android resources in Assets/Plugins/Android/res was removed, please move your resources to an AAR or an Android Library. See “AAR plug-ins and Android Libraries” section of the Manual for more details.
UnityEditor.Android.PostProcessor.Tasks.CheckUserResources.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessAndroidPlayer.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTarget target) (at :0)
UnityEditor.Android.AndroidBuildPostprocessor.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTarget target) (at :0)
UnityEditor.PostprocessBuildPlayer.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target) (at :0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

the manual doesn’t help at all. I have no experience with Java to build AAR files. I will have to downgrade my project bakc to Unity 2021.1

You don’t need AAR files, just create a folder in Unity project with .androidlib extension, Unity will treat it as gradle module.

3 Likes

Thank you for the replies.

In my project I have Google Play Games and Leaderboards, Unity ads and analytics.

I have also addressables with Play Asset Delivery.

My project folder is not super clean and optimized and copying all the “Assets” folder into the androidlib folder would double the size of it, right?

I created a myLibray.anrdoidlib folder in my “Assets” folder but I don’t now what to put into it.

In my Plugins/Android folder I have these files

AndroidManifest
AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:node="remove" />
  <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name">
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <receiver android:name="com.adjust.sdk.AdjustReferrerReceiver" android:permission="android.permission.INSTALL_PACKAGES" android:exported="true">
      <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
      </intent-filter>
    </receiver>
  </application>
  <uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" />
</manifest>

baseProjectTemplate.gradle
gradleTemplate.properties
launcherTeplate.gradle
mainTemplate.gradle

I am using Addressables with PlayAssetDelivery followed this (https://github.com/Unity-Technologies/Addressables-Sample)

If I put AndroidManifest inot the androidlib folder I get and error in build.

I deleted the asset folder in Android folder and now it seem to build correctly but I get an error when I test the app if I try to connect to PlayGames and other GoogleServices

I get this error when the app is started

Logcat Error

2022/06/18 12:09:54.475 16078 19556 Error Unity AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.Games
2022/06/18 12:09:54.475 16078 19556 Error Unity java.lang.ClassNotFoundException: com.google.android.gms.games.Games
2022/06/18 12:09:54.475 16078 19556 Error Unity     at java.lang.Class.classForName(Native Method)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at java.lang.Class.forName(Class.java:454)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at android.os.Handler.dispatchMessage(Handler.java:102)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at android.os.Looper.loop(Looper.java:246)
2022/06/18 12:09:54.475 16078 19556 Error Unity     at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
2022/06/18 12:09:54.475 16078 19556 Error Unity Caused by: java.lang.ClassNotFoundException: com.google.android.gms.games.Games
2022/06/18 12:09:54.475 16078 19556 Error Unity     ... 8 more
2022/06/18 12:09:54.475 16078 19556 Error Unity   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
2022/06/18 12:09:54.475 16078 19556 Error Unity   at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0
2022/06/18 12:09:54.475 16078 19556 Error Unity   at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <000000000000

Can you tell me what I need to put into the androidlib folder to make GoogleServices works?

Thanks

The error stated is because of not having the dependency library. I would suggest to pass me a sample project to help you out. That ways its easy for me to pin point the issue.

Remove or rename “res” folder from Assets/Plugins/Android - it fixed my problem in this situation.
I don’t know why, but “res” word can’t use.

Then why wouldn’t the error suggest this and instead suggest something so complicated using third-party tools? :confused: If only Unity ate their own dogfood… who approves this stuff?

Having an issue now with this. What did you end up doing? And agreed. Why change something that worked for so long.

I have created the .androidlib. I then put the new styles.xml in there but its not working. Is there a step by step anywhere to make this work?