| 
									
										
										
										
											2022-05-31 19:10:15 +01:00
										 |  |  | plugins { | 
					
						
							|  |  |  |     id 'com.android.library' | 
					
						
							|  |  |  |     id 'org.jetbrains.kotlin.android' | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 09:19:04 -07:00
										 |  |  | ext { | 
					
						
							|  |  |  |     PUBLISH_ARTIFACT_ID = 'godot' | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | apply from: "../scripts/publish-module.gradle" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  | dependencies { | 
					
						
							| 
									
										
										
										
											2024-01-17 13:44:11 -08:00
										 |  |  |     implementation "androidx.fragment:fragment:$versions.fragmentVersion" | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def pathToRootDir = "../../../../" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | android { | 
					
						
							|  |  |  |     compileSdkVersion versions.compileSdk | 
					
						
							|  |  |  |     buildToolsVersion versions.buildTools | 
					
						
							| 
									
										
										
										
											2021-02-17 16:31:31 -08:00
										 |  |  |     ndkVersion versions.ndkVersion | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |     defaultConfig { | 
					
						
							|  |  |  |         minSdkVersion versions.minSdk | 
					
						
							|  |  |  |         targetSdkVersion versions.targetSdk | 
					
						
							| 
									
										
										
										
											2021-02-24 03:49:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersionName()] | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 09:19:04 -07:00
										 |  |  |     namespace = "org.godotengine.godot" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-28 16:32:45 -07:00
										 |  |  |     compileOptions { | 
					
						
							|  |  |  |         sourceCompatibility versions.javaVersion | 
					
						
							|  |  |  |         targetCompatibility versions.javaVersion | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 19:10:15 +01:00
										 |  |  |     kotlinOptions { | 
					
						
							|  |  |  |         jvmTarget = versions.javaVersion | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-17 13:44:11 -08:00
										 |  |  |     buildFeatures { | 
					
						
							|  |  |  |         aidl = true | 
					
						
							|  |  |  |         buildConfig = true | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |     buildTypes { | 
					
						
							|  |  |  |         dev { | 
					
						
							|  |  |  |             initWith debug | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     flavorDimensions "products" | 
					
						
							|  |  |  |     productFlavors { | 
					
						
							|  |  |  |         editor {} | 
					
						
							|  |  |  |         template {} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |     lintOptions { | 
					
						
							|  |  |  |         abortOnError false | 
					
						
							|  |  |  |         disable 'MissingTranslation', 'UnusedResources' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     packagingOptions { | 
					
						
							|  |  |  |         exclude 'META-INF/LICENSE' | 
					
						
							|  |  |  |         exclude 'META-INF/NOTICE' | 
					
						
							| 
									
										
										
										
											2020-04-23 00:21:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 00:14:57 -08:00
										 |  |  |         // 'doNotStrip' is enabled for development within Android Studio
 | 
					
						
							|  |  |  |         if (shouldNotStrip()) { | 
					
						
							|  |  |  |             doNotStrip '**/*.so' | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sourceSets { | 
					
						
							|  |  |  |         main { | 
					
						
							|  |  |  |             manifest.srcFile 'AndroidManifest.xml' | 
					
						
							|  |  |  |             java.srcDirs = ['src'] | 
					
						
							|  |  |  |             res.srcDirs = ['res'] | 
					
						
							|  |  |  |             aidl.srcDirs = ['aidl'] | 
					
						
							|  |  |  |             assets.srcDirs = ['assets'] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |         debug.jniLibs.srcDirs = ['libs/debug'] | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         dev.jniLibs.srcDirs = ['libs/dev'] | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |         release.jniLibs.srcDirs = ['libs/release'] | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Editor jni library
 | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |         editorRelease.jniLibs.srcDirs = ['libs/tools/release'] | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         editorDebug.jniLibs.srcDirs = ['libs/tools/debug'] | 
					
						
							|  |  |  |         editorDev.jniLibs.srcDirs = ['libs/tools/dev'] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |     libraryVariants.all { variant -> | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         def flavorName = variant.getFlavorName() | 
					
						
							|  |  |  |         if (flavorName == null || flavorName == "") { | 
					
						
							|  |  |  |             throw new GradleException("Invalid product flavor: $flavorName") | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         def buildType = variant.buildType.name | 
					
						
							| 
									
										
										
										
											2022-10-05 08:24:50 -07:00
										 |  |  |         if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) { | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |             throw new GradleException("Invalid build type: $buildType") | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-05 08:24:50 -07:00
										 |  |  |         boolean devBuild = buildType == "dev" | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |         boolean runTests = devBuild | 
					
						
							|  |  |  |         boolean productionBuild = !devBuild | 
					
						
							|  |  |  |         boolean storeRelease = buildType == "release" | 
					
						
							| 
									
										
										
										
											2022-10-05 08:24:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         def sconsTarget = flavorName | 
					
						
							|  |  |  |         if (sconsTarget == "template") { | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |             // Tests are not supported on template builds
 | 
					
						
							|  |  |  |             runTests = false | 
					
						
							| 
									
										
										
										
											2022-10-05 08:24:50 -07:00
										 |  |  |             switch (buildType) { | 
					
						
							|  |  |  |                 case "release": | 
					
						
							|  |  |  |                     sconsTarget += "_release" | 
					
						
							|  |  |  |                     break | 
					
						
							|  |  |  |                 case "debug": | 
					
						
							|  |  |  |                 case "dev": | 
					
						
							|  |  |  |                 default: | 
					
						
							|  |  |  |                     sconsTarget += "_debug" | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Update the name of the generated library
 | 
					
						
							| 
									
										
										
										
											2022-10-05 08:24:50 -07:00
										 |  |  |         def outputSuffix = "${sconsTarget}" | 
					
						
							|  |  |  |         if (devBuild) { | 
					
						
							|  |  |  |             outputSuffix = "${outputSuffix}.dev" | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |         variant.outputs.all { output -> | 
					
						
							| 
									
										
										
										
											2022-10-05 08:24:50 -07:00
										 |  |  |             output.outputFileName = "godot-lib.${outputSuffix}.aar" | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-14 14:36:53 -08:00
										 |  |  |         // Find scons' executable path
 | 
					
						
							|  |  |  |         File sconsExecutableFile = null | 
					
						
							|  |  |  |         def sconsName = "scons" | 
					
						
							|  |  |  |         def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows() | 
					
						
							| 
									
										
										
										
											2021-01-30 20:13:01 +08:00
										 |  |  |             ? [".bat", ".cmd", ".ps1", ".exe"] | 
					
						
							| 
									
										
										
										
											2020-11-14 14:36:53 -08:00
										 |  |  |             : [""]) | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |         logger.debug("Looking for $sconsName executable path") | 
					
						
							| 
									
										
										
										
											2020-11-14 14:36:53 -08:00
										 |  |  |         for (ext in sconsExts) { | 
					
						
							|  |  |  |             String sconsNameExt = sconsName + ext | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |             logger.debug("Checking $sconsNameExt") | 
					
						
							| 
									
										
										
										
											2020-11-14 14:36:53 -08:00
										 |  |  |             sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt) | 
					
						
							|  |  |  |             if (sconsExecutableFile != null) { | 
					
						
							|  |  |  |                 // We're done!
 | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             // Check all the options in path
 | 
					
						
							|  |  |  |             List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt) | 
					
						
							|  |  |  |             if (!allOptions.isEmpty()) { | 
					
						
							|  |  |  |                 // Pick the first option and we're done!
 | 
					
						
							|  |  |  |                 sconsExecutableFile = allOptions.get(0) | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (sconsExecutableFile == null) { | 
					
						
							|  |  |  |             throw new GradleException("Unable to find executable path for the '$sconsName' command.") | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |             logger.debug("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}") | 
					
						
							| 
									
										
										
										
											2020-11-14 14:36:53 -08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |         for (String selectedAbi : selectedAbis) { | 
					
						
							|  |  |  |             if (!supportedAbis.contains(selectedAbi)) { | 
					
						
							|  |  |  |                 throw new GradleException("Invalid selected abi: $selectedAbi") | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |             // Creating gradle task to generate the native libraries for the selected abi.
 | 
					
						
							|  |  |  |             def taskName = getSconsTaskName(flavorName, buildType, selectedAbi) | 
					
						
							|  |  |  |             tasks.create(name: taskName, type: Exec) { | 
					
						
							|  |  |  |                 executable sconsExecutableFile.absolutePath | 
					
						
							| 
									
										
										
										
											2023-03-01 14:09:30 -08:00
										 |  |  |                 args "--directory=${pathToRootDir}", "platform=android", "store_release=${storeRelease}", "production=${productionBuild}", "dev_mode=${devBuild}", "dev_build=${devBuild}", "tests=${runTests}", "target=${sconsTarget}", "arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors() | 
					
						
							| 
									
										
										
										
											2021-06-25 16:45:16 +03:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Schedule the tasks so the generated libs are present before the aar file is packaged.
 | 
					
						
							|  |  |  |             tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-03-14 09:19:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-10 16:35:50 -08:00
										 |  |  |     publishing { | 
					
						
							|  |  |  |         singleVariant("templateRelease") { | 
					
						
							|  |  |  |             withSourcesJar() | 
					
						
							|  |  |  |             withJavadocJar() | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-09-02 17:31:51 -07:00
										 |  |  | } |