cli
cli copied to clipboard
Allow gradle options to be passed to build
Describe the Feature
It would be great if we could include options for the gradle build command, or overwrite them completely
Here is the related source https://github.com/react-native-community/cli/blob/master/packages/platform-android/src/commands/runAndroid/index.ts#L204
This would allow me to disable tests for the build for example
Possible Implementations
function buildApk(gradlew: string, sourceDir: string, replacementGradleBuildArgs: string = undefined) {
try {
// using '-x lint' in order to ignore linting errors while building the apk
const gradleBuildArgs = replacementGradleBuildArgs || ['-x', 'lint'].join(' ');
const gradleArgs = ['build', gradleBuildArgs];
logger.info('Building the app...');
logger.debug(`Running command "${gradlew} ${gradleArgs.join(' ')}"`);
execa.sync(gradlew, gradleArgs, {stdio: 'inherit', cwd: sourceDir});
} catch (error) {
throw new CLIError('Failed to build the app.', error);
}
}
buildApk(gradlew, androidProject.sourceDir, args.gradleBuildArgs);
Usage:
yarn android --gradleBuildArgs="-x lint -x test"
I would expect to see in the logs:
Running command gradle build -x lint - x test
I am happy to do a PR if this issue is flagged as good to go
cc @Krizzu @troZee @dulmandakh
I believe this is essential for multi-stage builds, since Gradle allows easy build time overrides. Due to missing support of this feature, I was forced to come up with hack I did not like.
If there is interest from maintainer, I am willing to spend time on this.
cc @thymikee @Krizzu @troZee @dulmandakh
As a workaround, I used env variables. I know it is not perfect but enough for my use case. Hope it will help someone. Let me know if there is a better way, please :)
# this would be my own run-android.sh where I can pass VAR1 as parameter
export VAR1=foo
react-native run-android
In build.gradle then:
def name = "$System.env.VAR1"
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
There's ongoing effort to add custom gradle options with #1729