0.2.0-dev Download ZIP
183 lines ·6.0 KB Raw
| 1 | plugins { |
| 2 | id 'com.android.library' |
| 3 | id 'org.jetbrains.kotlin.android' |
| 4 | } |
| 5 | |
| 6 | ext { |
| 7 | DEBUG_PUBLISH_ARTIFACT_ID = 'godot-debug' |
| 8 | PUBLISH_ARTIFACT_ID = 'godot' |
| 9 | TOOLS_PUBLISH_ARTIFACT_ID = 'godot-tools' |
| 10 | } |
| 11 | |
| 12 | apply from: "../scripts/publish-module.gradle" |
| 13 | |
| 14 | dependencies { |
| 15 | implementation "androidx.fragment:fragment:$versions.fragmentVersion" |
| 16 | implementation "androidx.documentfile:documentfile:$versions.documentfileVersion" |
| 17 | |
| 18 | testImplementation "junit:junit:4.13.2" |
| 19 | } |
| 20 | |
| 21 | def pathToRootDir = "../../../../" |
| 22 | |
| 23 | android { |
| 24 | compileSdkVersion versions.compileSdk |
| 25 | buildToolsVersion versions.buildTools |
| 26 | ndkVersion = versions.ndkVersion |
| 27 | |
| 28 | defaultConfig { |
| 29 | minSdkVersion versions.minSdk |
| 30 | targetSdkVersion versions.targetSdk |
| 31 | |
| 32 | manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersionName()] |
| 33 | } |
| 34 | |
| 35 | namespace = "org.godotengine.godot" |
| 36 | |
| 37 | compileOptions { |
| 38 | sourceCompatibility versions.javaVersion |
| 39 | targetCompatibility versions.javaVersion |
| 40 | } |
| 41 | |
| 42 | kotlinOptions { |
| 43 | jvmTarget = versions.javaVersion |
| 44 | } |
| 45 | |
| 46 | buildFeatures { |
| 47 | aidl = true |
| 48 | buildConfig = true |
| 49 | } |
| 50 | |
| 51 | flavorDimensions = ["products"] |
| 52 | productFlavors { |
| 53 | editor {} |
| 54 | template {} |
| 55 | } |
| 56 | |
| 57 | lintOptions { |
| 58 | abortOnError = false |
| 59 | disable 'MissingTranslation', 'UnusedResources' |
| 60 | } |
| 61 | |
| 62 | packagingOptions { |
| 63 | exclude 'META-INF/LICENSE' |
| 64 | exclude 'META-INF/NOTICE' |
| 65 | |
| 66 | // Debug symbols are kept for development within Android Studio. |
| 67 | if (shouldNotStrip()) { |
| 68 | jniLibs { |
| 69 | keepDebugSymbols += '**/*.so' |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | sourceSets { |
| 75 | debug.jniLibs.srcDirs = ['libs/debug'] |
| 76 | release.jniLibs.srcDirs = ['libs/release'] |
| 77 | |
| 78 | // Editor jni library |
| 79 | editorRelease.jniLibs.srcDirs = ['libs/tools/release'] |
| 80 | editorDebug.jniLibs.srcDirs = ['libs/tools/debug'] |
| 81 | } |
| 82 | |
| 83 | libraryVariants.all { variant -> |
| 84 | def flavorName = variant.getFlavorName() |
| 85 | if (flavorName == null || flavorName == "") { |
| 86 | throw new GradleException("Invalid product flavor: $flavorName") |
| 87 | } |
| 88 | |
| 89 | def buildType = variant.buildType.name |
| 90 | if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) { |
| 91 | throw new GradleException("Invalid build type: $buildType") |
| 92 | } |
| 93 | |
| 94 | boolean debugBuild = buildType == "debug" |
| 95 | boolean debugSymbols = debugBuild |
| 96 | boolean runTests = debugBuild |
| 97 | boolean storeRelease = buildType == "release" |
| 98 | boolean productionBuild = storeRelease |
| 99 | |
| 100 | def sconsTarget = flavorName |
| 101 | if (sconsTarget == "template") { |
| 102 | // Tests are not supported on template builds |
| 103 | runTests = false |
| 104 | |
| 105 | //noinspection GroovyFallthrough |
| 106 | switch (buildType) { |
| 107 | case "release": |
| 108 | sconsTarget += "_release" |
| 109 | break |
| 110 | case "debug": |
| 111 | default: |
| 112 | sconsTarget += "_debug" |
| 113 | break |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // Update the name of the generated library |
| 118 | def outputSuffix = "${sconsTarget}" |
| 119 | variant.outputs.all { output -> |
| 120 | output.outputFileName = "godot-lib.${outputSuffix}.aar" |
| 121 | } |
| 122 | |
| 123 | // Find scons' executable path |
| 124 | File sconsExecutableFile = null |
| 125 | def sconsName = "scons" |
| 126 | def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows() |
| 127 | ? [".bat", ".cmd", ".ps1", ".exe"] |
| 128 | : [""]) |
| 129 | logger.debug("Looking for $sconsName executable path") |
| 130 | for (ext in sconsExts) { |
| 131 | String sconsNameExt = sconsName + ext |
| 132 | logger.debug("Checking $sconsNameExt") |
| 133 | sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt) |
| 134 | if (sconsExecutableFile != null) { |
| 135 | // We're done! |
| 136 | break |
| 137 | } |
| 138 | // Check all the options in path |
| 139 | List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt) |
| 140 | if (!allOptions.isEmpty()) { |
| 141 | // Pick the first option and we're done! |
| 142 | sconsExecutableFile = allOptions.get(0) |
| 143 | break |
| 144 | } |
| 145 | } |
| 146 | if (sconsExecutableFile == null) { |
| 147 | throw new GradleException("Unable to find executable path for the '$sconsName' command.") |
| 148 | } else { |
| 149 | logger.debug("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}") |
| 150 | } |
| 151 | |
| 152 | for (String selectedAbi : selectedAbis) { |
| 153 | if (!supportedAbis.contains(selectedAbi)) { |
| 154 | throw new GradleException("Invalid selected abi: $selectedAbi") |
| 155 | } |
| 156 | |
| 157 | // Creating gradle task to generate the native libraries for the selected abi. |
| 158 | def taskName = getSconsTaskName(flavorName, buildType, selectedAbi) |
| 159 | tasks.create(name: taskName, type: Exec) { |
| 160 | executable sconsExecutableFile.absolutePath |
| 161 | args "--directory=${pathToRootDir}", "platform=android", "store_release=${storeRelease}", "production=${productionBuild}", "dev_mode=${debugBuild}", "dev_build=${debugBuild}", "debug_symbols=${debugSymbols}", "tests=${runTests}", "target=${sconsTarget}", "arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors() |
| 162 | } |
| 163 | |
| 164 | // Schedule the tasks so the generated libs are present before the aar file is packaged. |
| 165 | tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | publishing { |
| 170 | singleVariant("templateDebug") { |
| 171 | withSourcesJar() |
| 172 | withJavadocJar() |
| 173 | } |
| 174 | singleVariant("templateRelease") { |
| 175 | withSourcesJar() |
| 176 | withJavadocJar() |
| 177 | } |
| 178 | singleVariant("editorRelease") { |
| 179 | withSourcesJar() |
| 180 | withJavadocJar() |
| 181 | } |
| 182 | } |
| 183 | } |