-
-
Notifications
You must be signed in to change notification settings - Fork 204
feat(android): ship the app and plugin gradle files with the CLI #6129
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
7dedb57
77cfbb6
108f3c2
89f2ffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
The gradle build scripts used to live only in the android runtime, so any fix to them had to wait for a runtime release. This bundles the app-level gradle files in `vendor/gradle-app` and copies them over the ones the runtime lays down when the platform is added, the same way the plugin build already uses `vendor/gradle-plugin`. - `vendor/gradle-app` holds `build.gradle`, `settings.gradle`, `app/build.gradle`, `app/gradle.properties` and the `app/gradle-helpers`. They are copied on top of the runtime files in `createProject`, so the runtime keeps providing everything that is not part of the overlay. - `--no-override-runtime-gradle-files` opts out and keeps the runtime files. - The directory the files come from is resolved through `getGradleFilesPath`, which already understands an `android.gradleFilesPackageName` config key so the files can later be provided by an npm package instead of the bundled copy. - The CLI now interpolates `__PACKAGE__` (android namespace) and `USER_PROJECT_ROOT` in the copied files, and honours `android.gradleVersion` by rewriting the gradle wrapper. - `--gradleArgs` becomes an array option, so it can be passed several times, and a single value may hold several space separated arguments. Arguments listed in `android.gradleArgs` are passed too, before the command line ones. Both app and plugin builds go through the same merge. - Both app and plugin gradle invocations now get `-PcompileSdk`, `-PtargetSdk`, `-PbuildToolsVersion`, `-PgenerateTypings`, `-PprojectRoot` and `-PappBuildPath` (the last two also as `-D` so `settings.gradle` can read them before project properties exist). - A debug build is signed when the `--key-store-*` options are passed, which is needed for system app builds. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -578,7 +578,13 @@ interface IAndroidOptions extends IEmbedOptions { | |
| */ | ||
| gradleFlavor: string; | ||
| gradlePath: string; | ||
| gradleArgs: string; | ||
| gradleArgs: string[]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Retain compatibility with scalar Existing JavaScript
📍 Affects 6 files
🤖 Prompt for AI Agents |
||
| /** | ||
| * When true (the default) the gradle files bundled with the CLI are copied | ||
| * over the ones shipped by the android runtime. Pass `--no-override-runtime-gradle-files` | ||
| * to keep the runtime files untouched. | ||
| */ | ||
| overrideRuntimeGradleFiles: boolean; | ||
| } | ||
|
|
||
| interface IIOSOptions extends IEmbedOptions {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,8 @@ import { injector } from "../common/yok"; | |
| import * as _ from "lodash"; | ||
| import { resolvePackageJSONPath } from "@rigor789/resolve-package-path"; | ||
| import { cwd } from "process"; | ||
| import { IAndroidToolsInfo } from "../declarations"; | ||
| import { IGradleBuildArgsService } from "../definitions/gradle"; | ||
|
|
||
| export class AndroidPluginBuildService implements IAndroidPluginBuildService { | ||
| private get $platformsDataService(): IPlatformsDataService { | ||
|
|
@@ -46,7 +48,9 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { | |
|
|
||
| constructor( | ||
| private $fs: IFileSystem, | ||
| private $androidToolsInfo: IAndroidToolsInfo, | ||
| private $childProcess: IChildProcess, | ||
| private $gradleBuildArgsService: IGradleBuildArgsService, | ||
| private $hostInfo: IHostInfo, | ||
| private $options: IOptions, | ||
| private $logger: ILogger, | ||
|
|
@@ -263,7 +267,9 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { | |
| ); | ||
| await this.buildPlugin({ | ||
| gradlePath: options.gradlePath, | ||
| gradleArgs: options.gradleArgs, | ||
| gradleArgs: ( | ||
| this.$projectData.nsConfig?.android?.gradleArgs ?? [] | ||
| ).concat(options.gradleArgs ?? []), | ||
| pluginDir: pluginTempDir, | ||
| pluginName: options.pluginName, | ||
| projectDir: options.projectDir, | ||
|
|
@@ -413,10 +419,11 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { | |
| this.addCompileDependencies(platformsAndroidDirPath, buildGradlePath); | ||
| const runtimeGradleVersions = | ||
| await this.getRuntimeGradleVersions(projectDir); | ||
| this.replaceGradleVersion( | ||
| pluginTempDir, | ||
| runtimeGradleVersions.gradleVersion, | ||
| ); | ||
| // a gradle version pinned in the project config wins over the runtime one | ||
| const gradleVersion = | ||
| this.$projectData.nsConfig?.android?.gradleVersion ?? | ||
| runtimeGradleVersions.gradleVersion; | ||
| this.replaceGradleVersion(pluginTempDir, gradleVersion); | ||
| this.replaceGradleAndroidPluginVersion( | ||
| buildGradlePath, | ||
| runtimeGradleVersions.gradleAndroidPluginVersion, | ||
|
|
@@ -808,22 +815,38 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { | |
| pluginBuildSettings.gradlePath ?? | ||
| (this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew"); | ||
|
|
||
| const toolsInfo = this.$androidToolsInfo.getToolsInfo({ | ||
| projectDir: this.$projectData.projectDir, | ||
| }); | ||
|
|
||
| const localArgs = [ | ||
| "-p", | ||
| pluginBuildSettings.pluginDir, | ||
| "assembleRelease", | ||
| `-PtempBuild=true`, | ||
| `-PcompileSdk=${toolsInfo.compileSdkVersion}`, | ||
| `-PtargetSdk=${toolsInfo.targetSdkVersion}`, | ||
| `-PbuildToolsVersion=${toolsInfo.buildToolsVersion}`, | ||
| `-PprojectRoot=${this.$projectData.projectDir}`, | ||
| // settings.gradle runs before the project properties are available, | ||
| // so the same values have to be passed as system properties too | ||
| `-DprojectRoot=${this.$projectData.projectDir}`, | ||
| `-PappBuildPath=${this.$projectData.getBuildRelativeDirectoryPath()}`, | ||
| `-DappBuildPath=${this.$projectData.getBuildRelativeDirectoryPath()}`, | ||
| `-PappPath=${this.$projectData.getAppDirectoryPath()}`, | ||
| `-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`, | ||
|
Comment on lines
+818
to
837
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use
🤖 Prompt for AI Agents |
||
| ]; | ||
|
|
||
| if (pluginBuildSettings.gradleArgs) { | ||
| localArgs.push(pluginBuildSettings.gradleArgs); | ||
| for (const gradleArg of pluginBuildSettings.gradleArgs ?? []) { | ||
| localArgs.push( | ||
| ...gradleArg | ||
| .split(" ") | ||
| .map((arg) => arg.trim()) | ||
| .filter((arg) => !!arg), | ||
| ); | ||
| } | ||
|
|
||
| if (this.$logger.getLevel() === "INFO") { | ||
| localArgs.push("--quiet"); | ||
| } | ||
| localArgs.push(...this.$gradleBuildArgsService.getBuildLoggingArgs()); | ||
|
|
||
| const opts: any = { | ||
| cwd: pluginBuildSettings.pluginDir, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use complete, hyphenated Gradle argument text.
Replace the sentence fragment “Can be passed multiple times” with a complete sentence. Replace “space separated” with “space-separated”.
docs/man_pages/project/testing/build-android.md#L38-L38: revise the--gradleArgsdescription.docs/man_pages/project/testing/debug-android.md#L42-L42: apply the same revised description.docs/man_pages/project/testing/run-android.md#L47-L47: apply the same revised description.🧰 Tools
🪛 LanguageTool
[style] ~38-~38: To form a complete sentence, be sure to include a subject.
Context: ... Passes additional arguments to gradle. Can be passed multiple times, and a single ...
(MISSING_IT_THERE)
[grammar] ~38-~38: Use a hyphen to join words.
Context: ...nd a single value may hold several space separated arguments. Use the
=form so...(QB_NEW_EN_HYPHEN)
📍 Affects 3 files
docs/man_pages/project/testing/build-android.md#L38-L38(this comment)docs/man_pages/project/testing/debug-android.md#L42-L42docs/man_pages/project/testing/run-android.md#L47-L47🤖 Prompt for AI Agents
Source: Linters/SAST tools