@@ -16,6 +16,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
16
16
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.5.0" ;
17
17
private static MIN_RUNTIME_VERSION_WITHOUT_DEPS = "4.2.0-2018-06-29-02" ;
18
18
19
+ private isAndroidStudioTemplate : boolean ;
20
+
19
21
constructor ( private $androidToolsInfo : IAndroidToolsInfo ,
20
22
private $childProcess : IChildProcess ,
21
23
private $errors : IErrors ,
@@ -32,6 +34,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
32
34
private $androidResourcesMigrationService : IAndroidResourcesMigrationService ,
33
35
private $filesHashService : IFilesHashService ) {
34
36
super ( $fs , $projectDataService ) ;
37
+ this . isAndroidStudioTemplate = false ;
35
38
}
36
39
37
40
private _platformData : IPlatformData = null ;
@@ -41,10 +44,27 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
41
44
}
42
45
if ( projectData && projectData . platformsDir ) {
43
46
const projectRoot = path . join ( projectData . platformsDir , AndroidProjectService . ANDROID_PLATFORM_NAME ) ;
47
+ if ( this . isAndroidStudioCompatibleTemplate ( projectData ) ) {
48
+ this . isAndroidStudioTemplate = true ;
49
+ }
50
+
51
+ const appDestinationDirectoryArr = [ projectRoot ] ;
52
+ if ( this . isAndroidStudioTemplate ) {
53
+ appDestinationDirectoryArr . push ( constants . APP_FOLDER_NAME ) ;
54
+ }
55
+ appDestinationDirectoryArr . push ( constants . SRC_DIR , constants . MAIN_DIR , constants . ASSETS_DIR ) ;
44
56
45
- const appDestinationDirectoryArr = [ projectRoot , constants . APP_FOLDER_NAME , constants . SRC_DIR , constants . MAIN_DIR , constants . ASSETS_DIR ] ;
46
- const configurationsDirectoryArr = [ projectRoot , constants . APP_FOLDER_NAME , constants . SRC_DIR , constants . MAIN_DIR , constants . MANIFEST_FILE_NAME ] ;
47
- const deviceBuildOutputArr = [ projectRoot , constants . APP_FOLDER_NAME , constants . BUILD_DIR , constants . OUTPUTS_DIR , constants . APK_DIR ] ;
57
+ const configurationsDirectoryArr = [ projectRoot ] ;
58
+ if ( this . isAndroidStudioTemplate ) {
59
+ configurationsDirectoryArr . push ( constants . APP_FOLDER_NAME ) ;
60
+ }
61
+ configurationsDirectoryArr . push ( constants . SRC_DIR , constants . MAIN_DIR , constants . MANIFEST_FILE_NAME ) ;
62
+
63
+ const deviceBuildOutputArr = [ projectRoot ] ;
64
+ if ( this . isAndroidStudioTemplate ) {
65
+ deviceBuildOutputArr . push ( constants . APP_FOLDER_NAME ) ;
66
+ }
67
+ deviceBuildOutputArr . push ( constants . BUILD_DIR , constants . OUTPUTS_DIR , constants . APK_DIR ) ;
48
68
49
69
const packageName = this . getProjectNameFromId ( projectData ) ;
50
70
@@ -140,7 +160,30 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
140
160
const targetSdkVersion = androidToolsInfo && androidToolsInfo . targetSdkVersion ;
141
161
this . $logger . trace ( `Using Android SDK '${ targetSdkVersion } '.` ) ;
142
162
143
- this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "*" , "-R" ) ;
163
+ this . isAndroidStudioTemplate = this . isAndroidStudioCompatibleTemplate ( projectData , frameworkVersion ) ;
164
+ if ( this . isAndroidStudioTemplate ) {
165
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "*" , "-R" ) ;
166
+ } else {
167
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "libs" , "-R" ) ;
168
+
169
+ if ( config . pathToTemplate ) {
170
+ const mainPath = path . join ( this . getPlatformData ( projectData ) . projectRoot , constants . SRC_DIR , constants . MAIN_DIR ) ;
171
+ this . $fs . createDirectory ( mainPath ) ;
172
+ shell . cp ( "-R" , path . join ( path . resolve ( config . pathToTemplate ) , "*" ) , mainPath ) ;
173
+ } else {
174
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , constants . SRC_DIR , "-R" ) ;
175
+ }
176
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "build.gradle settings.gradle build-tools" , "-Rf" ) ;
177
+
178
+ try {
179
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "gradle.properties" , "-Rf" ) ;
180
+ } catch ( e ) {
181
+ this . $logger . warn ( `\n${ e } \nIt's possible, the final .apk file will contain all architectures instead of the ones described in the abiFilters!\nYou can fix this by using the latest android platform.` ) ;
182
+ }
183
+
184
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "gradle" , "-R" ) ;
185
+ this . copy ( this . getPlatformData ( projectData ) . projectRoot , frameworkDir , "gradlew gradlew.bat" , "-f" ) ;
186
+ }
144
187
145
188
this . cleanResValues ( targetSdkVersion , projectData ) ;
146
189
@@ -702,6 +745,24 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
702
745
}
703
746
}
704
747
748
+ private isAndroidStudioCompatibleTemplate ( projectData : IProjectData , frameworkVersion ?: string ) : boolean {
749
+ const currentPlatformData : IDictionary < any > = this . $projectDataService . getNSValue ( projectData . projectDir , constants . TNS_ANDROID_RUNTIME_NAME ) ;
750
+ const platformVersion = ( currentPlatformData && currentPlatformData [ constants . VERSION_STRING ] ) || frameworkVersion ;
751
+
752
+ if ( ! platformVersion ) {
753
+ return true ;
754
+ }
755
+
756
+ if ( ! semver . valid ( platformVersion ) ) {
757
+ return true ;
758
+ }
759
+
760
+ const androidStudioCompatibleTemplate = "3.4.0" ;
761
+ const normalizedPlatformVersion = `${ semver . major ( platformVersion ) } .${ semver . minor ( platformVersion ) } .0` ;
762
+
763
+ return semver . gte ( normalizedPlatformVersion , androidStudioCompatibleTemplate ) ;
764
+ }
765
+
705
766
private runtimeVersionIsGreaterThanOrEquals ( projectData : IProjectData , versionString : string ) : boolean {
706
767
const platformVersion = this . getCurrentPlatformVersion ( this . getPlatformData ( projectData ) , projectData ) ;
707
768
@@ -714,12 +775,20 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
714
775
}
715
776
716
777
private getLegacyAppResourcesDestinationDirPath ( projectData : IProjectData ) : string {
717
- const resourcePath : string [ ] = [ constants . APP_FOLDER_NAME , constants . SRC_DIR , constants . MAIN_DIR , constants . RESOURCES_DIR ] ;
778
+ const resourcePath : string [ ] = [ constants . SRC_DIR , constants . MAIN_DIR , constants . RESOURCES_DIR ] ;
779
+ if ( this . isAndroidStudioTemplate ) {
780
+ resourcePath . unshift ( constants . APP_FOLDER_NAME ) ;
781
+ }
782
+
718
783
return path . join ( this . getPlatformData ( projectData ) . projectRoot , ...resourcePath ) ;
719
784
}
720
785
721
786
private getUpdatedAppResourcesDestinationDirPath ( projectData : IProjectData ) : string {
722
- const resourcePath : string [ ] = [ constants . APP_FOLDER_NAME , constants . SRC_DIR ] ;
787
+ const resourcePath : string [ ] = [ constants . SRC_DIR ] ;
788
+ if ( this . isAndroidStudioTemplate ) {
789
+ resourcePath . unshift ( constants . APP_FOLDER_NAME ) ;
790
+ }
791
+
723
792
return path . join ( this . getPlatformData ( projectData ) . projectRoot , ...resourcePath ) ;
724
793
}
725
794
0 commit comments