Android build fails: “Execution failed for task ':react-native-iap:compilePlayDebugKotlin'”
This Gradle message hides the real error. Almost always, the installed react-native-iap is older than your React Native version, whose Kotlin APIs changed. Scroll up to the first e: line. String? but String was expected (React Native 0.76 / Expo 52) needs react-native-iap 12.15.7+. ObjectAlreadyConsumedException … internal (React Native 0.77) needs 12.16.2+. Upgrade and rebuild.
Symptom
The Android build fails with:
Execution failed for task ':react-native-iap:compilePlayDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
- It started right after upgrading React Native or the Expo SDK.
- Release builds fail the same way on
compilePlayReleaseKotlin.
Why it happens
React Native 0.76 rewrote parts of its Android bridge in Kotlin. Some parameters that used to accept null no longer do, and a class the library used became internal in 0.77. react-native-iap releases from before those versions don't compile against them. Each case has a fixed release:
First e: line |
Your React Native | Fixed in react-native-iap |
|---|---|---|
Type mismatch: inferred type is String? but String was expected (in PromiseUtlis.kt) |
0.76 / Expo SDK 52 | 12.15.7 |
Cannot access 'class ObjectAlreadyConsumedException …': it is internal |
0.77 | 12.16.2 |
Argument type mismatch: actual type is 'kotlin.String?' (in RNIapModule.kt) |
0.77 | 12.16.2 |
Module was compiled with an incompatible version of Kotlin |
Older projects | Align kotlinVersion in the root build.gradle |
| Any of the above on React Native 0.81+ with react-native-iap 13.x | 0.81+ | Move to react-native-iap 14.x; 13.x doesn't target that toolchain |
Confirm it
- Get the real error:
cd android && ./gradlew :react-native-iap:compilePlayDebugKotlin 2>&1 | grep -m3 "^e:"
- Check the versions you actually have installed:
npm ls react-native react-native-iap
- Match the
e:line and versions against the table above.
Fix
- Upgrade react-native-iap to the version in the table for your React Native release, or the latest in its major version:
npm install react-native-iap@^12.16.2
On React Native 0.81 or later, move to the current major version and follow its migration guide.
- Clean and rebuild:
cd android && ./gradlew clean && cd ..
npx react-native run-android # or: npx expo run:android
In Expo with Continuous Native Generation, run npx expo prebuild --clean first.
- Kotlin version mismatch: set
kotlinVersioninandroid/build.gradle(ext { kotlinVersion = "…" }) to the version your React Native release expects, then rebuild. - Still failing: check that no other dependency pins an old react-native-iap through a
resolutionsoroverridesentry.
Stop it coming back
- Upgrade native libraries in the same change as React Native or the Expo SDK, and check each library's supported React Native range first.
- Build Android in CI on every dependency change, so a Kotlin break shows up in the pull request, not on release day.
If you use BillDog
This error comes from react-native-iap's own Gradle module, and BillDog doesn't change it. BillDog's React Native package is a separate native module with its own Android code, so if you're replacing react-native-iap with BillDog, uninstall react-native-iap completely rather than leaving both installed. The library versions on this page come from react-native-iap's releases and issues, and haven't been reproduced on a device for this page.
Related
Sources
Did this fix it?
Frequently asked questions
What does 'Play' mean in compilePlayDebugKotlin?
It's react-native-iap's store flavour. The library builds a Play variant (and an Amazon one), so Gradle names its tasks compilePlayDebugKotlin or compilePlayReleaseKotlin. The failure is in the library's Kotlin code, not in your app.
Will missingDimensionStrategy 'store', 'play' fix it?
No. That line fixes a different error, where your app can't choose which react-native-iap variant to use. It doesn't fix Kotlin that won't compile inside the library.
Can I patch the Kotlin file myself?
You can with patch-package, but it's fragile. The fixed releases are small upgrades within the same major version, so upgrade unless something blocks you.