Почему крошится приложение?

Рейтинг: 0Ответов: 0Опубликовано: 04.03.2023

Суть такова, пытаюсь интегрировать UnityAds баннер в приложение но оно при запуске крошится с ошибкой. С UnityAds некогда ранее не работал.

Ошибка

2023-03-04 21:58:22.562 8667-8667/com.buratinoapps.tictactoe E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.buratinoapps.tictactoe, PID: 8667
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/services/identifiers/SessionId;

Указывает на строку UnityAds.initialize(getApplicationContext(), unityGameID, testMode, null);

Мой xml макет

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBg"
    tools:context=".MainActivity">


    <RelativeLayout
        android:id="@+id/topBanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/topBanner"/>


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorBottomNavigation"
        app:itemIconTint="@color/colorButton"
        app:itemTextColor="@color/colorWhite"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navmenu" />

</androidx.constraintlayout.widget.ConstraintLayout>

Активити

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    // UnityAds
    String AppId = String.valueOf(R.string.AppId);
    String AdIdTop = String.valueOf(R.string.AdIdTop);
    String AdIdBottom = String.valueOf(R.string.AdIdBottom);


    Boolean AppAds = true;

    // This banner view object will be placed at the top of the screen:
    BannerView topBanner;
    // This banner view object will be placed at the bottom of the screen:
    BannerView bottomBanner;
    // View objects to display banners:
    RelativeLayout topBannerView;
    RelativeLayout bottomBannerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);

        // Unity SDK Settings...
        UnityAds.initialize(MainActivity.this, AppId, AppAds, null);

        // Load Unity Banners
        // Create the top banner view object:
        topBanner = new BannerView(MainActivity.this, AdIdTop, new UnityBannerSize(320, 50));
        // Set the listener for banner lifecycle events:
        topBannerView = findViewById(R.id.topBanner);
        LoadBannerAd(topBanner, topBannerView);

        replaceFragment(new HomeFragment());
        binding.bottom.setOnItemSelectedListener(item -> {

            switch (item.getItemId()){

                case R.id.home:
                    replaceFragment(new HomeFragment());
                    break;

                case R.id.donate:
                    replaceFragment(new DonateFragment());
                    break;

                case R.id.policy:
                    replaceFragment(new PrivacyFragment());
                    break;

                case R.id.share:
                    Intent intent = new Intent(
                            Intent.ACTION_SEND
                    );
                    intent.setType("text/plain");
                    String Body = "Download this App";
                    String Sub = "https://play.google.com/store/apps/details?id=com.buratinoapps.tictactoe";
                    intent.putExtra(Intent.EXTRA_TEXT, Body);
                    intent.putExtra(Intent.EXTRA_TEXT, Sub);
                    startActivity(Intent.createChooser(intent, "Share using"));
                    break;
            }
            return true;
        });
    }

    private void replaceFragment(Fragment fragment){

        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame_layout, fragment);
        fragmentTransaction.commit();
    }

    public void LoadBannerAd(BannerView bannerView, RelativeLayout bannerLayout) {
        // Request a banner ad:
        bannerView.load();
        // Associate the banner view object with the banner view:
        bannerLayout.addView(bannerView);
    }
}

Ответы

Ответов пока нет.