Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Can Unity please support API level 31 as target SDK on the 2020.3 LTS?

Discussion in 'Android' started by nikk98, Aug 14, 2022.

  1. nikk98

    nikk98

    Joined:
    Mar 8, 2021
    Posts:
    43
    This is now the minimum requirement for uploading to the Play store. Currently, you can't get a build to upload to the store with the editor out of the box.

    Is there an easy workaround, provided I'm using CI and building on linux?

    The ones I've thought that are not great are:
    - Extend the CI scripts to build on android studio and add that to the docker image
    - Add the SDK in the docker image and hack the shell script unity uses to build.
     
    HyperModeGG likes this.
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,858
    Share us what error you see so that can suggest a solution. Is it related to exported flag?
     
  3. nikk98

    nikk98

    Joined:
    Mar 8, 2021
    Posts:
    43
    The error is in the play console, when uploading a new aab. It mentions the requirement.

    This is related to the new playstore requirement that just kicked in.

    https://developer.android.com/google/play/requirements/target-sdk

    If you want to change the target API level in an editor script you can't as the relevant enum doesn't have a value for level 31.

    I did notice after posting that there's a value if you try to change it via the editor.

    I ended up solving it by enabling custom gradle files and hard coding the value for the target SDK though. I needed them for adding support for crashlytics anyway.

    Thanks for enquiring and trying to help!
     
  4. HyperModeGG

    HyperModeGG

    Joined:
    Jul 26, 2019
    Posts:
    1
    Can you elaborate more on your solution? having this issue also...
     
  5. nikk98

    nikk98

    Joined:
    Mar 8, 2021
    Posts:
    43
    Sure, I'll write down what I remember. It would be great if Unity made all this easier. As things are the automatic flow of building in Android based on build settings is broken.

    A) Add the android:exported="true" property in the AndroidManifest.xml in the activity tag.

    1) Enable Custom Main Manifest under Project Settings > Player >Publishing Settings > Build > Custom Main Manifest.
    2) Add android:exported="true" in the activity tag.

    If you don't do that, the console will complain that your activity won't run on android 12 and will not let you to upload.

    B) Change permissions of the SDK folder in Unity (If you are building in windows - not sure about mac. Doesn't seem to happen in linux)
    E.g. C:\Program Files\Unity\Hub\Editor\2020.3.37f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK
    for the 2020.3.37f1

    Gradle tries to download build tools under there and it can't because it has no write permissions as it's under Program Files.

    You need to first change ownership to your own account, and then add and make it writable. I used this answer to find out how to do it.

    C) Change the target sdk version in buld settings

    Try changing Project Settings > Player > Other Settings > Identification >Target API level. That might be enough.

    What I did is the following.
    1) Enable custom gradle files in "Project Settings> Player >Publishing Settings > build"
    2) In launcherTemplate.gradle and mainTemplate.gradle under Plugings/Android (they are created after you enable them) I have nailed the targetSdkVersion to 31, in the defaultConfig section.

    It looks like this:

    In LauncherTemplate
    Code (CSharp):
    1.  
    2. defaultConfig {
    3.         minSdkVersion **MINSDKVERSION**
    4.         targetSdkVersion 31
    5.         applicationId '**APPLICATIONID**'
    6.         ndk {
    7.             abiFilters **ABIFILTERS**
    8.         }
    9.         versionCode **VERSIONCODE**
    10.         versionName '**VERSIONNAME**'
    11.     }
    12.  
    In MainTemplate:
    Code (CSharp):
    1.  
    2.     defaultConfig {
    3.         minSdkVersion **MINSDKVERSION**
    4.         targetSdkVersion 31
    5.         ndk {
    6.             abiFilters **ABIFILTERS**
    7.         }
    8.         versionCode **VERSIONCODE**
    9.         versionName '**VERSIONNAME**'
    10.         consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    11.     }
    In case you need it, this is how my manifest looks (it has firebase stuff in as well that you might not need). You definitely need the 'android:exported="true"' in the activity part.


    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.           xmlns:tools="http://schemas.android.com/tools"
    4.           android:installLocation="preferExternal">
    5.   <supports-screens android:smallScreens="true"
    6.                     android:normalScreens="true"
    7.                     android:largeScreens="true"
    8.                     android:xlargeScreens="true"
    9.                     android:anyDensity="true" />
    10.   <application android:theme="@style/UnityThemeSelector"
    11.                android:icon="@mipmap/app_icon"
    12.                android:label="@string/app_name"
    13.                android:allowNativeHeapPointerTagging="false">
    14.     <activity android:name="com.unity3d.player.UnityPlayerActivity"
    15.               android:label="@string/app_name"
    16.               android:exported="true">
    17.       <intent-filter>
    18.         <action android:name="android.intent.action.MAIN" />
    19.         <category android:name="android.intent.category.LAUNCHER" />
    20.         <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    21.       </intent-filter>
    22.       <intent-filter>
    23.         <action android:name="com.google.intent.action.TEST_LOOP"/>
    24.         <category android:name="android.intent.category.DEFAULT"/>
    25.         <data android:mimeType="application/javascript"/>
    26.       </intent-filter>
    27.       <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    28.     </activity>
    29.     <meta-data android:name="com.google.test.loops" android:value="236"/>
    30.     <meta-data android:name="com.google.test.loops.noscale" android:value="1-6" />
    31.     <meta-data android:name="com.google.test.loops.lowres" android:value="11-16" />
    32.     <meta-data android:name="com.google.test.loops.medres" android:value="21-26" />
    33.     <meta-data android:name="com.google.test.loops.highres" android:value="31-36" />
    34.     <meta-data android:name="com.google.test.loops.resDr" android:value="4,14,24,34" />
    35.     <meta-data android:name="com.google.test.loops.resRender" android:value="104,114,124,134" />
    36.     <meta-data android:name="com.google.test.loops.resSr" android:value="204,214,224,234" />
    37.  
    38.    </application>
    39.    <uses-feature android:glEsVersion="0x00020000" />
    40.    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    41.    <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    42.    <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
    43. </manifest>
    This made it work on my CI - but changing in the editor settings might have worked too.
     
    HyperModeGG likes this.
  6. Lanzeeno

    Lanzeeno

    Joined:
    Sep 7, 2020
    Posts:
    1
    Hi, sorry to disturb, but I'm trying everything and you seem to be the only one on the Internet with my same (solved) issue. I followed every step but nothing seems to change. In my project I always see like 40 different errors like these ones:
    Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
    System.Reflection.MethodBase:Invoke (object,object[])
    CommandInvokationFailure: Gradle build failed.
     
  7. djhatvr

    djhatvr

    Joined:
    Sep 22, 2019
    Posts:
    42
    Your not the only one, I'm dealing with it right now as well..
    Any luck?