Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): update android template to gradle 8.0 (#6890)
* feat(cli): update android template to gradle 8.0 * update java in CI to 17 * updat to latest tauri-mobile
- Loading branch information
Showing
13 changed files
with
98 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'cli.rs': 'patch' | ||
'cli.js': 'patch' | ||
--- | ||
|
||
Update android template to gradle 8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 51 additions & 25 deletions
76
tooling/cli/templates/mobile/android/buildSrc/src/main/kotlin/RustPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,85 @@ | ||
package {{reverse-domain app.domain}} | ||
|
||
import com.android.build.api.dsl.ApplicationExtension | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import java.io.File | ||
import java.util.* | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.get | ||
|
||
const val TASK_GROUP = "rust" | ||
|
||
open class Config { | ||
var rootDirRel: String? = null | ||
var targets: List<String>? = null | ||
var arches: List<String>? = null | ||
lateinit var rootDirRel: String | ||
} | ||
|
||
open class RustPlugin : Plugin<Project> { | ||
private lateinit var config: Config | ||
|
||
override fun apply(project: Project) { | ||
config = project.extensions.create("rust", Config::class.java) | ||
project.afterEvaluate { | ||
if (config.targets == null) { | ||
throw GradleException("targets cannot be null") | ||
} | ||
if (config.arches == null) { | ||
throw GradleException("arches cannot be null") | ||
override fun apply(project: Project) = with(project) { | ||
config = extensions.create("rust", Config::class.java) | ||
|
||
val defaultAbiList = listOf({{quote-and-join abi-list}}); | ||
val abiList = (findProperty("abiList") as? String)?.split(',') ?: defaultAbiList | ||
|
||
val defaultArchList = listOf({{quote-and-join arch-list}}); | ||
val archList = (findProperty("archList") as? String)?.split(',') ?: listOf({{quote-and-join arch-list}}) | ||
|
||
val targetsList = (findProperty("targetList") as? String)?.split(',') ?: listOf({{quote-and-join target-list}}) | ||
|
||
extensions.configure<ApplicationExtension> { | ||
@Suppress("UnstableApiUsage") | ||
flavorDimensions.add("abi") | ||
productFlavors { | ||
create("universal") { | ||
dimension = "abi" | ||
ndk { | ||
abiFilters += abiList | ||
} | ||
} | ||
defaultArchList.forEachIndexed { index, arch -> | ||
create(arch) { | ||
dimension = "abi" | ||
ndk { | ||
abiFilters.add(defaultAbiList[index]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
afterEvaluate { | ||
for (profile in listOf("debug", "release")) { | ||
val profileCapitalized = profile.capitalize(Locale.ROOT) | ||
val buildTask = project.tasks.maybeCreate( | ||
"rustBuild$profileCapitalized", | ||
val profileCapitalized = profile.replaceFirstChar { it.uppercase() } | ||
val buildTask = tasks.maybeCreate( | ||
"rustBuildUniversal$profileCapitalized", | ||
DefaultTask::class.java | ||
).apply { | ||
group = TASK_GROUP | ||
description = "Build dynamic library in $profile mode for all targets" | ||
} | ||
for (targetPair in config.targets!!.withIndex()) { | ||
|
||
tasks["mergeUniversal${profileCapitalized}JniLibFolders"].dependsOn(buildTask) | ||
|
||
for (targetPair in targetsList.withIndex()) { | ||
val targetName = targetPair.value | ||
val targetArch = config.arches!![targetPair.index] | ||
val targetArchCapitalized = targetArch.capitalize(Locale.ROOT) | ||
val targetArch = archList[targetPair.index] | ||
val targetArchCapitalized = targetArch.replaceFirstChar { it.uppercase() } | ||
val targetBuildTask = project.tasks.maybeCreate( | ||
"rustBuild$targetArchCapitalized$profileCapitalized", | ||
BuildTask::class.java | ||
).apply { | ||
group = TASK_GROUP | ||
description = "Build dynamic library in $profile mode for $targetArch" | ||
rootDirRel = config.rootDirRel?.let { File(it) } | ||
rootDirRel = config.rootDirRel | ||
target = targetName | ||
release = profile == "release" | ||
} | ||
|
||
buildTask.dependsOn(targetBuildTask) | ||
project.tasks.findByName("preBuild")?.mustRunAfter(targetBuildTask) | ||
tasks["merge$targetArchCapitalized${profileCapitalized}JniLibFolders"].dependsOn( | ||
targetBuildTask | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tooling/cli/templates/mobile/android/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue May 10 19:22:52 CST 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |