[英]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:现在的两个插件是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.