update example app

Seto committed Nov 22, 2025 at 15:44 UTC 587bd82cedbef5167fc13b53a18e55aa6f450711
7 files changed +67 -33
examples/tauri-app/README.md
+4 -5
@@ -1,8 +1,7 @@
1 -# Svelte + Vite
1 +# Tauri Plugin AdMod Example
2
3 -This template should help get you started developing with Tauri and Svelte in Vite.
3 +This is an example app of Tauri plugin AdMob.
4
5 -## Recommended IDE Setup
6 -
7 -[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).
5 +## Android XML
6
7 +Replace the `gen/android/app/src/main/AndroidManifest.xml` manifest with the one in the `gen-override`.
examples/tauri-app/src-tauri/Cargo.toml
+5 -3
@@ -15,9 +15,11 @@ crate-type = ["staticlib", "cdylib", "lib"]
15 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
16
17 [build-dependencies]
18 -tauri-build = { version = "2.0.0-beta.19", default-features = false , features = [] }
18 +tauri-build = { version = "2", default-features = false , features = [] }
19
20 [dependencies]
21 -tauri = { version = "2.0.0-beta.24", features = [] }
21 +tauri = { version = "2", features = [] }
22 +tauri-plugin-devtools = "2"
23 +
24 +[target.'cfg(target_os = "android")'.dependencies]
25 tauri-plugin-admob = { path = "../../../" }
23 -tauri-plugin-devtools = "2.0.0-beta"
examples/tauri-app/src-tauri/capabilities/default.json
+2 -13
@@ -1,18 +1,7 @@
1 {
2 - "$schema": "../gen/schemas/desktop-schema.json",
2 + "$schema": "../gen/schemas/mobile-schema.json",
3 "identifier": "default",
4 "description": "enables the default permissions",
5 "windows": ["main"],
6 - "permissions": [
7 - "path:default",
8 - "event:default",
9 - "window:default",
10 - "webview:default",
11 - "app:default",
12 - "resources:default",
13 - "image:default",
14 - "menu:default",
15 - "tray:default",
16 - "admob:default"
17 - ]
6 + "permissions": ["admob:default"]
7 }
examples/tauri-app/src-tauri/gen-override/android/app/src/main/AndroidManifest.xml new
+44
@@ -0,0 +1,44 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3 + <uses-permission android:name="android.permission.INTERNET" />
4 +
5 + <!-- AndroidTV support -->
6 + <uses-feature android:name="android.software.leanback" android:required="false" />
7 +
8 + <application
9 + android:icon="@mipmap/ic_launcher"
10 + android:label="@string/app_name"
11 + android:theme="@style/Theme.tauri_app"
12 + android:usesCleartextTraffic="${usesCleartextTraffic}">
13 + <activity
14 + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
15 + android:launchMode="singleTask"
16 + android:label="@string/main_activity_title"
17 + android:name=".MainActivity"
18 + android:exported="true">
19 + <intent-filter>
20 + <action android:name="android.intent.action.MAIN" />
21 + <category android:name="android.intent.category.LAUNCHER" />
22 + <!-- AndroidTV support -->
23 + <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
24 + </intent-filter>
25 + </activity>
26 +
27 + <provider
28 + android:name="androidx.core.content.FileProvider"
29 + android:authorities="${applicationId}.fileprovider"
30 + android:exported="false"
31 + android:grantUriPermissions="true">
32 + <meta-data
33 + android:name="android.support.FILE_PROVIDER_PATHS"
34 + android:resource="@xml/file_paths" />
35 + </provider>
36 +
37 + <meta-data
38 + android:name="com.google.android.gms.ads.APPLICATION_ID"
39 + android:value="ca-app-pub-3940256099942544~3347511713"/>
40 + <meta-data
41 + android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
42 + android:value="true"/>
43 + </application>
44 +</manifest>
examples/tauri-app/src-tauri/src/lib.rs
+8 -1
@@ -13,7 +13,14 @@ pub fn run() {
13
14 builder
15 .invoke_handler(tauri::generate_handler![greet])
16 - .plugin(tauri_plugin_admob::init())
16 + .setup(|#[allow(unused)] app| {
17 + // Android-only plugin.
18 + #[cfg(target_os = "android")]
19 + {
20 + app.handle().plugin(tauri_plugin_admob::init())?;
21 + }
22 + Ok(())
23 + })
24 .run(tauri::generate_context!())
25 .expect("error while running tauri application");
26 }
examples/tauri-app/src/App.svelte
+3 -9
@@ -1,16 +1,10 @@
1 <script lang="ts">
2 -import { BannerAd, InterstitialAd } from "tauri-plugin-admob-api";
2 +import { BannerAd } from "tauri-plugin-admob-api";
3 import Greet from "./lib/Greet.svelte";
4
5 let response = "";
6
7 -function updateResponse(returnValue) {
8 - response += `[${new Date().toLocaleTimeString()}] ${
9 - typeof returnValue === "string" ? returnValue : JSON.stringify(returnValue)
10 - }<br>`;
11 -}
12 -
13 -async function _ping() {
7 +async function showBannerAd() {
8 const banner = new BannerAd({
9 adUnitId: "ca-app-pub-3940256099942544/9214589741",
10 position: "top",
@@ -46,7 +40,7 @@ async function _ping() {
40 </div>
41
42 <div>
49 - <button on:click="{_ping}">Ping</button>
43 + <button on:click="{showBannerAd}">Show Banner Ad</button>
44 <div>{@html response}</div>
45 </div>
46
examples/tauri-app/src/lib/Greet.svelte
+1 -2
@@ -1,7 +1,7 @@
1 <script>
2 import { invoke } from "@tauri-apps/api/core";
3
4 -const name = "";
4 +let name = "";
5 let greetMsg = "";
6
7 async function greet() {
@@ -19,4 +19,3 @@ async function greet() {
19 </div>
20 <p>{greetMsg}</p>
21 </div>
22 -