Unity upgrade targetSdkVersion33 solution

Because of Google upload requirements, you need to upgrade targetsdk33. Here are some solutions:
Use version 2019.4.20f1

  1. Because the SDK after 31 lacks dx files, the solution is to change the file name of these files to dx.bat. The
    solution is as follows:
    1) Enter the build-tools\33.0.2 directory under the project SDK directory, for example: C:\Users\ user\AppData\Local\Android\Sdk\build-tools\33.0.2
    2) Find a file named d8.bat, which is a Windows batch file.
    3) Copy the file and rename d8.bat to dx.bat.
    4) Enter the build-tools\33.0.2\lib directory under the project SDK directory, for example: C:\Users\user\AppData\Local\Android\Sdk\build-tools\33.0.2\lib 5) After adding
    d8 Copy and rename .jar to dx.jar
    2. You need to check the following settings in Edit-projectSettings-player-publishingsettings:

Insert image description here
1). Modify the two generated gardle files:
Assets/Plugins/Android/mainTemplate.gradle. Remove the following comments at the top of
Assets/Plugins/Android/launcherTemplate.gradle : // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAINAdd the following code:


buildscript {
    
    
    repositories {
    
    
        google()
        mavenCentral()
    }
    dependencies {
    
    
        // Must be Android Gradle Plugin 3.6.0 or later. For a list of
        // compatible Gradle versions refer to:
        // https://developer.android.com/studio/releases/gradle-plugin
        classpath 'com.android.tools.build:gradle:4.0.1'
    }
}

allprojects {
    
    
   repositories {
    
    
      google()
      mavenCentral()
      flatDir {
    
    
        dirs 'libs'
      }
   }
}

Modify classpath 'com.android.tools.build:gradle:4.0.1' as needed

3) You need to add android:exported="true" to the AndroidManifest.xml file.

 <application>
     <activity android:name="com.unity3d.player.UnityPlayerActivity"
               android:theme="@style/UnityThemeSelector"
               android:exported="true">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
         <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
     </activity>
 </application>

All activity service receivers with intents need to be added, otherwise a parsing error will be prompted when installing Android 12 or above.

Reference places:

https://blog.csdn.net/zyl766800/article/details/127693050
https://google-developers.gonglchuangl.net/ar/develop/unity-arf/android-12-build?hl=zh-cn
https://blog.csdn.net/wq6ylg08/article/details/121882199

Guess you like

Origin blog.csdn.net/qq_41827636/article/details/131901706