dodorare / crossbow

Cross-Platform build tools and toolkit for games and game engines written in Rust! 🦀
https://crossbow.dodorare.com/
Apache License 2.0
201 stars 13 forks source link

Error: Singleton with `CrossbowAdMob` name not found or haven't registered #167

Open kacper-cholewinski opened 1 year ago

kacper-cholewinski commented 1 year ago

Crossbow version

0.2.3

What you did

Code:

use crossbow::android::*;

#[macroquad::main("project_name")]
async fn main() -> anyhow::Result<()> {

  let crossbow = CrossbowInstance::new();
  let admob: admob_android::AdMobPlugin = crossbow.get_plugin()?;

  loop {
    clear_background(WHITE);
    draw_rectangle(0., 0., 100., 100., BLUE);
    next_frame().await;
  }
}

What went wrong

I get black screen and error: Singleton with CrossbowAdMob name not found or haven't registered (adb logcat)

Thanks for all your help

enfipy commented 1 year ago

Merry Christmas! Sorry for the late response.

Have you added everything required in Cargo.toml as specified in this link?

kacper-cholewinski commented 1 year ago

Wish you same.

I think I added all things required. I got only problem with this one: [[package.metadata.android.manifest.application.meta_data]] I got error that I need to add some "package" property to it (when building using crossbundle). I've tried other plugins and I get same problems.

enfipy commented 1 year ago

@kacper-cholewinski can you paste error message or your Cargo.toml? Also, did you try running examples?

kacper-cholewinski commented 1 year ago

The error is:

error: Invalid metadata in manifest: missing field `package` for key `android.manifest`

for:

[[package.metadata.android.manifest.application.meta_data]]
name = "com.google.android.gms.ads.APPLICATION_ID"
value = "ca-app-pub-3940256099942544~3347511713"

@kacper-cholewinski ... Also, did you try running examples?

That's where I've first encountered the problem.

kacper-cholewinski commented 1 year ago

Happy New Year btw

enfipy commented 1 year ago

@kacper-cholewinski Happy New Year too.

This error looks like you forgot to specify the android manifest package in Cargo.toml:

Screenshot 2023-01-01 at 19 11 13

Sorry friend, I can't reproduce this error in any example on my mac and it looks like our CI doesn't have this issue. Can you provide more info about your setup, Cargo.toml, and full error message?

kacper-cholewinski commented 1 year ago

Thanks for help again

I did as you suggested and now I'm in starting point:

PanicInfo { payload: Any { .. }, message: Some(called `Result::unwrap()` on an `Err` value: SingletonNotRegistered("CrossbowAdMob")), location: Location { file: "src\\__cargo_apk_mainaqyhhg.tmp", line: 11, col: 65 }, can_unwind: true }

Cargo.toml:

[package]
name = "project_name"
version = "0.1.0"
authors = REDACTED
edition = "2021"

[dependencies]
crossbow = "*"
log = "0.4"
anyhow = "1.0"
macroquad = "=0.3.7"
admob-android = "0.2.3"
crossbow-android = "0.2.3"
play-core = "0.2.3"

[patch.crates-io]
miniquad = { git = "https://github.com/not-fl3/miniquad", rev = "d67ffe6950cf73df307e2d23aaa4726f14399985" }

[package.metadata]
app_name = "Macroquad"
assets = ["assets"]
icon = "assets/icon.png"

[package.metadata.android]
app_wrapper = "quad"
release_build_targets = ["aarch64-linux-android"]
plugins_remote = ["com.crossbow.admob:admob:0.2.3", "com.crossbow.play_core:play_core:0.2.3"]

[package.metadata.android.manifest]
package = "com.crossbow.example.permissions"

[package.metadata.android.manifest.uses_sdk]
min_sdk_version = 19
target_sdk_version = 31

[[package.metadata.android.manifest.uses_permission]]
name = "android.permission.INTERNET"

[[package.metadata.android.manifest.application.meta_data]]
name = "com.google.android.gms.ads.APPLICATION_ID"
value = "ca-app-pub-3940256099942544~3347511713"

[package.metadata.apple]
release_build_targets = ["aarch64-apple-ios", "x86_64-apple-ios"]

main.rs:

use macroquad::prelude::*;

use crossbow_android::*;

#[macroquad::main("project_name")]
async fn main() {
  let crossbow = CrossbowInstance::new();
  // info!("initializing play core");
  // let play_core: play_core::PlayCorePlugin = crossbow.get_plugin().unwrap();
  info!("initializing admob");
  let admob: admob_android::AdMobPlugin = crossbow.get_plugin().unwrap();

  loop {
    clear_background(WHITE);
    draw_circle(100., 100., 100., BLUE);
    next_frame().await;
  }
}

