Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifestPlaceholders: appAuthRedirectScheme missing from android/app/build.gradle causing build errors #2743

Open
dpuckett opened this issue Dec 5, 2024 · 11 comments

Comments

@dpuckett
Copy link

dpuckett commented Dec 5, 2024

Build/Submit details page URL

No response

Summary

This is a continuation from bug #2322 since no one will look at it.
This is causing multiple people using the Expo AuthSession package build issues, has been reopened multiple times and is being ignored.

Currently the only way to fix the problem is to manually change the android/app/build.gradle to include:

defaultConfig{
  manifestPlaceholders = [appAuthRedirectScheme: '<yourAppScheme>']
} 

Then use patch-project to create a build time patch that is applied.
This is then however causing other side effects, and inconveniences.

Please refer to the original bug log AND FIX.

Managed or bare?

either

Environment

expo-env-info 1.2.1 environment info:
System:
OS: macOS 14.2
Shell: 5.9 - /bin/zsh
Binaries:
Node: 21.2.0 - /opt/homebrew/bin/node
Yarn: 1.22.22 - ~/.yarn/bin/yarn
npm: 10.2.3 - /opt/homebrew/bin/npm
Watchman: 2023.11.20.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.14.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.4, iOS 17.4, macOS 14.4, tvOS 17.4, visionOS 1.1, watchOS 10.4
Android SDK:
API Levels: 28, 29, 30, 31, 32, 33, 34, 35
Build Tools: 30.0.3, 31.0.0, 33.0.0, 33.0.1, 34.0.0, 35.0.0, 35.0.0
System Images: android-30 | Google APIs ARM 64 v8a, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play ARM 64 v8a, android-31 | ARM 64 v8a, android-31 | Google APIs Intel x86 Atom_64, android-32 | Google APIs ARM 64 v8a, android-33 | Google APIs ARM 64 v8a, android-34 | Google APIs ARM 64 v8a, android-S | Google APIs ARM 64 v8a, android-VanillaIceCream | Google Play ARM 64 v8a
IDEs:
Android Studio: 2023.3 AI-233.14808.21.2331.11709847
Xcode: 15.3/15E204a - /usr/bin/xcodebuild
npmPackages:
expo: ^52.0.11 => 52.0.14
react: 18.3.1 => 18.3.1
react-dom: 18.3.1 => 18.3.1
react-native: 0.76.3 => 0.76.3
react-native-web: ~0.19.10 => 0.19.13
npmGlobalPackages:
eas-cli: 10.0.3
Expo Workflow: bare

Error output

No response

Reproducible demo or steps to reproduce from a blank project

https://snack.expo.dev/@hibobo/github.com-h1b0b0-trello-mobile-app

@dpuckett dpuckett added the needs review Issue is ready to be reviewed by a maintainer label Dec 5, 2024
@szdziedzic
Copy link
Member

Hey,

It seems like it is some sort of bug in this package's config plugin. There shouldn't be a need to substitute a placeholder for this value from the build.gradle level, but rather the value itself should be put in the manifest while prebuild happens (config plugin should do it) 🤔 I will try to talk about it with people who work on expo-auth-session and will get back to you.

@szdziedzic szdziedzic added eas build and removed needs review Issue is ready to be reviewed by a maintainer labels Dec 6, 2024
@szdziedzic
Copy link
Member

It started to occur for you after installing expo-auth-session, right?

@szdziedzic
Copy link
Member

I see that probably the same issue occurs for react-native-app-auth and react-native-auth0 🤔

@szdziedzic
Copy link
Member

