braze-inc / braze-cordova-sdk

Public repo for the Braze Cordova SDK
https://www.braze.com
Other
21 stars 63 forks source link

Android build failing: Could not find method kotlinOptions() #91

Closed benmarsh closed 8 months ago

benmarsh commented 1 year ago

Hi,

I'm getting the following error when adding the Braze Cordova SDK to a Capacitor project.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/ben/Code/cap-5-test/node_modules/braze-cordova-sdk/src/android/build-extras.gradle' line: 28

* What went wrong:
A problem occurred evaluating script.
> Could not find method kotlinOptions() for arguments [build_extras_f3s7x5xace2nhpapu2c5nbnj7$_run_closure3$_closure4$_closure5@40cb30f2] on extension 'android' of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

Steps to reproduce;

This is with Gradle 8.0.2 and braze-cordova-sdk 7.0.0

radixdev commented 1 year ago

Hello @benmarsh ,

You'll need to import kotlin into your ionic app. This will likely need to be done in your top level build.gradle file.

benmarsh commented 8 months ago

Finally came back to this upgrade - thanks for the above hint, that worked well. Interestingly it threw up a new problem, but it is different so I will raise a new issue for that.

Just for completeness and to help anyone looking at this in future, I added the following:

/android/app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

/android/build.gradle

buildscript {
    ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.8.20'
    . . .
    dependencies {
        . . .
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"   
    }
}
NoelBaron commented 1 month ago

Finally came back to this upgrade - thanks for the above hint, that worked well. Interestingly it threw up a new problem, but it is different so I will raise a new issue for that.

Just for completeness and to help anyone looking at this in future, I added the following:

/android/app/build.gradle

  • directly below “apply plugin: 'com.android.application'” at top of file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

/android/build.gradle

  • add classpath to dependencies and optionally version at top of buildscript block
  • 1.8.20 is used elsewhere in other Capacitor plugins
buildscript {
  ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.8.20'
  . . .
  dependencies {
      . . .
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"   
  }
}

Thanks @benmarsh this was helpful