Skip to content

Latest commit

 

History

History
178 lines (143 loc) · 6.97 KB

File metadata and controls

178 lines (143 loc) · 6.97 KB

Here is an example config plugin for an Expo (Continuous Native Generation) app using this library, kept in line with the demo app's plugin at /expo/withIgnitePlugin.js (Expo SDK 56 / React Native 0.85).

Create a file called withIgnitePlugin.js and paste in the below code

const {
  AndroidConfig,
  withAppBuildGradle,
  withGradleProperties,
  withProjectBuildGradle,
  withStringsXml,
  withPodfileProperties,
} = require('@expo/config-plugins');

const KOTLIN_VERSION = '2.3.0';

module.exports = function withIgnitePlugin(expoConfig) {
  withGradleProperties(expoConfig, (config) => {
    config.modResults = config.modResults.filter(
      (item) =>
        !(item.type === 'property' && item.key === 'android.kotlinVersion')
    );
    config.modResults.push({
      type: 'property',
      key: 'android.kotlinVersion',
      value: KOTLIN_VERSION,
    });
    return config;
  });

  withProjectBuildGradle(expoConfig, (config) => {
    config.modResults.contents = config.modResults.contents.replace(
      "classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')",
      `classpath('org.jetbrains.kotlin:kotlin-gradle-plugin:${KOTLIN_VERSION}')`
    );
    return config;
  });

  withAppBuildGradle(expoConfig, (config) => {
  
    const buildGradleUpdates = [`buildFeatures {`, `dataBinding = true`, `}`, `compileOptions {`, `coreLibraryDesugaringEnabled true`, `}`].join(
      "\n"
    );

    config.modResults.contents = config.modResults.contents.replace(
      `android {`,
      `android {\n${buildGradleUpdates}`
    );

    config.modResults.contents = config.modResults.contents.replace(
      `compileSdk rootProject.ext.compileSdkVersion`,
      `compileSdk 36`
    );

    config.modResults.contents = config.modResults.contents.replace(
      `minSdkVersion rootProject.ext.minSdkVersion`,
      `minSdkVersion 28`
    );

    config.modResults.contents = config.modResults.contents.replace(
      `dependencies {`,
      `dependencies {\ncoreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.3'\n`
    );

    return config;
  });

  withStringsXml(expoConfig, (modConfig) => {
    const isModernAccounts = false
    const isSportXr = false
    const modernAccountsSchemes = [''];
    const sportXRSchemes = [''];
    
    if(isModernAccounts) {
      modernAccountsSchemes.forEach((value, index) => {
        modConfig.modResults = AndroidConfig.Strings.setStringItem(
          [
            {
              _: value,
              $: {
                name: `${
                  index === 0
                    ? 'app_tm_modern_accounts_scheme'
                    : `app_tm_modern_accounts_scheme_${index + 1}`
                }`
              }
            }
          ],
          modConfig.modResults
        );
      });
    } else if (isSportXr) {
      sportXRSchemes.forEach((value, index) => {
        modConfig.modResults = AndroidConfig.Strings.setStringItem(
          [
            {
              _: value,
              $: {
                name: `${
                  index === 0
                    ? 'app_tm_sportxr_scheme'
                    : `app_tm_sportxr_scheme_${index + 1}`
                }`
              }
            }
          ],
          modConfig.modResults
        );
      });
    }

    return modConfig;
  });

  withPodfileProperties(expoConfig, (config) => {
    config.modResults['ios.deploymentTarget'] = '17.0';
    return config;
  });

  return expoConfig;
};

You can then add the config plugin to your array of plugins in app.json

    "plugins": [
      ...
      "./withIgnitePlugin"
      ...
    ],

You will need to update isModernAccounts or isSportXr to true and add all your schemes to the respective array in withStringsXml() for Android. If you skip this, the login screen opens but never redirects back into your app after authenticating — i.e. login appears to do nothing. The scheme value comes from your Ticketmaster developer app settings.

If you have a Modern Accounts Scheme you would have the below:

const isModernAccounts = true
const modernAccountsSchemes = ["myScheme"];

or for an Android app with multiple API keys:

const isModernAccounts = true
const modernAccountsSchemes = ["firstScheme", "secondScheme"];

You can update withIgnitePlugin.js's values for iOS deployment target, compileSdkVersion etc. to the values needed for your project.

Kotlin version — required for Ticketmaster SDK 3.18.0+: the SDK pulls in kotlin-stdlib:2.3.0, which the Expo/RN-default Kotlin compiler (2.1.20) cannot read. Without the pin below, Android builds fail compiling the :react-native-ticketmaster-ignite (and :react-native-safe-area-context) Kotlin — e.g. :react-native-ticketmaster-ignite:compileDebugKotlin errors with the binary version of its metadata is 2.3.0, expected version is 2.1.0. Because the native android/ directory is regenerated by expo prebuild, this must be set through the config plugin — editing android/gradle.properties or android/build.gradle directly won't survive a prebuild. Use Kotlin 2.2.0 or newer (a 2.2.x compiler reads 2.3.0 metadata via Kotlin's one-minor-forward tolerance); this repo pins 2.2.21. Keep it within the range your Expo SDK's bundled KSP and Compose compiler plugin support — don't jump straight to 2.3.0, since SDK 56's latest bundled KSP still targets 2.2.x and would break.

The plugin applies this pin in two mods. withGradleProperties sets the android.kotlinVersion property — Expo maps it onto the version-catalog kotlin entry, which drives rootProject.ext.kotlinVersion (consumed by the library module) plus the Compose compiler plugin / KSP versions. withProjectBuildGradle then pins the root buildscript's kotlin-gradle-plugin classpath, which is declared version-less and would otherwise resolve to RN's transitive 2.1.20 — setting the property alone isn't enough.

Troubleshooting

Koin dependency issues

If you face any Koin dependency issues you can add the below inside withProjectBuildGradle() to force koin versions in your project to a specific version

    const projectGradleUpdates = [`configurations.all {`, `resolutionStrategy {`, `force "io.insert-koin:koin-android:4.0.2"`, `force "io.insert-koin:koin-core:4.0.2"
      `, `eachDependency { details ->`, `if (details.requested.group == "io.insert-koin" && details.requested.name == "koin-android") {`, `details.useVersion "4.0.2"`, `}`,`if (details.requested.group == "io.insert-koin" && details.requested.name == "koin-core") {`, `details.useVersion "4.0.2"`, `}`, `}`, `}`, `}`].join(
            "\n"
          );
      
      config.modResults.contents = config.modResults.contents.replace(
      `allprojects {`,
      `allprojects {\n${projectGradleUpdates}`
    );

Update all references of 4.0.2 to the desired version

It has been reported that the inclusion of expo-dev-client may cause crashes for Android, you can try removing this library if you experience problems.