Search Unity

Question Problem movind from res/ to .androidlabrary

Discussion in 'Android' started by jj-steele, Nov 28, 2022.

  1. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    Hi,

    I am updating some code from 2019 to 2021 and am getting the OBSOLETE message when trying to build with an Android/res folder.

    The res folder looked like:-
    res/
    xml/
    filepaths.xml

    and filepaths.xml contains

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="." />
    </paths>


    I have now removed res/ added filepaths.androidlib which contains:-
    AndroidManifest.xml
    project.properties
    res/

    The res folder contains the same files as the old res folder.

    AndroidManifest.xml contains:-

    <?xml version="1.0" encoding="UTF-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.westcoat.Fitbag" android:versionCode="1" android:versionName="1.0">
    <application>
    <activity android:name="filepaths" android:hardwareAccelerated="true" />
    </application>
    </manifest>


    and project.properties contains:-

    # Project target.
    target=android-32
    android.library=true


    This builds without error but crashes at startup with
    java.lang.RuntimeException: Unable to get provider androidx.core.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file

    so it looks like the filepaths.xml isn't being added as it used to be.

    Can anybody help as I've googled for a couple of days and can't find an answer.


    Thanks.
    John
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,919
  3. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    Copied that but having lots of errors referencing AndroidManifest.xml.
     
  4. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    Is there more info on making this an aar or .androidlib out of this? I've spent another day and still no luck.
     
  5. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,919
    You need to show the errors.
     
  6. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    upload_2022-11-30_10-56-6.png

    The copy in OnPostGenerateGradleAndroidProject has created res/xml/file_paths.xml in Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary.
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Looks like you are mixing things up and run into problems because of that.
    The .androidlib directory is a gradle module that is placed as child of unityLibrary. If your post process script modifies unityLibrary, sure you get problems if child project needs those.
    Normally, you should make your .androidlib to be fully self-contained gradle module.

    If that will be of any help to you, I have a work in progress branch here: https://github.com/Unity-Technologies/com.unity.mobile.notifications/tree/android-big-picture
    The project TestProjects/AndroidBigPicture is a unity project that also uses AndroidX FileProfider, so you can look how it's setup. I've actually set it up by first exporting gradle project from Unity, then created android library project in it, got stuff working and finally moved the module directory to Unity project as .androidlib (deleting unnecessary files from it).
     
  8. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    Thanks for this, I was getting confused and still am. I only tried the copy instead of .androidlib on the advice of Tomas1856, I woould really like this to work wirh .androidlib. Unfortuantely, I inherited this project and don't really understand Android that well. Everything was working well upgrading the project until Unity2021.
    The docs and replies on google seem to suggest that all you need to do is more res from plugins/Android into something.androidlib and that should work. I also found that I would need project.properties and AndroidManifest.xml to make it work. If you take a look at the beginning of this stream, you can see what I ended up with that doesn't work.
    Can you see where I have gone wrong?
     
  9. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    It turned out there was nothing wrong with my .androidlib!
    Somewhere in the upgrade from 2020 to 2021 the gradle template got corrupted. copying that over to 2021 fixed the problem.