@@ -4,7 +4,7 @@ import * as constants from "../constants";
4
4
import * as semver from "semver" ;
5
5
import * as projectServiceBaseLib from "./platform-project-service-base" ;
6
6
import { DeviceAndroidDebugBridge } from "../common/mobile/android/device-android-debug-bridge" ;
7
- import { attachAwaitDetach , isRecommendedAarFile } from "../common/helpers" ;
7
+ import { attachAwaitDetach } from "../common/helpers" ;
8
8
import { Configurations , LiveSyncPaths } from "../common/constants" ;
9
9
import { SpawnOptions } from "child_process" ;
10
10
import { performanceLog } from ".././common/decorators" ;
@@ -14,7 +14,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
14
14
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService . VALUES_DIRNAME + "-v" ;
15
15
private static ANDROID_PLATFORM_NAME = "android" ;
16
16
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.5.0" ;
17
- private static MIN_RUNTIME_VERSION_WITHOUT_DEPS = "4.2.0-2018-06-29-02" ;
18
17
19
18
private isAndroidStudioTemplate : boolean ;
20
19
@@ -26,9 +25,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
26
25
private $logger : ILogger ,
27
26
$projectDataService : IProjectDataService ,
28
27
private $injector : IInjector ,
29
- private $pluginVariablesService : IPluginVariablesService ,
30
28
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
31
- private $packageManager : INodePackageManager ,
32
29
private $androidPluginBuildService : IAndroidPluginBuildService ,
33
30
private $platformEnvironmentRequirements : IPlatformEnvironmentRequirements ,
34
31
private $androidResourcesMigrationService : IAndroidResourcesMigrationService ,
@@ -186,52 +183,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
186
183
}
187
184
188
185
this . cleanResValues ( targetSdkVersion , projectData ) ;
189
-
190
- if ( semver . lt ( frameworkVersion , AndroidProjectService . MIN_RUNTIME_VERSION_WITHOUT_DEPS ) ) {
191
- await this . installRuntimeDeps ( projectData , config ) ;
192
- }
193
- }
194
-
195
- private async installRuntimeDeps ( projectData : IProjectData , config : ICreateProjectOptions ) {
196
- const requiredDevDependencies = [
197
- { name : "babel-traverse" , version : "^6.4.5" } ,
198
- { name : "babel-types" , version : "^6.4.5" } ,
199
- { name : "babylon" , version : "^6.4.5" } ,
200
- { name : "lazy" , version : "^1.0.11" }
201
- ] ;
202
-
203
- const npmConfig : INodePackageManagerInstallOptions = {
204
- save : true ,
205
- "save-dev" : true ,
206
- "save-exact" : true ,
207
- silent : true ,
208
- disableNpmInstall : false ,
209
- frameworkPath : config . frameworkPath ,
210
- ignoreScripts : config . ignoreScripts
211
- } ;
212
-
213
- const projectPackageJson : any = this . $fs . readJson ( projectData . projectFilePath ) ;
214
-
215
- for ( const dependency of requiredDevDependencies ) {
216
- let dependencyVersionInProject = ( projectPackageJson . dependencies && projectPackageJson . dependencies [ dependency . name ] ) ||
217
- ( projectPackageJson . devDependencies && projectPackageJson . devDependencies [ dependency . name ] ) ;
218
-
219
- if ( ! dependencyVersionInProject ) {
220
- await this . $packageManager . install ( `${ dependency . name } @${ dependency . version } ` , projectData . projectDir , npmConfig ) ;
221
- } else {
222
- const cleanedVersion = semver . clean ( dependencyVersionInProject ) ;
223
-
224
- // The plugin version is not valid. Check node_modules for the valid version.
225
- if ( ! cleanedVersion ) {
226
- const pathToPluginPackageJson = path . join ( projectData . projectDir , constants . NODE_MODULES_FOLDER_NAME , dependency . name , constants . PACKAGE_JSON_FILE_NAME ) ;
227
- dependencyVersionInProject = this . $fs . exists ( pathToPluginPackageJson ) && this . $fs . readJson ( pathToPluginPackageJson ) . version ;
228
- }
229
-
230
- if ( ! semver . satisfies ( dependencyVersionInProject || cleanedVersion , dependency . version ) ) {
231
- this . $errors . failWithoutHelp ( `Your project have installed ${ dependency . name } version ${ cleanedVersion } but Android platform requires version ${ dependency . version } .` ) ;
232
- }
233
- }
234
- }
235
186
}
236
187
237
188
private cleanResValues ( targetSdkVersion : number , projectData : IProjectData ) : void {
@@ -442,166 +393,37 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
442
393
}
443
394
444
395
public async preparePluginNativeCode ( pluginData : IPluginData , projectData : IProjectData ) : Promise < void > {
445
- if ( ! this . runtimeVersionIsGreaterThanOrEquals ( projectData , "3.3.0" ) ) {
446
- const pluginPlatformsFolderPath = this . getPluginPlatformsFolderPath ( pluginData , AndroidProjectService . ANDROID_PLATFORM_NAME ) ;
447
- await this . processResourcesFromPlugin ( pluginData , pluginPlatformsFolderPath , projectData ) ;
448
- } else if ( this . runtimeVersionIsGreaterThanOrEquals ( projectData , "4.0.0" ) ) {
449
- // build Android plugins which contain AndroidManifest.xml and/or resources
450
- const pluginPlatformsFolderPath = this . getPluginPlatformsFolderPath ( pluginData , AndroidProjectService . ANDROID_PLATFORM_NAME ) ;
451
- if ( this . $fs . exists ( pluginPlatformsFolderPath ) ) {
452
- const options : IPluginBuildOptions = {
453
- projectDir : projectData . projectDir ,
454
- pluginName : pluginData . name ,
455
- platformsAndroidDirPath : pluginPlatformsFolderPath ,
456
- aarOutputDir : pluginPlatformsFolderPath ,
457
- tempPluginDirPath : path . join ( projectData . platformsDir , "tempPlugin" )
458
- } ;
396
+ // build Android plugins which contain AndroidManifest.xml and/or resources
397
+ const pluginPlatformsFolderPath = this . getPluginPlatformsFolderPath ( pluginData , AndroidProjectService . ANDROID_PLATFORM_NAME ) ;
398
+ if ( this . $fs . exists ( pluginPlatformsFolderPath ) ) {
399
+ const options : IPluginBuildOptions = {
400
+ projectDir : projectData . projectDir ,
401
+ pluginName : pluginData . name ,
402
+ platformsAndroidDirPath : pluginPlatformsFolderPath ,
403
+ aarOutputDir : pluginPlatformsFolderPath ,
404
+ tempPluginDirPath : path . join ( projectData . platformsDir , "tempPlugin" )
405
+ } ;
459
406
460
- await this . prebuildNativePlugin ( options ) ;
407
+ if ( await this . $androidPluginBuildService . buildAar ( options ) ) {
408
+ this . $logger . info ( `Built aar for ${ options . pluginName } ` ) ;
461
409
}
462
- }
463
-
464
- // Do nothing, the Android Gradle script will configure itself based on the input dependencies.json
465
- }
466
-
467
- public async checkIfPluginsNeedBuild ( projectData : IProjectData ) : Promise < Array < { platformsAndroidDirPath : string , pluginName : string } > > {
468
- const detectedPlugins : Array < { platformsAndroidDirPath : string , pluginName : string } > = [ ] ;
469
-
470
- const platformsAndroid = path . join ( constants . PLATFORMS_DIR_NAME , "android" ) ;
471
- const pathToPlatformsAndroid = path . join ( projectData . projectDir , platformsAndroid ) ;
472
- const dependenciesJson = await this . $fs . readJson ( path . join ( pathToPlatformsAndroid , constants . DEPENDENCIES_JSON_NAME ) ) ;
473
- const productionDependencies = dependenciesJson . map ( ( item : any ) => {
474
- return path . resolve ( pathToPlatformsAndroid , item . directory ) ;
475
- } ) ;
476
410
477
- for ( const dependency of productionDependencies ) {
478
- const jsonContent = this . $fs . readJson ( path . join ( dependency , constants . PACKAGE_JSON_FILE_NAME ) ) ;
479
- const isPlugin = ! ! jsonContent . nativescript ;
480
- const pluginName = jsonContent . name ;
481
- if ( isPlugin ) {
482
- const platformsAndroidDirPath = path . join ( dependency , platformsAndroid ) ;
483
- if ( this . $fs . exists ( platformsAndroidDirPath ) ) {
484
- let hasGeneratedAar = false ;
485
- let generatedAarPath = "" ;
486
- const nativeFiles = this . $fs . enumerateFilesInDirectorySync ( platformsAndroidDirPath ) . filter ( ( item ) => {
487
- if ( isRecommendedAarFile ( item , pluginName ) ) {
488
- generatedAarPath = item ;
489
- hasGeneratedAar = true ;
490
- }
491
- return this . isAllowedFile ( item ) ;
492
- } ) ;
493
-
494
- if ( hasGeneratedAar ) {
495
- const aarStat = this . $fs . getFsStats ( generatedAarPath ) ;
496
- nativeFiles . forEach ( ( item ) => {
497
- const currentItemStat = this . $fs . getFsStats ( item ) ;
498
- if ( currentItemStat . mtime > aarStat . mtime ) {
499
- detectedPlugins . push ( {
500
- platformsAndroidDirPath,
501
- pluginName
502
- } ) ;
503
- }
504
- } ) ;
505
- } else if ( nativeFiles . length > 0 ) {
506
- detectedPlugins . push ( {
507
- platformsAndroidDirPath,
508
- pluginName
509
- } ) ;
510
- }
511
- }
512
- }
411
+ this . $androidPluginBuildService . migrateIncludeGradle ( options ) ;
513
412
}
514
- return detectedPlugins ;
515
- }
516
-
517
- private isAllowedFile ( item : string ) : boolean {
518
- return item . endsWith ( constants . MANIFEST_FILE_NAME ) || item . endsWith ( constants . RESOURCES_DIR ) ;
519
- }
520
-
521
- public async prebuildNativePlugin ( options : IPluginBuildOptions ) : Promise < void > {
522
- if ( await this . $androidPluginBuildService . buildAar ( options ) ) {
523
- this . $logger . info ( `Built aar for ${ options . pluginName } ` ) ;
524
- }
525
-
526
- this . $androidPluginBuildService . migrateIncludeGradle ( options ) ;
527
413
}
528
414
529
415
public async processConfigurationFilesFromAppResources ( ) : Promise < void > {
530
416
return ;
531
417
}
532
418
533
- private async processResourcesFromPlugin ( pluginData : IPluginData , pluginPlatformsFolderPath : string , projectData : IProjectData ) : Promise < void > {
534
- const configurationsDirectoryPath = path . join ( this . getPlatformData ( projectData ) . projectRoot , "configurations" ) ;
535
- this . $fs . ensureDirectoryExists ( configurationsDirectoryPath ) ;
536
-
537
- const pluginConfigurationDirectoryPath = path . join ( configurationsDirectoryPath , pluginData . name ) ;
538
- if ( this . $fs . exists ( pluginPlatformsFolderPath ) ) {
539
- this . $fs . ensureDirectoryExists ( pluginConfigurationDirectoryPath ) ;
540
-
541
- const isScoped = pluginData . name . indexOf ( "@" ) === 0 ;
542
- const flattenedDependencyName = isScoped ? pluginData . name . replace ( "/" , "_" ) : pluginData . name ;
543
-
544
- // Copy all resources from plugin
545
- const resourcesDestinationDirectoryPath = path . join ( this . getPlatformData ( projectData ) . projectRoot , constants . SRC_DIR , flattenedDependencyName ) ;
546
- this . $fs . ensureDirectoryExists ( resourcesDestinationDirectoryPath ) ;
547
- shell . cp ( "-Rf" , path . join ( pluginPlatformsFolderPath , "*" ) , resourcesDestinationDirectoryPath ) ;
548
-
549
- const filesForInterpolation = this . $fs . enumerateFilesInDirectorySync ( resourcesDestinationDirectoryPath , file => this . $fs . getFsStats ( file ) . isDirectory ( ) || path . extname ( file ) === constants . XML_FILE_EXTENSION ) || [ ] ;
550
- for ( const file of filesForInterpolation ) {
551
- this . $logger . trace ( `Interpolate data for plugin file: ${ file } ` ) ;
552
- await this . $pluginVariablesService . interpolate ( pluginData , file , projectData . projectDir , projectData . projectIdentifiers . android ) ;
553
- }
554
- }
555
-
556
- // Copy include.gradle file
557
- const includeGradleFilePath = path . join ( pluginPlatformsFolderPath , constants . INCLUDE_GRADLE_NAME ) ;
558
- if ( this . $fs . exists ( includeGradleFilePath ) ) {
559
- shell . cp ( "-f" , includeGradleFilePath , pluginConfigurationDirectoryPath ) ;
560
- }
561
- }
562
-
563
419
public async removePluginNativeCode ( pluginData : IPluginData , projectData : IProjectData ) : Promise < void > {
564
- try {
565
- if ( ! this . runtimeVersionIsGreaterThanOrEquals ( projectData , "3.3.0" ) ) {
566
- const pluginConfigDir = path . join ( this . getPlatformData ( projectData ) . projectRoot , "configurations" , pluginData . name ) ;
567
- if ( this . $fs . exists ( pluginConfigDir ) ) {
568
- await this . cleanProject ( this . getPlatformData ( projectData ) . projectRoot , projectData ) ;
569
- }
570
- }
571
- } catch ( e ) {
572
- if ( e . code === "ENOENT" ) {
573
- this . $logger . debug ( "No native code jars found: " + e . message ) ;
574
- } else {
575
- throw e ;
576
- }
577
- }
420
+ // not implemented
578
421
}
579
422
580
423
public async beforePrepareAllPlugins ( projectData : IProjectData , dependencies ?: IDependencyData [ ] ) : Promise < void > {
581
- const shouldUseNewRoutine = this . runtimeVersionIsGreaterThanOrEquals ( projectData , "3.3.0" ) ;
582
-
583
424
if ( dependencies ) {
584
425
dependencies = this . filterUniqueDependencies ( dependencies ) ;
585
- if ( shouldUseNewRoutine ) {
586
- this . provideDependenciesJson ( projectData , dependencies ) ;
587
- } else {
588
- const platformDir = path . join ( projectData . platformsDir , AndroidProjectService . ANDROID_PLATFORM_NAME ) ;
589
- const buildDir = path . join ( platformDir , "build-tools" ) ;
590
- const checkV8dependants = path . join ( buildDir , "check-v8-dependants.js" ) ;
591
- if ( this . $fs . exists ( checkV8dependants ) ) {
592
- const stringifiedDependencies = JSON . stringify ( dependencies ) ;
593
- try {
594
- await this . spawn ( 'node' , [ checkV8dependants , stringifiedDependencies , projectData . platformsDir ] , { stdio : "inherit" } ) ;
595
- } catch ( e ) {
596
- this . $logger . info ( "Checking for dependants on v8 public API failed. This is likely caused because of cyclic production dependencies. Error code: " + e . code + "\nMore information: https://github.com/NativeScript/nativescript-cli/issues/2561" ) ;
597
- }
598
- }
599
- }
600
- }
601
-
602
- if ( ! shouldUseNewRoutine ) {
603
- const projectRoot = this . getPlatformData ( projectData ) . projectRoot ;
604
- await this . cleanProject ( projectRoot , projectData ) ;
426
+ this . provideDependenciesJson ( projectData , dependencies ) ;
605
427
}
606
428
}
607
429
@@ -763,17 +585,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
763
585
return semver . gte ( normalizedPlatformVersion , androidStudioCompatibleTemplate ) ;
764
586
}
765
587
766
- private runtimeVersionIsGreaterThanOrEquals ( projectData : IProjectData , versionString : string ) : boolean {
767
- const platformVersion = this . getCurrentPlatformVersion ( this . getPlatformData ( projectData ) , projectData ) ;
768
-
769
- if ( platformVersion === constants . PackageVersion . NEXT ) {
770
- return true ;
771
- }
772
-
773
- const normalizedPlatformVersion = `${ semver . major ( platformVersion ) } .${ semver . minor ( platformVersion ) } .0` ;
774
- return semver . gte ( normalizedPlatformVersion , versionString ) ;
775
- }
776
-
777
588
private getLegacyAppResourcesDestinationDirPath ( projectData : IProjectData ) : string {
778
589
const resourcePath : string [ ] = [ constants . SRC_DIR , constants . MAIN_DIR , constants . RESOURCES_DIR ] ;
779
590
if ( this . isAndroidStudioTemplate ) {
0 commit comments