tauri-plugin-admob

Crates.iotauri-plugin-admob
lib.rstauri-plugin-admob
version0.0.4
created_at2025-03-23 11:25:55.542489+00
updated_at2025-03-23 11:25:55.542489+00
descriptionTauri Plugin admob
homepage
repository
max_upload_size
id1602571
size278,547
Lorenzo Rizzotti (Dreaming-Codes)

documentation

README

Tauri Plugin admob

For now this is just a copy of admob-plus in the future I would like to refactor the code to be more Tauri friendly.

The plugin currently only supports android. If you want iOS support, please feel free to create a pull request

How to install

Since this plugin is yet not published to crates.io or npm registery, we can install it using github link directly.

  1. Inside your root directory run this command
npm i tauri-plugin-admob-api

You might need to update your tauri version to "2.4.0" or more

  1. Inside your src-tauri directory run this command
cargo add tauri-plugin-admob
  1. Since google library uses different Kotlin version than Tauri you may need to add the following compiler arg: -Xskip-metadata-version-check
// src-tauri/gen/android/app/build.gradle.kts
kotlinOptions {
    // ...
    freeCompilerArgs += "-Xskip-metadata-version-check"
}
  1. Add your AdMob app ID, as identified in the AdMob web interface, to your app's AndroidManifest.xml. To do so, add a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID". You can find your app ID in the AdMob web interface. For android:value, insert your own AdMob app ID, surrounded by quotation marks.
<!-- ./src-tauri/gen/android/app/src/main/AndroidManifest.xml -->
<manifest>
    <application>
        <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
        <meta-data
                android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
                android:value="true"/>
    </application>
</manifest>

How to use

import { BannerAd } from "tauri-plugin-admob-api";

const showBanner = async () => {
  const banner = new BannerAd({
    adUnitId: "ca-app-pub-3940256099942544/9214589741",
    position: "bottom",
  });
  await banner.load();
  await banner.show();
};

For more details on how to use it check the documentation of admob-plus

Commit count: 0

cargo fmt