|
| 1 | +import java.util.Properties |
| 2 | +import java.io.FileInputStream |
| 3 | +import java.io.IOException |
| 4 | +import java.net.URI |
| 5 | + |
| 6 | +plugins { |
| 7 | + alias(libs.plugins.android.library) |
| 8 | + alias(libs.plugins.jreleaser) |
| 9 | + `maven-publish` |
| 10 | +} |
| 11 | + |
| 12 | +// Load file "keystore.properties" where we keep our keys |
| 13 | +val keystorePropertiesFile = rootProject.file("keystore.properties") |
| 14 | +val keystoreProperties = Properties() |
| 15 | + |
| 16 | +try { |
| 17 | + keystoreProperties.load(FileInputStream(keystorePropertiesFile)) |
| 18 | +} catch (ignored: IOException) { |
| 19 | + if (project.hasProperty("centralUsername")) keystoreProperties["centralUsername"] = property("centralUsername") |
| 20 | + if (project.hasProperty("centralPassword")) keystoreProperties["centralPassword"] = property("centralPassword") |
| 21 | + if (project.hasProperty("gpgPass")) keystoreProperties["gpgPass"] = property("gpgPass") |
| 22 | +} |
| 23 | + |
| 24 | +allprojects { |
| 25 | + val mavsdk_server_release = "v3.6.0" |
| 26 | + |
| 27 | + tasks { |
| 28 | + register<Copy>("extractMavsdkServer") { |
| 29 | + val tmpDir = File(layout.buildDirectory.get().asFile, "tmp") |
| 30 | + tmpDir.mkdirs() |
| 31 | + |
| 32 | + fun extractForArch(arch: String) { |
| 33 | + val archiveName = "mavsdk_server_android-${arch}_${mavsdk_server_release}.tar" |
| 34 | + val archiveFile = File(tmpDir, archiveName) |
| 35 | + val archiveUrl = "https://github.com/mavlink/MAVSDK/releases/download/${mavsdk_server_release}/mavsdk_server_android-$arch.tar" |
| 36 | + val destDir = "${project.projectDir.getAbsolutePath()}/src/main/prebuiltLibs" |
| 37 | + |
| 38 | + inputs.file(archiveFile) |
| 39 | + outputs.dir(destDir) |
| 40 | + |
| 41 | + if (!archiveFile.exists()) { |
| 42 | + project.logger.warn("Downloading ${archiveFile.getName()} into ${archiveFile.getAbsolutePath()}...") |
| 43 | + URI(archiveUrl).toURL().openStream().use { input -> |
| 44 | + archiveFile.outputStream().use { output -> |
| 45 | + input.copyTo(output) |
| 46 | + } |
| 47 | + } |
| 48 | + } else { |
| 49 | + project.logger.warn("Archive already exists! Skipping download.") |
| 50 | + } |
| 51 | + |
| 52 | + project.logger.warn("Extracting $archiveFile into $destDir") |
| 53 | + |
| 54 | + from(tarTree(archiveFile)) { |
| 55 | + duplicatesStrategy = DuplicatesStrategy.INCLUDE |
| 56 | + } |
| 57 | + eachFile { |
| 58 | + if (path.endsWith(".so")) { |
| 59 | + filePermissions { |
| 60 | + group.execute = true |
| 61 | + user.execute = true |
| 62 | + other.execute = true |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + into(destDir) |
| 67 | + project.logger.warn("Should be extracted for arch $arch") |
| 68 | + } |
| 69 | + |
| 70 | + extractForArch("arm64") |
| 71 | + extractForArch("arm") |
| 72 | + extractForArch("x86") |
| 73 | + extractForArch("x86_64") |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + tasks.named("preBuild") { |
| 78 | + dependsOn("extractMavsdkServer") |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +android { |
| 83 | + namespace = "io.mavsdk.mavsdkserver" |
| 84 | + compileSdk = 35 |
| 85 | + |
| 86 | + defaultConfig { |
| 87 | + minSdk = 21 |
| 88 | + |
| 89 | + group = "io.mavsdk" |
| 90 | + version = "3.6.0-SNAPSHOT" |
| 91 | + |
| 92 | + |
| 93 | + ndk { |
| 94 | + abiFilters += listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64") |
| 95 | + } |
| 96 | + |
| 97 | + externalNativeBuild { |
| 98 | + cmake { |
| 99 | + arguments.add("-DANDROID_STL=c++_shared") |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + externalNativeBuild { |
| 105 | + cmake { |
| 106 | + path = File("src/main/cpp/CMakeLists.txt") |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + buildTypes { |
| 111 | + release { |
| 112 | + isMinifyEnabled = false |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + publishing { |
| 117 | + singleVariant("release") { |
| 118 | + withSourcesJar() |
| 119 | + withJavadocJar() |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + compileOptions { |
| 124 | + sourceCompatibility = JavaVersion.VERSION_17 |
| 125 | + targetCompatibility = JavaVersion.VERSION_17 |
| 126 | + } |
| 127 | + |
| 128 | + ndkVersion = "28.0.13004108" |
| 129 | +} |
| 130 | + |
| 131 | + |
| 132 | +if (keystoreProperties.containsKey("centralUsername") && keystoreProperties.containsKey("centralPassword")) { |
| 133 | + afterEvaluate { |
| 134 | + publishing { |
| 135 | + publications { |
| 136 | + create<MavenPublication>("release") { |
| 137 | + from(components["release"]) |
| 138 | + |
| 139 | + pom { |
| 140 | + name = "MAVSDK-Server" |
| 141 | + packaging = "aar" |
| 142 | + description = "MAVSDK server for Android." |
| 143 | + url = "https://github.com/mavlink/MAVSDK-Java" |
| 144 | + |
| 145 | + scm { |
| 146 | + connection = "scm:git:https://github.com/mavlink/MAVSDK-Java" |
| 147 | + developerConnection = "scm:git:https://github.com/mavlink/MAVSDK-Java" |
| 148 | + url = "https://github.com/mavlink/MAVSDK-Java" |
| 149 | + } |
| 150 | + |
| 151 | + licenses { |
| 152 | + license { |
| 153 | + name = "BSD 3-Clause" |
| 154 | + url = "https://opensource.org/licenses/BSD-3-Clause" |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + developers { |
| 159 | + developer { |
| 160 | + id = "jonasvautherin" |
| 161 | + name = "Jonas Vautherin" |
| 162 | + |
| 163 | + } |
| 164 | + developer { |
| 165 | + id = "julianoes" |
| 166 | + name = "Julian Oes" |
| 167 | + |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + repositories { |
| 175 | + maven { |
| 176 | + url = uri(layout.buildDirectory.dir("target/staging-deploy")) |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + jreleaser { |
| 183 | + signing { |
| 184 | + setActive("ALWAYS") |
| 185 | + armored.set(true) |
| 186 | + setMode("COMMAND") |
| 187 | + keystoreProperties["gpgPass"]?.let { |
| 188 | + passphrase.set(it as String) |
| 189 | + } |
| 190 | + } |
| 191 | + deploy { |
| 192 | + release { |
| 193 | + github { |
| 194 | + skipRelease = true |
| 195 | + skipTag = true |
| 196 | + } |
| 197 | + } |
| 198 | + maven { |
| 199 | + mavenCentral { |
| 200 | + create("sonatype") { |
| 201 | + verifyPom = false |
| 202 | + setActive("RELEASE") |
| 203 | + username = keystoreProperties["centralUsername"] as String |
| 204 | + password = keystoreProperties["centralPassword"] as String |
| 205 | + url = "https://central.sonatype.com/api/v1/publisher" |
| 206 | + stagingRepository("build/target/staging-deploy") |
| 207 | + } |
| 208 | + } |
| 209 | + nexus2 { |
| 210 | + create("snapshot-deploy") { |
| 211 | + verifyPom = false |
| 212 | + setActive("SNAPSHOT") |
| 213 | + snapshotUrl.set("https://central.sonatype.com/repository/maven-snapshots") |
| 214 | + url = "https://central.sonatype.com/repository/maven-snapshots" |
| 215 | + applyMavenCentralRules = true |
| 216 | + snapshotSupported = true |
| 217 | + username = keystoreProperties["centralUsername"] as String |
| 218 | + password = keystoreProperties["centralPassword"] as String |
| 219 | + stagingRepository("build/target/staging-deploy") |
| 220 | + } |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | + } |
| 225 | +} |
| 226 | + |
0 commit comments