crossbow-admob

Crates.iocrossbow-admob
lib.rscrossbow-admob
version0.1.7
sourcesrc
created_at2022-07-14 03:01:28.503544
updated_at2022-07-28 01:05:45.967977
descriptionAdMob Plugin for Crossbow
homepage
repositoryhttps://github.com/dodorare/crossbow
max_upload_size
id625421
size47,316
David (enfipy)

documentation

README

Crossbow Admob Plugin

About

This project is a Crossbow Plugin that allows showing AdMob ads from Rust. Without worrying about the building, just download and use.

Features

Ad Format Available
Banner
Interstitial
Rewarded
Rewarded Interstitial
Native

✅ = Works and tested — 🆗 = Works but may contain bugs — 🛠 = Under development — 📝 = Planned - ❌ = Not working - ❗ = Not planned to be implemented

Installation

Just add Rust dependencies like this:

[dependencies]
crossbow = "0.1.7"
crossbow-admob = "0.1.7"

And finally, add this to your Crossbow Android configuration:

[package.metadata.android]
plugins_remote = ["com.crossbow.admob:admob:0.1.7"]

That's it, now you can start using AdMob ads!

If you want to configure custom APPLICATION_ID add this to your Cargo.toml file:

[[package.metadata.android.meta_data]]
name = "com.google.android.gms.ads.APPLICATION_ID"
value = "<YOUR ID HERE>"
# By default: ca-app-pub-3940256099942544~3347511713

Usage

In your rust project, you will need to get JNIEnv first and retrieve the JNI Singleton instance of AdMob from Crossbow. To do this, write following code:

use crossbow::android::{permission::*, plugin};

let (_, vm) = crossbow::android::create_java_vm().unwrap();
let jnienv = vm.attach_current_thread_as_daemon().unwrap();

let admob_singleton = plugin::get_jni_singleton("AdMob").expect("Crossbow Error: AdMob is not registered");
let admob = crossbow_admob::AdMobPlugin::from_jnienv(admob_singleton.clone(), jnienv).unwrap();

To show Interstitial Ad, use following code:

admob.initialize(true, "G", false, true).unwrap();
admob.load_interstitial("ca-app-pub-3940256099942544/1033173712").unwrap();
admob.show_interstitial().unwrap();

To read signals:

if let Ok(signal) = admob_singleton.get_receiver().recv().await {
    println!("signal: {:?}", signal);
}

Complete documentation you can find here.

Thanks and inspiration

This Plugin was initially inspired by godot-admob-android.

Commit count: 474

cargo fmt