How do you configure an Android Gradle project so that it filters resources?

Viewed 56

I want to apply filtering to my resources (src/main/resources), at this stage just trying replace 'majorVersion with '1A'. But I can't work out what syntax Gradle requires.

This is my gradle.properties

plugins {
    id 'com.android.application'
}

android {
    compileSdk 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        minSdk 16
        targetSdk 30

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        pickFirst 'META-INF/ASL2.0'
    }

    lint {
        abortOnError false
    }
}

processResources {
    expand(majorVersion : '1A')
}

dependencies {
    implementation project(path: ':common-apk')
    testImplementation "junit:junit:4.13.2"
    androidTestImplementation "com.android.support.test:runner:1.0.2"
    androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
}

But it's not even getting past the config stage of the build and dies with:

Build file 'C:\Source\wylas\wirelesstiming\android-apps\display\build.gradle' line: 31

A problem occurred evaluating project ':display'.
> Could not find method processResources() for arguments [build_yau1h6fg0ru083xv7vjt0sg8$_run_closure2@6ec9337d] on project ':display' of type org.gradle.api.Project.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Line#31 is processResources {

I've spent hours on this. For something that would have taken 30 seconds in Maven. This looks like it is correct, according to page 101 of the Gradle 7.2 UserGuide https://docs.gradle.org/current/userguide/userguide.pdf and any of about 20 SO posts I have worked through.

What am I doing wrong?

0 Answers
Related