I'm not experienced android developer and I know it wasn't good idea to start with developing mobile apps in rust (in current mobile ecosystem state), but I like this technology so much, that's why we are here :)

I hope it will help you figure out the problem

enfipy commented 1 year ago

Hey, I succeeded in running your Cargo.toml (also I changed the main.rs code to the following):

use macroquad::prelude::*;
use macroquad::ui::{hash, root_ui, Skin};

use crossbow_android::*;

#[macroquad::main("project_name")]
async fn main() {
  let crossbow = CrossbowInstance::new();
  // info!("initializing play core");
  // let play_core: play_core::PlayCorePlugin = crossbow.get_plugin().unwrap();
  info!("initializing admob");
  let admob: admob_android::AdMobPlugin = crossbow.get_plugin().unwrap();

  let skin = get_skin();
  let window_skin = skin.clone();

  loop {
    clear_background(WHITE);

    root_ui().push_skin(&window_skin);
    root_ui().window(hash!(), vec2(0.0, 50.0), vec2(1000.0, 1000.0), |ui| {
        if ui.button(vec2(-15.0, 250.0), "Show ad") {
            if !admob.is_initialized().unwrap() {
                println!("Calling AdMob::initialize()");
                admob.initialize(true, "G", false, true).unwrap();
            }
            if admob.is_initialized().unwrap() && !admob.is_interstitial_loaded().unwrap() {
                println!("Calling load_interstitial()");
                admob.load_interstitial("ca-app-pub-3940256099942544/1033173712").unwrap();
            }
            if admob.is_interstitial_loaded().unwrap() {
                println!("Calling show_interstitial()");
                admob.show_interstitial().unwrap();
            }
        }
    });
    root_ui().pop_skin();

    // draw_circle(100., 100., 100., BLUE);

    next_frame().await;
  }
}

fn get_skin() -> Skin {
  let label_style = root_ui()
      .style_builder()
      .text_color(Color::from_rgba(180, 180, 120, 255))
      .font_size(30)
      .build();
  let window_style = root_ui()
      .style_builder()
      .background_margin(RectOffset::new(20.0, 20.0, 10.0, 10.0))
      .margin(RectOffset::new(-20.0, -30.0, 0.0, 0.0))
      .build();
  let button_style = root_ui()
      .style_builder()
      .background_margin(RectOffset::new(37.0, 37.0, 5.0, 5.0))
      .margin(RectOffset::new(10.0, 10.0, 0.0, 0.0))
      .text_color(Color::from_rgba(180, 180, 100, 255))
      .font_size(40)
      .build();
  let editbox_style = root_ui()
      .style_builder()
      .background_margin(RectOffset::new(0., 0., 0., 0.))
      .text_color(Color::from_rgba(120, 120, 120, 255))
      .color_selected(Color::from_rgba(190, 190, 190, 255))
      .font_size(50)
      .build();
  Skin {
      editbox_style,
      window_style,
      button_style,
      label_style,
      ..root_ui().default_skin()
  }
}

So the result is the following:

Screenshot 2023-01-02 at 13 06 55 Screenshot 2023-01-02 at 13 03 35

@kacper-cholewinski Can you try running this command: crossbundle run android --log? The --release flag probably has some issues.

kacper-cholewinski commented 1 year ago

So, I copied your code and still have same issue.

I think it could be important to add, that im using -s=native-apk flag, cause without it I got some error during daemon initialization (with or without plugins): image

EDIT: Also, it could be worth mentioning, that I'm testing on physical device (Xiaomi Redmi 9) using adb

enfipy commented 1 year ago

@kacper-cholewinski Look, strategy native-apk builds it without gradle. It will not add plugins. Can you try build with command I mentioned and paste error log?

kacper-cholewinski commented 1 year ago

I pasted screenshot of error above

enfipy commented 1 year ago

Looks like something is wrong with generated Gradle project. It's very hard to understand what the problem is from this error message as we with @Heezay don't have this problem... I wonder, perhaps you can try to upload somewhere generated Gradle project so that I will take a look.

kacper-cholewinski commented 1 year ago

I'm not sure if I know what you mean, but: https://github.com/kacper-cholewinski/crossbow-plugins There is my whole workspace with target folder and Cargo.lock included, I hope it would help.