Skip to content

Commit

Permalink
feat: gradle 8, kotlin 2 & updated bundletool (#5799)
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz authored Jul 1, 2024
1 parent 32f8fc5 commit 29acc76
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 160 deletions.
41 changes: 25 additions & 16 deletions lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Builder, parseString } from "xml2js";
import {
IRuntimeGradleVersions,
INodePackageManager,
IAndroidToolsInfo,
IWatchIgnoreListService,
} from "../declarations";
import { IPlatformsDataService } from "../definitions/platform";
Expand Down Expand Up @@ -47,7 +46,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
private $fs: IFileSystem,
private $childProcess: IChildProcess,
private $hostInfo: IHostInfo,
private $androidToolsInfo: IAndroidToolsInfo,
private $logger: ILogger,
private $packageManager: INodePackageManager,
private $projectData: IProjectData,
Expand Down Expand Up @@ -423,6 +421,31 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
);
this.replaceFileContent(buildGradlePath, "{{pluginName}}", pluginName);
this.replaceFileContent(settingsGradlePath, "{{pluginName}}", pluginName);

// gets the package from the AndroidManifest to use as the namespace or fallback to the `org.nativescript.${shortPluginName}`
const shortPluginName = getShortPluginName(pluginName);

const manifestPath = path.join(
pluginTempDir,
"src",
"main",
"AndroidManifest.xml"
);
const manifestContent = this.$fs.readText(manifestPath);

let packageName = `org.nativescript.${shortPluginName}`;
const xml = await this.getXml(manifestContent);
if (xml["manifest"]) {
if (xml["manifest"]["$"]["package"]) {
packageName = xml["manifest"]["$"]["package"];
}
}

this.replaceFileContent(
buildGradlePath,
"{{pluginNamespace}}",
packageName
);
}

private async getRuntimeGradleVersions(
Expand Down Expand Up @@ -777,18 +800,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
private async buildPlugin(
pluginBuildSettings: IBuildAndroidPluginData
): Promise<void> {
if (!pluginBuildSettings.androidToolsInfo) {
this.$androidToolsInfo.validateInfo({
showWarningsAsErrors: true,
validateTargetSdk: true,
projectDir: pluginBuildSettings.projectDir,
});
pluginBuildSettings.androidToolsInfo =
this.$androidToolsInfo.getToolsInfo({
projectDir: pluginBuildSettings.projectDir,
});
}

const gradlew =
pluginBuildSettings.gradlePath ??
(this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew");
Expand All @@ -798,8 +809,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
pluginBuildSettings.pluginDir,
"assembleRelease",
`-PtempBuild=true`,
`-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`,
`-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`,
`-PappPath=${this.$projectData.getAppDirectoryPath()}`,
`-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`,
];
Expand Down
10 changes: 0 additions & 10 deletions lib/services/android/gradle-build-args-service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as path from "path";
import { Configurations } from "../../common/constants";
import { IGradleBuildArgsService } from "../../definitions/gradle";
import { IAndroidToolsInfo } from "../../declarations";
import { IAndroidBuildData } from "../../definitions/build";
import { IHooksService, IAnalyticsService } from "../../common/declarations";
import { injector } from "../../common/yok";
import { IProjectData } from "../../definitions/project";

export class GradleBuildArgsService implements IGradleBuildArgsService {
constructor(
private $androidToolsInfo: IAndroidToolsInfo,
private $hooksService: IHooksService,
private $analyticsService: IAnalyticsService,
private $staticConfig: Config.IStaticConfig,
Expand Down Expand Up @@ -49,18 +47,10 @@ export class GradleBuildArgsService implements IGradleBuildArgsService {
private getBaseTaskArgs(buildData: IAndroidBuildData): string[] {
const args = this.getBuildLoggingArgs();

const toolsInfo = this.$androidToolsInfo.getToolsInfo({
projectDir: buildData.projectDir,
});

// ensure we initialize project data
this.$projectData.initializeProjectData(buildData.projectDir);

args.push(
`-PcompileSdk=android-${toolsInfo.compileSdkVersion}`,
`-PtargetSdk=${toolsInfo.targetSdkVersion}`,
`-PbuildToolsVersion=${toolsInfo.buildToolsVersion}`,
`-PgenerateTypings=${toolsInfo.generateTypings}`,
`-PappPath=${this.$projectData.getAppDirectoryPath()}`,
`-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`
);
Expand Down
Loading

0 comments on commit 29acc76

Please sign in to comment.