简体   繁体   English

如何在 Ionic 中使用电容器使用 admob?

[英]How to use admob using capacitor in Ionic?

I have problems with admob-free plugin.我在使用 admob-free 插件时遇到问题。 I executed these command in a ionic 4 project:我在 ionic 4 项目中执行了这些命令:

    ionic start myapp sidemenu
    ionic capacitor add android 
    ionic cordova plugin add cordova-plugin-admob-free  --save --variable ADMOB_APP_ID="myadmobid"
    npm install @ionic-native/admob-free
    Ionic capacitor sync android 
    ionic capacitor run android 

when I test the program on my device android studio shows the next error and the app stop.当我在我的设备上测试程序时,android studio 显示下一个错误并且应用程序停止。

 FATAL EXCEPTION: main
    Process: com.danieltrevino.myapp, PID: 29617
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzur;
        at com.google.android.gms.ads.BaseAdView.<init>(Unknown Source:3)
        at com.google.android.gms.ads.AdView.<init>(Unknown Source:1)
        at name.ratson.cordova.admob.banner.BannerExecutor$1.run(BannerExecutor.java:70)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:280)
        at android.app.ActivityThread.main(ActivityThread.java:6706)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: com.google.android.gms.internal.zzur
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312

I read that the problem could be about google play services versions我读到问题可能与谷歌播放服务版本有关

android/build.gradle android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android/capacitor-cordova-android-plugins/build.gradle android/capacitor-cordova-android-plugins/build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    google()
    jcenter()
    mavenCentral()
    flatDir{
        dirs 'src/main/libs', 'libs'
    }
}

dependencies {
    implementation fileTree(dir: 'src/main/libs', include: ['*.jar'])
    implementation 'org.apache.cordova:framework:7.0.0'
    // SUB-PROJECT DEPENDENCIES START
    implementation "com.google.android.gms:play-services-base:11.0.4"
    implementation "com.google.android.gms:play-services-ads:11.0.4"
    // SUB-PROJECT DEPENDENCIES END
}

// PLUGIN GRADLE EXTENSIONS START
apply from: "cordova.variables.gradle"
// PLUGIN GRADLE EXTENSIONS END

for (def func : cdvPluginPostBuildExtras) {
    func()
}

I am following the next tutorial , do you know some solution for this?我正在关注下一个教程,你知道一些解决方案吗?

The admob plugin has some issues due to the new ionic 4/5 version of the framework.由于框架的新 ionic 4/5 版本,admob 插件存在一些问题。 For the ones using capacitor, there's two plugins( community plugins) that are avalaible now, they're pretty new so you might find some bugs there.对于使用电容的人,现在有两个插件(社区插件)可用,它们很新,所以你可能会在那里发现一些错误。

Those two plugins (at the moment of writing this, so you can find more than two) are found in the docs capacitor's documentation这两个插件(在撰写本文时,因此您可以找到两个以上)可在 docs电容器的文档中找到

The two plugins right now are:现在的两个插件是:

plugin 1 plugin 2插件 1插件 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ModalPage Ionic 6/Capacitor 中使用自定义组件? - How to use a custom component in a ModalPage Ionic 6/Capacitor? Ionic Capacitor Admob 插件 loadAd null 对象参考 - Ionic Capacitor Admob plugin loadAd null object reference 如何使用电容器运行 Ionic 项目? - How to run Ionic project with capacitor? 使用离子和电容器创建的深层链接不起作用 - Deeplink created using ionic and capacitor is not working 如何使用 Ionic Capacitor 打包托管的 Web 应用程序 - How to package a hosted web app with Ionic Capacitor AdMob,如何使用AdMob中介 - AdMob, how to use AdMob Mediation 使用电容器在真正的安卓设备上运行 Ionic 5 应用程序 - Run Ionic 5 app on real android device using capacitor 我已经使用 ionic 和 angular 构建了一个简单的应用程序? 如何在不使用 android studio 的情况下生成带电容器的 apk 文件? - I have build an simple app using ionic with angular ? How do i generate apk file with capacitor without using android studio? 带有 .net 核心后端的 Ionic 使用电容器到 android 应用程序 - Ionic with .net core backend to android app using capacitor 使用具有正数和负数的 ngClass 并在 Ionic/Capacitor 中更改颜色 - Using ngClass with positive and negative numbers and change color in Ionic/Capacitor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM