Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Help about android AAR Library

Discussion in 'Android' started by EdoC-QWERTY, Nov 26, 2021.

  1. EdoC-QWERTY

    EdoC-QWERTY

    Joined:
    Feb 1, 2020
    Posts:
    75
    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
    https://docs.unity3d.com/2021.2/Documentation/Manual/AndroidAARPlugins.html

    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.
    https://developer.android.com/studio/projects/android-library.html

    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.
     
    anycolourulike likes this.
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
    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.

    Code (CSharp):
    1. target=android-31
    2. android.library=true
    4. 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.
     

    Attached Files:

    Last edited: May 24, 2022
  3. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    I think putting files in Android Library which is a folder with extension .androidlib in Unity project might be an easier option for you.
     
  4. Zeeppo-Games

    Zeeppo-Games

    Joined:
    May 13, 2015
    Posts:
    102
    I could get this to work. so frustrating. Why change these things that have been working for years?
     
    BryanO and anycolourulike like this.
  5. Zeeppo-Games

    Zeeppo-Games

    Joined:
    May 13, 2015
    Posts:
    102
    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 <cf82a25f0a8443eb910fd35454292555>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <cf82a25f0a8443eb910fd35454292555>:0)
    UnityEditor.Android.PostProcessAndroidPlayer.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTarget target) (at <cf82a25f0a8443eb910fd35454292555>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTarget target) (at <cf82a25f0a8443eb910fd35454292555>:0)
    UnityEditor.PostprocessBuildPlayer.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target) (at <a017e354f3154926a5617fbac3a64fcc>: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
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    You don't need AAR files, just create a folder in Unity project with .androidlib extension, Unity will treat it as gradle module.
     
    kevinatgame likes this.
  7. EdoC-QWERTY

    EdoC-QWERTY

    Joined:
    Feb 1, 2020
    Posts:
    75


    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
    Code (JavaScript):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    3.   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    4.   <uses-permission android:name="android.permission.INTERNET" />
    5.   <uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:node="remove" />
    6.   <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name">
    7.     <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
    8.       <intent-filter>
    9.         <action android:name="android.intent.action.MAIN" />
    10.         <category android:name="android.intent.category.LAUNCHER" />
    11.       </intent-filter>
    12.     </activity>
    13.     <receiver android:name="com.adjust.sdk.AdjustReferrerReceiver" android:permission="android.permission.INSTALL_PACKAGES" android:exported="true">
    14.       <intent-filter>
    15.         <action android:name="com.android.vending.INSTALL_REFERRER" />
    16.       </intent-filter>
    17.     </receiver>
    18.   </application>
    19.   <uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" />
    20. </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

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

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

    Thanks
     
  8. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
    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.
     
  9. IAVAR

    IAVAR

    Joined:
    Jan 15, 2017
    Posts:
    7
    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.
    ----
     
    Last edited: Mar 10, 2023