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

buildConfigField seems to bug gradle parser causing flavor to not be detected #2815

Open
Grohden opened this issue Jan 14, 2025 · 1 comment
Labels
needs review Issue is ready to be reviewed by a maintainer

Comments

@Grohden
Copy link

Grohden commented Jan 14, 2025

Build/Submit details page URL

No response

Summary

I've been having this issue after trying to get flavors to work in our bare project. Nothing made sense since I was just doing normal gradle stuff AND following the docs, so I decided to investigate, essentially in parseGradleCommand neither flavorDimensions nor productFlavors are being found

I tried to debug the parser and... well, I discovered that I don't want to debug a parser right now. However I've noticed that my keys are being parsed, but they're in the wrong place:

Image

Managed or bare?

Bare

Environment

expo-env-info 1.2.2 environment info:
System:
OS: macOS 15.0
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.18.0 - ~/.asdf/installs/nodejs/20.18.0/bin/node
Yarn: 4.3.1 - ~/.asdf/installs/nodejs/20.18.0/bin/yarn
npm: 10.8.2 - ~/.asdf/plugins/nodejs/shims/npm
Managers:
CocoaPods: 1.16.2 - /Users/gabrielrohden/.asdf/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 24.2, iOS 18.2, macOS 15.2, tvOS 18.2, visionOS 2.2, watchOS 11.2
Android SDK:
API Levels: 28, 30, 33, 34, 35
Build Tools: 34.0.0, 35.0.0, 36.0.0
System Images: android-34 | Google APIs ARM 64 v8a, android-34 | Google Play ARM 64 v8a, android-34 | Google Play Intel x86_64 Atom, android-35 | Google Play ARM 64 v8a, android-35 | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
IDEs:
Xcode: 16.2/16C5032a - /usr/bin/xcodebuild
npmPackages:
expo: ^52.0.0 => 52.0.23
react: 18.3.1 => 18.3.1
react-dom: ^18.3.1 => 18.3.1
react-native: 0.76.5 => 0.76.5
npmGlobalPackages:
eas-cli: 14.4.0
Expo Workflow: bare

Error output

Unable to read gradle project config: flavor staging is not defined.
log.js:55Values from app/build.gradle might be resolved incorrectly.
log.js:55Error: Failed to autodetect applicationId in multi-flavor project.

Reproducible demo or steps to reproduce from a blank project

I didn't setup any runtime/test of this cli codebase, but I think that this file might help to pinpoint where the parser is failing

apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")

import com.android.build.OutputFile

react {
    debuggableVariants = ["debug"]

    autolinkLibrariesWithApp()

    entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", rootDir.getAbsoluteFile().getParentFile().getAbsolutePath(), "android", "absolute"].execute(null, rootDir).text.trim())
    cliFile = new File(["node", "--print", "require.resolve('@expo/cli')"].execute(null, rootDir).text.trim())
    bundleCommand = "export:embed"
}

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc-intl:+'

android {
    buildFeatures {
        buildConfig true
    }

    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.rnproject"
    defaultConfig {
        applicationId "com.rnproject"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        multiDexEnabled true
        versionName "3.29.0"
        versionCode 1731069170
        testBuildType System.getProperty('testBuildType', 'debug')
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

        buildConfigField "String", "BRAZE_ANDROID_API_KEY", "\"${System.getenv("BRAZE_ANDROID_API_KEY")}\""
        buildConfigField "String", "SUNSHINE_ANDROID_API_KEY", "\"${System.getenv("SUNSHINE_ANDROID_API_KEY")}\""
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    flavorDimensions "env"
    productFlavors {
        staging {
            dimension "env"
            applicationId 'com.rnproject'
        }
        production {
            dimension "env"
            applicationId 'com.rnproject'
        }
    }
}

dependencies {
    implementation("com.facebook.react:react-android")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

apply plugin: 'com.google.gms.google-services'
@Grohden Grohden added the needs review Issue is ready to be reviewed by a maintainer label Jan 14, 2025
@Grohden
Copy link
Author

Grohden commented Jan 14, 2025

btw, just declaring them with parenthesis works:

buildConfigField("String", "BRAZE_ANDROID_API_KEY", "\"${System.getenv("BRAZE_ANDROID_API_KEY")}\"")
buildConfigField("String", "SUNSHINE_ANDROID_API_KEY", "\"${System.getenv("SUNSHINE_ANDROID_API_KEY")}\"")

But having that cause expo to not detect flavors/parse configs incorrectly is a big deal, especially if no error is raised (or the wrong one is raised in this case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

1 participant