Skip to content

Instantly share code, notes, and snippets.

@valery-iwanofu
Last active December 8, 2022 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valery-iwanofu/26a53d82835616e37273787bb4d7720a to your computer and use it in GitHub Desktop.
Save valery-iwanofu/26a53d82835616e37273787bb4d7720a to your computer and use it in GitHub Desktop.
Yandex Mobile Ads в Ren'Py игре
# добавить в конец файла
android.useAndroidX=true
android.enableJetifier=true
// убрать данный импорт
import android.support.annotation.NonNull;
// удалить упоминания NonNull
@NonNull
android{
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
dependencies {
...
// https://github.com/yandexmobile/yandex-ads-sdk-android/issues/126
implementation 'androidx.core:core-ktx:1.6.0'
implementation ('com.yandex.android:mobileads:5.2.0') {
exclude group: 'androidx.core', module: 'core'
exclude group: 'androidx.core', module: 'core-ktx'
}
...
}
// УСТАРЕЛО. Лучше создавать баннеры напрямую из питон кода
// секция импорта
...
import com.yandex.mobile.ads.banner.AdSize;
import com.yandex.mobile.ads.banner.BannerAdEventListener;
import com.yandex.mobile.ads.banner.BannerAdView;
import com.yandex.mobile.ads.common.AdRequest;
import com.yandex.mobile.ads.common.AdRequestError;
import com.yandex.mobile.ads.common.ImpressionData;
import com.yandex.mobile.ads.common.MobileAds;
...
// тело класса
private static final String YANDEX_TAG = "YANDEX_ADDS_RENPY";
private static final String ADD_ID = "R-M-DEMO-320x50";
protected void onCreate(Bundle savedInstanceState) {
...
MobileAds.initialize(this, () -> {
Log.v(YANDEX_TAG, "Adds initialized");
});
BannerAdView adView = new BannerAdView(this);
{
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
adView.setLayoutParams(layoutParams);
}
adView.setAdSize(AdSize.stickySize(-1));
adView.setAdUnitId(ADD_ID);
adView.setBannerAdEventListener(new BannerAdEventListener() {
@Override
public void onAdLoaded() {
Log.v(YANDEX_TAG, "Add view load success");
}
@Override
public void onAdFailedToLoad(AdRequestError adRequestError) {
Log.e(YANDEX_TAG, "Add view load error: "+adRequestError.getDescription());
}
@Override
public void onAdClicked() {
}
@Override
public void onLeftApplication() {
}
@Override
public void onReturnedToApplication() {
}
@Override
public void onImpression(ImpressionData impressionData) {
}
});
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);
mLayout.addView(adView);
}
android {
defaultConfig {
...
multiDexEnabled true
...
}
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment