Skip to content

Commit 5a9307d

Browse files
authored
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
1 parent 39f1b04 commit 5a9307d

File tree

13 files changed

+98
-107
lines changed

13 files changed

+98
-107
lines changed

.changes/gradle-8.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'cli.rs': 'patch'
3+
'cli.js': 'patch'
4+
---
5+
6+
Update android template to gradle 8.0

.github/workflows/test-android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- uses: actions/setup-java@v3
5858
with:
5959
distribution: temurin
60-
java-version: 11
60+
java-version: 17
6161
cache: gradle
6262

6363
- name: Setup NDK

tooling/cli/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ name = "cargo-tauri"
3939
path = "src/main.rs"
4040

4141
[dependencies]
42-
tauri-mobile = { version = "0.4", default-features = false }
42+
tauri-mobile = { version = "0.5", default-features = false }
4343
textwrap = { version = "0.11.0", features = [ "term_size" ] }
4444
jsonrpsee = { version = "0.16", features = [ "server" ] }
4545
jsonrpsee-core = "0.16"

tooling/cli/src/mobile/android/project.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ pub fn gen(
5252
)),
5353
);
5454
map.insert("root-dir", config.app().root_dir());
55-
map.insert("targets", Target::all().values().collect::<Vec<_>>());
56-
map.insert("target-names", Target::all().keys().collect::<Vec<_>>());
5755
map.insert(
58-
"arches",
56+
"abi-list",
57+
Target::all()
58+
.values()
59+
.map(|target| target.abi)
60+
.collect::<Vec<_>>(),
61+
);
62+
map.insert("target-list", Target::all().keys().collect::<Vec<_>>());
63+
map.insert(
64+
"arch-list",
5965
Target::all()
6066
.values()
6167
.map(|target| target.arch)
@@ -77,6 +83,7 @@ pub fn gen(
7783
|| metadata.app_dependencies().is_some()
7884
|| metadata.app_dependencies_platform().is_some(),
7985
);
86+
map.insert("has-asset-packs", !asset_packs.is_empty());
8087
map.insert(
8188
"asset-packs",
8289
asset_packs
Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
plugins {
22
id("com.android.application")
33
id("org.jetbrains.kotlin.android")
4-
id("rustPlugin")
4+
id("rust")
55
{{~#each android-app-plugins}}
66
id("{{this}}"){{/each}}
77
}
88

99
android {
1010
compileSdk = 33
11+
namespace = "{{reverse-domain app.domain}}.{{snake-case app.name}}"
1112
defaultConfig {
1213
manifestPlaceholders["usesCleartextTraffic"] = "false"
1314
applicationId = "{{reverse-domain app.domain}}.{{snake-case app.name}}"
@@ -16,88 +17,47 @@ android {
1617
versionCode = 1
1718
versionName = "1.0"
1819
}
19-
sourceSets.getByName("main") {
20-
{{#if android.vulkan-validation}}// Vulkan validation layers
21-
val ndkHome = System.getenv("NDK_HOME")
22-
jniLibs.srcDir("${ndkHome}/sources/third_party/vulkan/src/build-android/jniLibs")
23-
{{/if}}
24-
}
2520
buildTypes {
2621
getByName("debug") {
2722
manifestPlaceholders["usesCleartextTraffic"] = "true"
2823
isDebuggable = true
2924
isJniDebuggable = true
3025
isMinifyEnabled = false
31-
packagingOptions {
32-
{{~#each targets}}
33-
jniLibs.keepDebugSymbols.add("*/{{this.abi}}/*.so")
26+
packaging {
27+
{{~#each abi-list}}
28+
jniLibs.keepDebugSymbols.add("*/{{this}}/*.so")
3429
{{/each}}
3530
}
3631
}
3732
getByName("release") {
3833
isMinifyEnabled = true
39-
val proguards = fileTree(".") {
40-
include("**/*.pro")
41-
}
42-
proguardFiles(*proguards.toList().toTypedArray())
34+
proguardFiles(
35+
*fileTree(".") { include("**/*.pro") }
36+
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
37+
.toList().toTypedArray()
38+
)
4339
}
4440
}
45-
flavorDimensions.add("abi")
46-
productFlavors {
47-
create("universal") {
48-
dimension = "abi"
49-
ndk {
50-
abiFilters += (findProperty("abiList") as? String)?.split(",") ?: listOf(
51-
{{~#each targets}}
52-
"{{this.abi}}",{{/each}}
53-
)
54-
}
55-
}
56-
{{~#each targets}}
57-
58-
create("{{this.arch}}") {
59-
dimension = "abi"
60-
ndk {
61-
abiFilters += listOf("{{this.abi}}")
62-
}
63-
}
64-
{{/each}}
41+
kotlinOptions {
42+
jvmTarget = "1.8"
6543
}
66-
67-
assetPacks += mutableSetOf({{quote-and-join-colon-prefix asset-packs}})
68-
namespace = "{{reverse-domain app.domain}}.{{snake-case app.name}}"
6944
}
7045

7146
rust {
7247
rootDirRel = "{{root-dir-rel}}"
73-
targets = (findProperty("targetList") as? String)?.split(",") ?: listOf({{quote-and-join target-names}})
74-
arches = (findProperty("archList") as? String)?.split(",") ?: listOf({{quote-and-join arches}})
7548
}
7649

7750
dependencies {
7851
{{~#each android-app-dependencies-platform}}
7952
implementation(platform("{{this}}")){{/each}}
8053
{{~#each android-app-dependencies}}
8154
implementation("{{this}}"){{/each}}
82-
implementation("androidx.webkit:webkit:1.5.0")
83-
implementation("androidx.appcompat:appcompat:1.5.1")
84-
implementation("com.google.android.material:material:1.7.0")
55+
implementation("androidx.webkit:webkit:1.6.1")
56+
implementation("androidx.appcompat:appcompat:1.6.1")
57+
implementation("com.google.android.material:material:1.8.0")
8558
testImplementation("junit:junit:4.13.2")
8659
androidTestImplementation("androidx.test.ext:junit:1.1.4")
8760
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
8861
}
8962

9063
apply(from = "tauri.build.gradle.kts")
91-
92-
afterEvaluate {
93-
android.applicationVariants.all {
94-
tasks["mergeUniversalReleaseJniLibFolders"].dependsOn(tasks["rustBuildRelease"])
95-
tasks["mergeUniversalDebugJniLibFolders"].dependsOn(tasks["rustBuildDebug"])
96-
if (findProperty("targetList") == null) {
97-
productFlavors.filter{ it.name != "universal" }.forEach { _ ->
98-
val archAndBuildType = name.capitalize()
99-
tasks["merge${archAndBuildType}JniLibFolders"].dependsOn(tasks["rustBuild${archAndBuildType}"])
100-
}
101-
}
102-
}
103-
}

tooling/cli/templates/mobile/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
android:exported="true">
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />
17-
1817
<category android:name="android.intent.category.LAUNCHER" />
1918
</intent-filter>
2019
</activity>

tooling/cli/templates/mobile/android/build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
21
buildscript {
32
repositories {
43
google()
54
mavenCentral()
65
}
76
dependencies {
8-
classpath("com.android.tools.build:gradle:7.3.1")
9-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
7+
classpath("com.android.tools.build:gradle:8.0.0")
8+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
109
{{~#each android-project-dependencies}}
1110
classpath("{{this}}"){{/each}}
12-
// NOTE: Do not place your application dependencies here; they belong
13-
// in the individual module build.gradle files
1411
}
1512
}
1613

tooling/cli/templates/mobile/android/buildSrc/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ plugins {
55
gradlePlugin {
66
plugins {
77
create("pluginsForCoolKids") {
8-
id = "rustPlugin"
9-
implementationClass = "{{reverse-domain app.domain}}.RustPlugin"
8+
id = "rust"
9+
implementationClass = "RustPlugin"
1010
}
1111
}
1212
}
@@ -18,6 +18,6 @@ repositories {
1818

1919
dependencies {
2020
compileOnly(gradleApi())
21-
implementation("com.android.tools.build:gradle:7.3.1")
21+
implementation("com.android.tools.build:gradle:8.0.0")
2222
}
2323

tooling/cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
package {{reverse-domain app.domain}}
2-
31
import java.io.File
42
import org.apache.tools.ant.taskdefs.condition.Os
53
import org.gradle.api.DefaultTask
64
import org.gradle.api.GradleException
75
import org.gradle.api.logging.LogLevel
86
import org.gradle.api.tasks.Input
9-
import org.gradle.api.tasks.InputDirectory
10-
import org.gradle.api.tasks.PathSensitive
11-
import org.gradle.api.tasks.PathSensitivity
127
import org.gradle.api.tasks.TaskAction
138

149
open class BuildTask : DefaultTask() {
15-
@InputDirectory
16-
@PathSensitive(PathSensitivity.RELATIVE)
17-
var rootDirRel: File? = null
10+
@Input
11+
var rootDirRel: String? = null
1812
@Input
1913
var target: String? = null
2014
@Input
@@ -41,7 +35,7 @@ open class BuildTask : DefaultTask() {
4135
val args = listOf({{quote-and-join tauri-binary-args}});
4236

4337
project.exec {
44-
workingDir(File(project.projectDir, rootDirRel.path))
38+
workingDir(File(project.projectDir, rootDirRel))
4539
executable(executable)
4640
args(args)
4741
if (project.logger.isEnabled(LogLevel.DEBUG)) {

0 commit comments

Comments
 (0)