It seems like what you can do is add a config plugin that looks like this (I didn't test it, I just generated it with chat gpt):

// withAppRedirectScheme.js

const { withAppBuildGradle } = require('@expo/config-plugins');

// Function to add the redirect scheme to build.gradle
const addRedirectSchemeToGradle = (config, redirectScheme) => {
    return withAppBuildGradle(config, config => {
        if(config.modResults.language === 'groovy') { 
            // Using regex to insert manifestPlaceholders
            let gradleContent = config.modResults.contents;
            const manifestPlaceholders = `manifestPlaceholders = [appAuthRedirectScheme: "${redirectScheme}"]`;
            const defaultConfigPattern = /defaultConfig \{/;

            if (!gradleContent.match(manifestPlaceholders)) {
                gradleContent = gradleContent.replace(defaultConfigPattern, `defaultConfig {\n        ${manifestPlaceholders}`);
            }

            config.modResults.contents = gradleContent;
        }
        return config;
    });
};

// Accept configuration options with a "scheme" property
const withAppRedirectScheme = (config, options = {}) => {
    const { scheme } = options;

    if (!scheme) {
        throw new Error("AppRedirectScheme plugin requires a valid 'scheme' option");
    }
    
    return addRedirectSchemeToGradle(config, scheme);
};

module.exports = withAppRedirectScheme;

which you can use as

// app.config.js

const withAppRedirectScheme = require('./plugins/withAppRedirectScheme');

module.exports = {
    name: "YourAppName",
    slug: "your-app-name",
    // other configuration options ...
    plugins: [
      [withAppRedirectScheme, { scheme: 'scheme' }]
    ],
};

in your app config to solve your issues. You can give it a try and test if it works for you. This way the placeholder will be filled for you during the prebuild phase by this mod. You can also take a look at these docs for more context https://docs.expo.dev/config-plugins/plugins-and-mods.

I've seen in the repro you sent at the bottom of the issue that react-native-app-auth is being used there and it's likely that the error is being thrown because of this lib (which Expo doesn't own) not working well with CNG flow. They even mention that you need to set it in their docs: https://github.com/FormidableLabs/react-native-app-auth?tab=readme-ov-file#notes. I'm kind of confused that you mentioned expo-auth-session on top of the issue. Do you use expo-auth-session as well?

@dpuckett
Copy link
Author

dpuckett commented Dec 6, 2024

Thank you for looking at this @szdziedzic.

The repro demo was taken from the original bug log mentioned, as it was quicker and more consistent than making a new one.

Personally our project uses Expo Auth Session, and this problem started being encountered once in use.

As per the bug log, this appears to be a problem with multiple Auth packages, and the eas build process when interpreting them, leading me to believe it is an issue with the eas build process itself for this gradle setting.

It shouldn't really be necessary for me to have to use a custom config plugin for this to work, since expo are providing both the Auth package and the build service.

I appreciate the effort as a workaround, but I already have a workaround in the form of a project patch.

Ideally however it shouldn't require either, and any settings should be part of the Auth session configuration.

@szdziedzic
Copy link
Member

szdziedzic commented Dec 6, 2024

As per the bug log, this appears to be a problem with multiple Auth packages, and the eas build process when interpreting them, leading me to believe it is an issue with the eas build process itself for this gradle setting.

It doesn't seem right to me to introduce logic to add some magic Android Manifest edit logic on the EAS Build side because it would be hacky and could potentially break some other setups + it can lead to weird side effects for all other projects that currently work well on EAS. The existing mechanism for such modifications is mods/plugins that are executed during prebuild and I believe that "magically" modifying the result config produced by it on EAS Build is dangerous and can lead to very hard-to-debug issues 🤔. I would say that this should be solved on the project level (or library) level by adding the config plugin to modify the result AndroidManifest.

We can't really do much about other auth packages that we don't own, but yeah, if it is the issue with expo-auth-session that we own the config plugin for this package should handle it by default 👍. I will talk to people who work on this lib about it.

@dpuckett
Copy link
Author

dpuckett commented Dec 6, 2024

That seems fair enough. That would address my issue personally, and seems a less intrusive way to fix the issue. It could also be taken as an example by other package providers then as well.

If the addition of a config-plugin to expo-auth-session would fix this issue by default for current users without the need for a workaround, then it sounds like the way to go.

Thank you

@szdziedzic
Copy link
Member

@dpuckett is there a chance that you have react-native-app-auth in your app's dependencies?

@dpuckett
Copy link
Author

dpuckett commented Dec 9, 2024

@dpuckett is there a chance that you have react-native-app-auth in your app's dependencies?

Apparently it is. It may have been added previously when attempting to solve other issues with expo-auth-session at the time.
Do you think this is the cause?

@szdziedzic
Copy link
Member

Yeah, I think this lib is the root cause of the issue. I believe that once you uninstall it, everything should start to work 🤔.

@szdziedzic
Copy link
Member

Even without config plugins/workarounds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants