@@ -16,6 +16,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
1616 private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.5.0" ;
1717 private static MIN_RUNTIME_VERSION_WITHOUT_DEPS = "4.2.0-2018-06-29-02" ;
1818
19+ private isAndroidStudioTemplate : boolean ;
20+
1921 constructor ( private $androidToolsInfo : IAndroidToolsInfo ,
2022 private $childProcess : IChildProcess ,
2123 private $errors : IErrors ,
@@ -32,6 +34,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
3234 private $androidResourcesMigrationService : IAndroidResourcesMigrationService ,
3335 private $filesHashService : IFilesHashService ) {
3436 super ( $fs , $projectDataService ) ;
37+ this . isAndroidStudioTemplate = false ;
3538 }
3639
3740 private _platformData : IPlatformData = null ;
@@ -41,10 +44,27 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
4144 }
4245 if ( projectData && projectData . platformsDir ) {
4346 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 ) ;
4456
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 ) ;
4868
4969 const packageName = this . getProjectNameFromId ( projectData ) ;
5070
@@ -140,7 +160,30 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
140160 const targetSdkVersion = androidToolsInfo && androidToolsInfo . targetSdkVersion ;
141161 this . $logger . trace ( `Using Android SDK '${ targetSdkVersion } '.` ) ;
142162
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+ }
144187
145188 this . cleanResValues ( targetSdkVersion , projectData ) ;
146189
@@ -702,6 +745,24 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
702745 }
703746 }
704747
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 ( platformVersion === constants . PackageVersion . NEXT || platformVersion === constants . PackageVersion . LATEST || platformVersion === constants . PackageVersion . RC ) {
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+
705766 private runtimeVersionIsGreaterThanOrEquals ( projectData : IProjectData , versionString : string ) : boolean {
706767 const platformVersion = this . getCurrentPlatformVersion ( this . getPlatformData ( projectData ) , projectData ) ;
707768
@@ -714,12 +775,20 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
714775 }
715776
716777 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+
718783 return path . join ( this . getPlatformData ( projectData ) . projectRoot , ...resourcePath ) ;
719784 }
720785
721786 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+
723792 return path . join ( this . getPlatformData ( projectData ) . projectRoot , ...resourcePath ) ;
724793 }
725794
0 commit comments