-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathandroid-plugin-build-service.ts
787 lines (693 loc) · 21.2 KB
/
android-plugin-build-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
import * as path from "path";
import {
MANIFEST_FILE_NAME,
INCLUDE_GRADLE_NAME,
ASSETS_DIR,
RESOURCES_DIR,
AndroidBuildDefaults,
PLUGIN_BUILD_DATA_FILENAME,
SCOPED_ANDROID_RUNTIME_NAME,
} from "../constants";
import { getShortPluginName, hook } from "../common/helpers";
import { Builder, parseString } from "xml2js";
import {
IRuntimeGradleVersions,
INodePackageManager,
IAndroidToolsInfo,
IWatchIgnoreListService,
} from "../declarations";
import { IPlatformsDataService } from "../definitions/platform";
import { IProjectDataService } from "../definitions/project";
import {
IAndroidPluginBuildService,
IPluginBuildOptions,
IBuildAndroidPluginData,
} from "../definitions/android-plugin-migrator";
import {
IFileSystem,
IChildProcess,
IHostInfo,
IErrors,
IHooksService,
IFsStats,
IStringDictionary,
} from "../common/declarations";
import { IFilesHashService } from "../definitions/files-hash-service";
import { IInjector } from "../common/definitions/yok";
import { injector } from "../common/yok";
import * as _ from "lodash";
export class AndroidPluginBuildService implements IAndroidPluginBuildService {
private get $platformsDataService(): IPlatformsDataService {
return this.$injector.resolve("platformsDataService");
}
constructor(
private $fs: IFileSystem,
private $childProcess: IChildProcess,
private $hostInfo: IHostInfo,
private $androidToolsInfo: IAndroidToolsInfo,
private $logger: ILogger,
private $packageManager: INodePackageManager,
private $projectDataService: IProjectDataService,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $filesHashService: IFilesHashService,
public $hooksService: IHooksService,
private $injector: IInjector,
private $watchIgnoreListService: IWatchIgnoreListService
) {}
private static MANIFEST_ROOT = {
$: {
"xmlns:android": "http://schemas.android.com/apk/res/android",
},
};
private getAndroidSourceDirectories(source: string): Array<string> {
const directories = [RESOURCES_DIR, "java", ASSETS_DIR, "jniLibs"];
const resultArr: Array<string> = [];
this.$fs.enumerateFilesInDirectorySync(source, (file, stat) => {
if (
stat.isDirectory() &&
_.some(directories, (element) => file.endsWith(element))
) {
resultArr.push(file);
return true;
}
});
return resultArr;
}
private getManifest(platformsDir: string): string {
const manifest = path.join(platformsDir, MANIFEST_FILE_NAME);
return this.$fs.exists(manifest) ? manifest : null;
}
private async updateManifestContent(
oldManifestContent: string,
defaultPackageName: string
): Promise<string> {
let xml: any = await this.getXml(oldManifestContent);
let packageName = defaultPackageName;
// if the manifest file is full-featured and declares settings inside the manifest scope
if (xml["manifest"]) {
if (xml["manifest"]["$"]["package"]) {
packageName = xml["manifest"]["$"]["package"];
}
// set the xml as the value to iterate over its properties
xml = xml["manifest"];
}
// if the manifest file doesn't have a <manifest> scope, only the first setting will be picked up
const newManifest: any = { manifest: {} };
for (const prop in xml) {
newManifest.manifest[prop] = xml[prop];
}
newManifest.manifest["$"]["package"] = packageName;
const xmlBuilder = new Builder();
const newManifestContent = xmlBuilder.buildObject(newManifest);
return newManifestContent;
}
private createManifestContent(packageName: string): string {
const newManifest: any = {
manifest: AndroidPluginBuildService.MANIFEST_ROOT,
};
newManifest.manifest["$"]["package"] = packageName;
const xmlBuilder: any = new Builder();
const newManifestContent = xmlBuilder.buildObject(newManifest);
return newManifestContent;
}
private async getXml(stringContent: string): Promise<any> {
const promise = new Promise<any>((resolve, reject) =>
parseString(stringContent, (err: any, result: any) => {
if (err) {
reject(err);
} else {
resolve(result);
}
})
);
return promise;
}
private getIncludeGradleCompileDependenciesScope(
includeGradleFileContent: string
): Array<string> {
const indexOfDependenciesScope = includeGradleFileContent.indexOf(
"dependencies"
);
const result: Array<string> = [];
if (indexOfDependenciesScope === -1) {
return result;
}
const indexOfRepositoriesScope = includeGradleFileContent.indexOf(
"repositories"
);
let repositoriesScope = "";
if (indexOfRepositoriesScope >= 0) {
repositoriesScope = this.getScope(
"repositories",
includeGradleFileContent
);
result.push(repositoriesScope);
}
const dependenciesScope = this.getScope(
"dependencies",
includeGradleFileContent
);
result.push(dependenciesScope);
return result;
}
private getScope(scopeName: string, content: string): string {
const indexOfScopeName = content.indexOf(scopeName);
const openingBracket = "{";
const closingBracket = "}";
let foundFirstBracket = false;
let openBrackets = 0;
let result = "";
let i = indexOfScopeName;
while (i !== -1 && i < content.length) {
const currCharacter = content[i];
if (currCharacter === openingBracket) {
if (openBrackets === 0) {
foundFirstBracket = true;
}
openBrackets++;
}
if (currCharacter === closingBracket) {
openBrackets--;
}
result += currCharacter;
if (openBrackets === 0 && foundFirstBracket) {
break;
}
i++;
}
return result;
}
/**
* Returns whether the build has completed or not
* @param {Object} options
* @param {string} options.pluginName - The name of the plugin. E.g. 'nativescript-barcodescanner'
* @param {string} options.platformsAndroidDirPath - The path to the 'plugin/src/platforms/android' directory.
* @param {string} options.aarOutputDir - The path where the aar should be copied after a successful build.
* @param {string} options.tempPluginDirPath - The path where the android plugin will be built.
*/
public async buildAar(options: IPluginBuildOptions): Promise<boolean> {
this.validateOptions(options);
const manifestFilePath = this.getManifest(options.platformsAndroidDirPath);
const androidSourceDirectories = this.getAndroidSourceDirectories(
options.platformsAndroidDirPath
);
const shortPluginName = getShortPluginName(options.pluginName);
const pluginTempDir = path.join(options.tempPluginDirPath, shortPluginName);
const pluginSourceFileHashesInfo = await this.getSourceFilesHashes(
options.platformsAndroidDirPath,
shortPluginName
);
const shouldBuildAar = await this.shouldBuildAar({
manifestFilePath,
androidSourceDirectories,
pluginTempDir,
pluginSourceDir: options.platformsAndroidDirPath,
shortPluginName,
fileHashesInfo: pluginSourceFileHashesInfo,
});
if (shouldBuildAar) {
this.cleanPluginDir(pluginTempDir);
const pluginTempMainSrcDir = path.join(pluginTempDir, "src", "main");
await this.updateManifest(
manifestFilePath,
pluginTempMainSrcDir,
shortPluginName
);
this.copySourceSetDirectories(
androidSourceDirectories,
pluginTempMainSrcDir
);
await this.setupGradle(
pluginTempDir,
options.platformsAndroidDirPath,
options.projectDir
);
await this.buildPlugin({
pluginDir: pluginTempDir,
pluginName: options.pluginName,
projectDir: options.projectDir,
});
this.$watchIgnoreListService.addFileToIgnoreList(
path.join(options.aarOutputDir, `${shortPluginName}.aar`)
);
this.copyAar(shortPluginName, pluginTempDir, options.aarOutputDir);
this.writePluginHashInfo(pluginSourceFileHashesInfo, pluginTempDir);
}
return shouldBuildAar;
}
private cleanPluginDir(pluginTempDir: string): void {
// In case plugin was already built in the current process, we need to clean the old sources as they may break the new build.
this.$fs.deleteDirectory(pluginTempDir);
this.$fs.ensureDirectoryExists(pluginTempDir);
}
private getSourceFilesHashes(
pluginTempPlatformsAndroidDir: string,
shortPluginName: string
): Promise<IStringDictionary> {
const pathToAar = path.join(
pluginTempPlatformsAndroidDir,
`${shortPluginName}.aar`
);
const pluginNativeDataFiles = this.$fs.enumerateFilesInDirectorySync(
pluginTempPlatformsAndroidDir,
(file: string, stat: IFsStats) => file !== pathToAar
);
return this.$filesHashService.generateHashes(pluginNativeDataFiles);
}
private writePluginHashInfo(
fileHashesInfo: IStringDictionary,
pluginTempDir: string
): void {
const buildDataFile = this.getPathToPluginBuildDataFile(pluginTempDir);
this.$fs.writeJson(buildDataFile, fileHashesInfo);
}
private async shouldBuildAar(opts: {
manifestFilePath: string;
androidSourceDirectories: string[];
pluginTempDir: string;
pluginSourceDir: string;
shortPluginName: string;
fileHashesInfo: IStringDictionary;
}): Promise<boolean> {
let shouldBuildAar =
!!opts.manifestFilePath || !!opts.androidSourceDirectories.length;
if (
shouldBuildAar &&
this.$fs.exists(opts.pluginTempDir) &&
this.$fs.exists(
path.join(opts.pluginSourceDir, `${opts.shortPluginName}.aar`)
)
) {
const buildDataFile = this.getPathToPluginBuildDataFile(
opts.pluginTempDir
);
if (this.$fs.exists(buildDataFile)) {
const oldHashes = this.$fs.readJson(buildDataFile);
shouldBuildAar = this.$filesHashService.hasChangesInShasums(
oldHashes,
opts.fileHashesInfo
);
}
}
return shouldBuildAar;
}
private getPathToPluginBuildDataFile(pluginDir: string): string {
return path.join(pluginDir, PLUGIN_BUILD_DATA_FILENAME);
}
private async updateManifest(
manifestFilePath: string,
pluginTempMainSrcDir: string,
shortPluginName: string
): Promise<void> {
let updatedManifestContent;
this.$fs.ensureDirectoryExists(pluginTempMainSrcDir);
const defaultPackageName = "org.nativescript." + shortPluginName;
if (manifestFilePath) {
let androidManifestContent;
try {
androidManifestContent = this.$fs.readText(manifestFilePath);
} catch (err) {
this.$errors.fail(
`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}. Error is: ${err.toString()}`
);
}
updatedManifestContent = await this.updateManifestContent(
androidManifestContent,
defaultPackageName
);
} else {
updatedManifestContent = this.createManifestContent(defaultPackageName);
}
const pathToTempAndroidManifest = path.join(
pluginTempMainSrcDir,
MANIFEST_FILE_NAME
);
try {
this.$fs.writeFile(pathToTempAndroidManifest, updatedManifestContent);
} catch (e) {
this.$errors.fail(
`Failed to write the updated AndroidManifest in the new location - ${pathToTempAndroidManifest}. Error is: ${e.toString()}`
);
}
}
private copySourceSetDirectories(
androidSourceSetDirectories: string[],
pluginTempMainSrcDir: string
): void {
for (const dir of androidSourceSetDirectories) {
const dirName = path.basename(dir);
const destination = path.join(pluginTempMainSrcDir, dirName);
this.$fs.ensureDirectoryExists(destination);
this.$fs.copyFile(path.join(dir, "*"), destination);
}
}
private async setupGradle(
pluginTempDir: string,
platformsAndroidDirPath: string,
projectDir: string
): Promise<void> {
const gradleTemplatePath = path.resolve(
path.join(__dirname, "../../vendor/gradle-plugin")
);
const allGradleTemplateFiles = path.join(gradleTemplatePath, "*");
const buildGradlePath = path.join(pluginTempDir, "build.gradle");
this.$fs.copyFile(allGradleTemplateFiles, pluginTempDir);
this.addCompileDependencies(platformsAndroidDirPath, buildGradlePath);
const runtimeGradleVersions = await this.getRuntimeGradleVersions(
projectDir
);
this.replaceGradleVersion(
pluginTempDir,
runtimeGradleVersions.gradleVersion
);
this.replaceGradleAndroidPluginVersion(
buildGradlePath,
runtimeGradleVersions.gradleAndroidPluginVersion
);
}
private async getRuntimeGradleVersions(
projectDir: string
): Promise<IRuntimeGradleVersions> {
let runtimeGradleVersions: IRuntimeGradleVersions = null;
if (projectDir) {
const projectData = this.$projectDataService.getProjectData(projectDir);
const platformData = this.$platformsDataService.getPlatformData(
this.$devicePlatformsConstants.Android,
projectData
);
const projectRuntimeVersion = platformData.platformProjectService.getFrameworkVersion(
projectData
);
runtimeGradleVersions = await this.getGradleVersions(
projectRuntimeVersion
);
this.$logger.trace(
`Got gradle versions ${JSON.stringify(
runtimeGradleVersions
)} from runtime v${projectRuntimeVersion}`
);
}
if (!runtimeGradleVersions) {
const latestRuntimeVersion = await this.getLatestRuntimeVersion();
runtimeGradleVersions = await this.getGradleVersions(
latestRuntimeVersion
);
this.$logger.trace(
`Got gradle versions ${JSON.stringify(
runtimeGradleVersions
)} from the latest runtime v${latestRuntimeVersion}`
);
}
return runtimeGradleVersions || {};
}
private async getLatestRuntimeVersion(): Promise<string> {
let runtimeVersion: string = null;
try {
const result = await this.$packageManager.view(
SCOPED_ANDROID_RUNTIME_NAME,
{
"dist-tags": true,
}
);
runtimeVersion = result.latest;
} catch (err) {
this.$logger.trace(
`Error while getting latest android runtime version from view command: ${err}`
);
const registryData = await this.$packageManager.getRegistryPackageData(
SCOPED_ANDROID_RUNTIME_NAME
);
runtimeVersion = registryData["dist-tags"].latest;
}
return runtimeVersion;
}
private async getGradleVersions(
runtimeVersion: string
): Promise<IRuntimeGradleVersions> {
let runtimeGradleVersions: {
versions: { gradle: string; gradleAndroid: string };
} = null;
try {
let output = await this.$packageManager.view(
`${SCOPED_ANDROID_RUNTIME_NAME}@${runtimeVersion}`,
{ version_info: true }
);
if (!output) {
/**
* fallback to the old 'gradle' key in package.json
*
* format:
*
* gradle: { version: '6.4', android: '3.6.4' }
*
*/
output = await this.$packageManager.view(
`${SCOPED_ANDROID_RUNTIME_NAME}@${runtimeVersion}`,
{ gradle: true }
);
const { version, android } = output;
// covert output to the new format...
output = {
gradle: version,
gradleAndroid: android,
};
}
runtimeGradleVersions = { versions: output };
} catch (err) {
this.$logger.trace(
`Error while getting gradle data for android runtime from view command: ${err}`
);
const registryData = await this.$packageManager.getRegistryPackageData(
SCOPED_ANDROID_RUNTIME_NAME
);
runtimeGradleVersions = registryData.versions[runtimeVersion];
}
const result = this.getGradleVersionsCore(runtimeGradleVersions);
return result;
}
private getGradleVersionsCore(packageData: {
versions: { gradle: string; gradleAndroid: string };
}): IRuntimeGradleVersions {
const packageJsonGradle = packageData && packageData.versions;
let runtimeVersions: IRuntimeGradleVersions = null;
if (
packageJsonGradle &&
(packageJsonGradle.gradle || packageJsonGradle.gradleAndroid)
) {
runtimeVersions = {};
runtimeVersions.gradleVersion = packageJsonGradle.gradle;
runtimeVersions.gradleAndroidPluginVersion =
packageJsonGradle.gradleAndroid;
}
return runtimeVersions;
}
private replaceGradleVersion(pluginTempDir: string, version: string): void {
const gradleVersion = version || AndroidBuildDefaults.GradleVersion;
const gradleVersionPlaceholder = "{{runtimeGradleVersion}}";
const gradleWrapperPropertiesPath = path.join(
pluginTempDir,
"gradle",
"wrapper",
"gradle-wrapper.properties"
);
this.replaceFileContent(
gradleWrapperPropertiesPath,
gradleVersionPlaceholder,
gradleVersion
);
}
private replaceGradleAndroidPluginVersion(
buildGradlePath: string,
version: string
): void {
const gradleAndroidPluginVersionPlaceholder =
"{{runtimeAndroidPluginVersion}}";
const gradleAndroidPluginVersion =
version || AndroidBuildDefaults.GradleAndroidPluginVersion;
this.replaceFileContent(
buildGradlePath,
gradleAndroidPluginVersionPlaceholder,
gradleAndroidPluginVersion
);
}
private replaceFileContent(
filePath: string,
content: string,
replacement: string
) {
const fileContent = this.$fs.readText(filePath);
const contentRegex = new RegExp(content, "g");
const replacedFileContent = fileContent.replace(contentRegex, replacement);
this.$fs.writeFile(filePath, replacedFileContent);
}
private addCompileDependencies(
platformsAndroidDirPath: string,
buildGradlePath: string
): void {
const includeGradlePath = path.join(
platformsAndroidDirPath,
INCLUDE_GRADLE_NAME
);
if (this.$fs.exists(includeGradlePath)) {
const includeGradleContent = this.$fs.readText(includeGradlePath);
const compileDependencies = this.getIncludeGradleCompileDependenciesScope(
includeGradleContent
);
if (compileDependencies.length) {
this.$fs.appendFile(
buildGradlePath,
"\n" + compileDependencies.join("\n")
);
}
}
}
private copyAar(
shortPluginName: string,
pluginTempDir: string,
aarOutputDir: string
): void {
const finalAarName = `${shortPluginName}-release.aar`;
const pathToBuiltAar = path.join(
pluginTempDir,
"build",
"outputs",
"aar",
finalAarName
);
if (this.$fs.exists(pathToBuiltAar)) {
try {
if (aarOutputDir) {
this.$fs.copyFile(
pathToBuiltAar,
path.join(aarOutputDir, `${shortPluginName}.aar`)
);
}
} catch (e) {
this.$errors.fail(
`Failed to copy built aar to destination. ${e.message}`
);
}
} else {
this.$errors.fail(`No built aar found at ${pathToBuiltAar}`);
}
}
/**
* @param {Object} options
* @param {string} options.platformsAndroidDirPath - The path to the 'plugin/src/platforms/android' directory.
*/
public migrateIncludeGradle(options: IPluginBuildOptions): boolean {
this.validatePlatformsAndroidDirPathOption(options);
const includeGradleFilePath = path.join(
options.platformsAndroidDirPath,
INCLUDE_GRADLE_NAME
);
if (this.$fs.exists(includeGradleFilePath)) {
let includeGradleFileContent: string;
try {
includeGradleFileContent = this.$fs
.readFile(includeGradleFilePath)
.toString();
} catch (err) {
this.$errors.fail(
`Failed to fs.readFileSync the include.gradle file located at ${includeGradleFilePath}. Error is: ${err.toString()}`
);
}
const productFlavorsScope = this.getScope(
"productFlavors",
includeGradleFileContent
);
if (productFlavorsScope) {
try {
const newIncludeGradleFileContent = includeGradleFileContent.replace(
productFlavorsScope,
""
);
this.$fs.writeFile(
includeGradleFilePath,
newIncludeGradleFileContent
);
return true;
} catch (e) {
this.$errors.fail(
`Failed to write the updated include.gradle ` +
`in - ${includeGradleFilePath}. Error is: ${e.toString()}`
);
}
}
}
return false;
}
@hook("buildAndroidPlugin")
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 = this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew";
const localArgs = [
"-p",
pluginBuildSettings.pluginDir,
"assembleRelease",
`-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`,
`-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`,
];
if (this.$logger.getLevel() === "INFO") {
localArgs.push("--quiet");
}
try {
await this.$childProcess.spawnFromEvent(gradlew, localArgs, "close", {
cwd: pluginBuildSettings.pluginDir,
stdio: "inherit",
});
} catch (err) {
this.$errors.fail(
`Failed to build plugin ${pluginBuildSettings.pluginName} : \n${err}`
);
}
}
private validateOptions(options: IPluginBuildOptions): void {
if (!options) {
this.$errors.fail(
"Android plugin cannot be built without passing an 'options' object."
);
}
if (!options.pluginName) {
this.$logger.info("No plugin name provided, defaulting to 'myPlugin'.");
}
if (!options.aarOutputDir) {
this.$logger.info(
"No aarOutputDir provided, defaulting to the build outputs directory of the plugin"
);
}
if (!options.tempPluginDirPath) {
this.$errors.fail(
"Android plugin cannot be built without passing the path to a directory where the temporary project should be built."
);
}
this.validatePlatformsAndroidDirPathOption(options);
}
private validatePlatformsAndroidDirPathOption(
options: IPluginBuildOptions
): void {
if (!options) {
this.$errors.fail(
"Android plugin cannot be built without passing an 'options' object."
);
}
if (!options.platformsAndroidDirPath) {
this.$errors.fail(
"Android plugin cannot be built without passing the path to the platforms/android dir."
);
}
}
}
injector.register("androidPluginBuildService", AndroidPluginBuildService);