Troubleshooting In-App Purchasing 5.4.0 Android builds on Unity 2022.3
Solve an Android build failure when you use In-App Purchasing 5.4.0 on Unity 2022.3 LTS.
Read time 2 minutesLast updated 8 days ago
In-App Purchasing (IAP) 5.4.0 is designed for Unity 6. To use IAP 5.4.0 with Unity 2022.3 LTS on Android, you need to adjust some project settings. This page explains why the build fails on Unity 2022.3, how to recognize the errors, and the steps to build successfully. The steps are verified against Unity 2022.3.62f2, but they apply to Unity 2022.3 LTS in general.
Symptoms
Depending on your build settings, IAP 5.4.0 on Unity 2022.3 can fail during the Android build with one or more of the following errors. If you get these errors, apply the steps in the Resolution section.- A manifest merge error such as .
uses-sdk:minSdkVersion 22 cannot be smaller than version 23 declared in library [com.android.billingclient:billing:9.0.0] - An R8 error during the minify step, for example with an origin of
R8: java.lang.NullPointerException(androidx.core).core-1.15.0-runtime.jar - A duplicate class failure from or
checkDebugDuplicateClasses, involving eithercheckReleaseDuplicateClasses/androidx.coreorandroid.support.v4(for examplekotlin-stdlib).Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt
Cause
IAP 5.4.0 depends on Google Play Billing Library 9.0.0, which in turn requiresandroidx.coreandroidx.coreandroidx.coreResolution
To build IAP 5.4.0 on Unity 2022.3, follow these steps:- Set the minimum API level to 23 or higher
- Pin the Android dependencies with a custom Gradle template
- Build your project
Set the minimum API level to 23 or higher
- Go to Edit > Project Settings > Player > Android > Other Settings.
- Set Minimum API Level to Android 6.0 'Marshmallow' (API level 23) or higher.
Pin the Android dependencies with a custom Gradle template
- Go to Edit > Project Settings > Player > Android > Publishing Settings.
- Under Build, enable Custom Base Gradle Template. Unity creates the file at .
Assets/Plugins/Android/baseProjectTemplate.gradle - Open and add the following block at the end of the file:
baseProjectTemplate.gradle
Keep Custom Base Gradle Template enabled. The dependency versions only apply while Unity builds with this template.allprojects { configurations.all { resolutionStrategy { // androidx.core 1.15.0 requires Android Gradle Plugin 8; // pin to the last release compatible with the Unity 2022.3 toolchain. force 'androidx.core:core:1.13.1' force 'androidx.core:core-ktx:1.13.1' // Align the Kotlin standard library to a single version to avoid duplicate classes. force 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22' force 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22' force 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22' } }}