dpa99c / cordova-plugin-firebasex

Cordova plugin for Google Firebase
MIT License
570 stars 457 forks source link

Is it possible to compile with GradlePluginKotlinEnabled? #863

Closed TheNotorius0 closed 3 months ago

TheNotorius0 commented 3 months ago

If we set <preference name="GradlePluginKotlinEnabled" value="true" />, cordova-plugin-firebasex crashes with this error (only after the 16.2.0 version though, the 16.1.0 version still works fine):

Task :app:compileDebugKotlin FAILED
e: C:/Users/sevan/.gradle/caches/transforms-3/1ee3f7841abe9979797edc39b62bd26a/transformed/jetified-firebase-auth-22.2.0-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.firebase-auth-api_firebase-auth-api.kotlin_module: Module was compiled with an inc
ompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/sevan/.gradle/caches/transforms-3/dade25bead44bca314189166709326d8/transformed/jetified-play-services-measurement-api-21.5.0-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled
 with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

Unfortunately, I'm using admob-plus-cordova too, and I need to set it to trueto make it work. So, is there a way to make this plugin work after the 16.2.0 version using the Kotlin extensions library?

To Reproduce

cordova plugin add admob-plus-cordova
cordova plugin cordova-plugin-firebasex
cordova build android
Task :app:compileDebugKotlin FAILED

Expected behavior Both plugins should work without failing to compile. I guess that since "GradlePluginKotlinEnabled" is deprecated, it's admob-plus that should fix this issue, but I'm not a Kotlin expert.

Additional context The Task :app:compileDebugKotlin FAILED only started to happen after cordova-plugin-firebasex@16.2.0 (I'm still using cordova-plugin-firebasex@16.1.0 and it compiles).

dpa99c commented 3 months ago

The error message states that the Kotlin module for the Firebase Measurement API was compiled with Gradle v1.9.0 but your project is configured to use v1.7.1 so it can't build.

To fix this, you need to configure your project to use v1.9.0 or above.

In a Cordova project this can be done in the config.xml:

<platform name="android">
    <preference name="GradlePluginKotlinEnabled" value="true" />
    <preference name="GradlePluginKotlinVersion" value="1.9.0" />   
</platform>
TheNotorius0 commented 3 months ago

I wished it was that easy, I 've already tried to set <preference name="GradlePluginKotlinVersion" value="1.9.0" />, but then it gives me this error:

Error: The 'kotlin-android-extensions' Gradle plugin is no longer supported. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.

At this point, though, I'm not even sure if it has anything to do with this plugin.

dpa99c commented 3 months ago

does it build with v1.9.0 if you remove admob-plus-cordova from the project?

TheNotorius0 commented 3 months ago

No, it still gives me the same error even with admob-plus-cordova removed:

> Configure project :app
Error: The 'kotlin-android-extensions' Gradle plugin is no longer supported. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and t
he 'kotlin-parcelize' plugin.
strippedNativeLibsDir is deprecated and no longer used. Please remove it from your build configuration.

> Task :app:compileDebugKotlin FAILED
e: The Android extensions ('kotlin-android-extensions') compiler plugin is no longer supported. Please use kotlin parcelize and view binding. More information: https://goo.gle/kotlin-android-extensions-deprecation

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

Keep in mind that if I set GradlePluginKotlinEnabled to false, cordova-plugin-firebasex builds fine, but admob-plus-cordova won't work.

dpa99c commented 3 months ago

https://github.com/apache/cordova-android/issues/1642

dpa99c commented 3 months ago

This is because cordova-android@12 is not compatible with Kotlin v1.9 You can try to pin older versions of the Android Firebase SDK components using plugin variables to choose those which use an earlier version of Kotlin. Or you can manually edit your Gradle files as outlined in the above issue.

Closing because it is not directly caused/cannot be fixed by this plugin.

TheNotorius0 commented 3 months ago

For anyone having the same problem, I fixed it with the following steps:

On config.xml:

<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinVersion" value="1.9.0" />

Then, on \platforms\android\app\build.gradle:

Delete the line 24: apply plugin: 'kotlin-android-extensions'

I've created a Cordova hook so I don't have to manually delete the line everytime I add or remove the android platform. This is just temporary solution until cordova-13 arrives (that line will be automatically removed in cordova-13).