Sentry-cli: [Android] Support variable for version name and code in the build.gradle

Created on 29 Nov 2017  路  15Comments  路  Source: getsentry/sentry-cli

I have declared the version code and name as something as follows.

project.ext.versionName = '0.0.1'
project.ext.versionCode = 99
////
versionCode project.ext.versionCode
versionName project.ext.versionName

When I tried to upload the assets after the code pushing, cli would output error: Could not parse app id from build.gradle and the uploading process stopped.

Could I explicitly specify the version name so that the cli can skip the detection? FYI, code push supports this kind of flag called --targetBinaryVersion.

Envrionment

  • macOS: 10.13.1
  • node: 8.9.1
  • sentry-cli: 1.23.0

Most helpful comment

The solution is to use --version-name when using dynamic versions, same when using product flavors, specify --bundle-id manually

All 15 comments

For which command is this. react-native codepush?

This is a part of my script to push the assets to Sentry. So the idea is to generate the assets first, then let sentry-cli to upload the assets for me. This idea is copied from the sentry guidelines.

  echo "### [$PLATFORM] Generating build assets ###"
  react-native bundle \
    --dev false \
    --platform "$PLATFORM" \
    --entry-file "$PROJECT_DIR/index.$PLATFORM.js" \
    --bundle-output "$BUILD_DIR/main.jsbundle" \
    --sourcemap-output "$BUILD_DIR/main.jsbundle.map" \
    --assets-dest "$BUILD_DIR"

  echo "### [$PLATFORM] Pushing assets to Sentry ###"
  $PROJECT_DIR/node_modules/sentry-cli-binary/bin/sentry-cli \
    react-native codepush "$CODEPUSH_APP" "$PLATFORM" "$BUILD_DIR" \
    --deployment Production \
    --org my_org \
    --project my_project

Any update on this?

Here is how my gradle is configured versionName is a function, which This part of the sentry cli doesn't like...

def getVersionName = { ->
    def name = project.hasProperty('versionName') ? versionName : "0.0.0"
    println "VersionName is set to $name"
    return name
}

 defaultConfig {
        applicationId "my.app.id"
        versionCode getVersionCode()
        versionName getVersionName()

We need the ability to specify this similar to --targetBinaryVersion in codepush...

sentry-cli is also failing here with error: Could not parse app id from build.gradle. My build.gradle uses methods to fill in the version information (because who wants to manually edit the gradle file on every release?).

  versionCode Integer.parseInt(computeVersionName().replaceAll("[^\\d]", ""))
  versionName computeVersionName()

Any solution to passing the version as a parameter to sentry-cli ?

@mitsuhiko How should we request a feature to add the flag --targetBinaryVersion ? To upload Android CodePush sourcemaps with sentry-cli, I have to manually edit build.gradle with hard-coded version numbers.

  versionCode 123
  versionName "1.2.3"

@mitsuhiko For my case, it should be fixed by changing this line to
static ref VERSION_NAME_RE: Regex = Regex::new(r#"versionName[\s=]+["']([^"']*)["']"#).unwrap();

It just changes \s+ to [\s=]+ to handle the case for project.ext.versionName = '0.0.1'

@mitsuhiko Does that allow computed a computed value for versionName? In our case, the value isn't a string in the build.gradle, but a function call that extracts the version from the package.json.

Have the same issue, any updates?

So, I think we should use --bundle-id option

@antonsivogrivov I don't see bundle-id in the documentation. Would you post a link, or provide an example?

@peacechen

$ sentry-cli react-native appcenter MyApp android ./build/CodePush --bundle-id "$VERSION_ANDROID"

Saw it in help

$ sentry-cli react-native appcenter --help

Thanks @antonsivogrivov . I had an older version of sentry-cli which didn't have that option. Updated to 1.36 and it's there.

We also encountered this problem because we, for some reason, had the character "=" between versionName and its value:

versionCode = rootProject.ext.versionCode
versionName = rootProject.ext.versionName

This made the regex expression on this line fail.

Removing the unnecessary character fixed the problem:

versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName

Posting it here in case it might help someone else.

Closing the issue as a part of large repository cleanup, due to it being inactive and/or outdated.
Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it.
Cheers!

The solution is to use --version-name when using dynamic versions, same when using product flavors, specify --bundle-id manually

Was this page helpful?
0 / 5 - 0 ratings