This project is a Crossbow Plugin that allows showing AdMob ads from Rust. Without worrying about the building, just download and use.
| 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
Just add Rust dependencies like this:
toml
[dependencies]
crossbow = "0.1.6"
crossbow-admob = "0.1.6"
And finally, add this to your Crossbow Android configuration:
toml
[package.metadata.android]
plugins_remote = ["com.crossbow.admob:admob:0.1.6"]
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:
```toml
[[package.metadata.android.metadata]]
name = "com.google.android.gms.ads.APPLICATIONID"
value = "
```
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:
```rust use crossbow::android::{permission::*, plugin};
let (, vm) = crossbow::android::createjavavm().unwrap(); let jnienv = vm.attachcurrentthreadas_daemon().unwrap();
let admobsingleton = plugin::getjnisingleton("AdMob").expect("Crossbow Error: AdMob is not registered"); let admob = crossbowadmob::AdMobPlugin::fromjnienv(admobsingleton.clone(), jnienv).unwrap(); ```
To show Interstitial Ad, use following code:
rust
admob.initialize(true, "G", false, true).unwrap();
admob.load_interstitial("ca-app-pub-3940256099942544/1033173712").unwrap();
admob.show_interstitial().unwrap();
To read signals:
rust
if let Ok(signal) = admob_singleton.get_receiver().recv().await {
println!("signal: {:?}", signal);
}
Complete documentation you can find here.
This Plugin was initially inspired by godot-admob-android.