How to use a shell environment variable to set gradleprops in metadata?

My build.gradle file sets a BuildConfig variable from the result of running ‘git describe --dirty’ so that the app’s About dialog can show what git revision the code was built from. Because build processes for F-droid and Travis modify the build.gradle file, this always shows up with ‘dirty’ in it. For Travis builds I’ve worked around the problem by running git before the code is modified, capturing the result in a shell variable, and then passing it to gradlew via a -P. But F-droid’s build process is different, and I can’t figure out a workaround. This sort of thing doesn’t work:

prebuild:

  • GITREV=$(git describe --tags --dirty)
    gradleprops:
  • GITREV=$(GITREV)

Looking at other metadata files, it appears some use a “build” stanza and invoke gradlew directly. Presumably if I did that I could use -P and perhaps mimic what I do for Travis. But the easy mods to my .yml file don’t work, so it’ll take some time to explore this option. I hope instead there’s a way to keep the structure I have.

And yeah, for the short term I can just hard-code GITREV. :slight_smile:

Thanks,

–Eric

Could you post the whole build block and name the app (I assume it’s already on F-Droid)?

Sorry. From org.eehouse.android.xw4.yml:

  - versionName: 4.4.174
    versionCode: 170
    commit: android_beta_174
    subdir: xwords4/android/app
    sudo:
      - apt-get update || apt-get update
      - apt-get install -y graphicsmagick-imagemagick-compat python3-lxml
    gradle:
      - Xw4fdroid
    rm:
      - xwords4/dawg/English/BasEnglish.dict.gz
    prebuild:
      - sed -i -e '/\/\/ rm-for-fdroid$/d' {..,.}/build.gradle
      - sed -i -e '/com.google.gms/d' build.gradle
    ndk: r21d
    gradleprops:
      - GITREV=android_beta_174

In the last line I want to set GITREV from state gathered earlier using a shell command, probably before the prebuild section.

Thanks,

–Eric

If I understood correctly, you can add the variable to gradle.properties at prebuild:

    prebuild:
      - echo GITREV=$(git describe --tags --dirty) >> ../gradle.properties

That works – except that by the time the stuff in prebuild: runs the repo has already been modified and so show up as dirty. The modification is removal of a ‘signingConfigs’ stanza in my app/build.gradle file.

Is there any way to run shell code at the very beginning of the process?

Yes, put this code into the init block:

    init:
      - echo GITREV=$(git describe --tags --dirty) >> ../gradle.properties

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.