ratson / cordova-plugin-admob-free

New development has been moved to "admob-plus-cordova", https://github.com/admob-plus/admob-plus/tree/master/packages/cordova
https://github.com/admob-plus/admob-plus
MIT License
499 stars 214 forks source link

AdMobFree crahsed on .prepare() #216

Open netidjen opened 6 years ago

netidjen commented 6 years ago

This is my ionic info result: cli packages: (/home/user/app/node-v8.9.4-linux-x64/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 3.1.6
Cordova Platforms  : android 6.4.0
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.1.1
Node              : v8.9.4
npm               : 6.0.0 
OS                : Linux 4.13

Environment Variables:

ANDROID_HOME : /home/user/Android/Sdk

Misc:

backend : pro

And this is the cordova plugins:

cc.fovea.cordova.purchase 7.1.3 "Purchase" com-sarriaroman-photoviewer 1.1.16 "PhotoViewer" cordova-admob-sdk 0.16.0 "AdMob SDK" cordova-plugin-admob-free 0.16.1 "Cordova AdMob Plugin" cordova-plugin-android-downloadmanager 0.5.0 "cordova-plugin-android-downloadmanager" cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-camera 4.0.2 "Camera" cordova-plugin-contacts 3.0.1 "Contacts" cordova-plugin-device 1.1.7 "Device" cordova-plugin-fcm 2.1.2 "FCMPlugin" cordova-plugin-file 6.0.1 "File" cordova-plugin-file-transfer 1.7.1 "File Transfer" cordova-plugin-ionic-webview 1.2.0 "cordova-plugin-ionic-webview" cordova-plugin-sms 1.0.5 "SMS" cordova-plugin-splashscreen 4.1.0 "Splashscreen" cordova-plugin-statusbar 2.4.1 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-plugin-x-socialsharing 5.4.0 "SocialSharing" cordova-promise-polyfill 0.0.2 "cordova-promise-polyfill" cordova.plugins.diagnostic 4.0.5 "Diagnostic" es6-promise-plugin 4.2.2 "Promise" ionic-plugin-keyboard 2.2.1 @@"Keyboard"

My problem is, when i try to show the banner it always stopping my apps. I've try to develop admobfree on a separated project, and it works. I'm pretty sure that i've implement the same code, the different is only on android engine version (mine is 6.4.0) & play-services-ads version (mine is 9.0.0) that required by my system. Is that the problem? @ratson

ivanov84 commented 6 years ago

@netidjen try to remove all plugins and run again. backup first

netidjen commented 6 years ago

@ivanov84 nothing is change, i already renewing the plugins & android platforms. Any suggestion?

ivanov84 commented 6 years ago

@netidjen not renew. Remove all plugin. Let stay only 1 plugin with admob-free. Then add one by one plugin to define after what prepare() crushes.

rafaellop commented 6 years ago

You probably have a wrong version of Google Play Services. The plugin requires a specific version and if it is different it compiles properly but crashes at prepare. Had this trouble too. You must find references to the services version in your plugins/platforms and change the + instead of version number.

And by the way, the method suggested in the docs to add variable with the preferred version to the config.xml simply doesn't change anything.

netidjen commented 6 years ago

@rafaellop Did you mean to edit the gms:play-service- version on project.properties with "+"? if so, then this is the result: `FAILURE: Build failed with an exception.

coolman7 commented 6 years ago

I have exactly same problem. I have Google Play Services SDK version 49, so I added following lines to config.xml but nothing has changed:

    <plugin name="cordova-admob-sdk" spec="~0.16.0">
        <variable name="PLAY_SERVICES_VERSION" value="49" />
    </plugin>
coolman7 commented 6 years ago

I noticed that If I use this plugin with the following Google Analytics plugin, this problem happens. If I don't use Admob plugin, I can use Google Analytics plugin. If I don't use Google Analytics plugin, I can use AdMob plugin. But I can't use both of them at the same time.

https://github.com/danwilson/google-analytics-plugin https://ionicframework.com/docs/native/google-analytics/

@netidjen Do you have same situation? Do you use Google Analytics plugin too?

rafaellop commented 6 years ago

@netidjen I have changed in project.properties

cordova.system.library.4=com.google.android.gms:play-services-base:+
cordova.system.library.5=com.google.android.gms:play-services-ads:+

In the effect you should have the following in the \platforms\android\build.gradle:

dependencies {
 [....]
    compile "com.google.android.gms:play-services-base:+"
    compile "com.google.android.gms:play-services-ads:+"
}

If you don't have + here there are other places you should replace this. Then cordova clean then cordova build. I also had errors if I tried to build without cleaning first.

netidjen commented 6 years ago

I noticed that If I use this plugin with the following Google Analytics plugin, this problem happens. If I don't use Admob plugin, I can use Google Analytics plugin. If I don't use Google Analytics plugin, I can use AdMob plugin. But I can't use both of them at the same time.

https://github.com/danwilson/google-analytics-plugin https://ionicframework.com/docs/native/google-analytics/

@netidjen Do you have same situation? Do you use Google Analytics plugin too?

@coolman7 i have no Google Analytics plugin

coolman7 commented 6 years ago

@netidjen So we should have different problems.

netidjen commented 6 years ago

@rafaellop after doing codova clean & build, the problem is still the same:

What went wrong: Execution failed for task ':processDebugGoogleServices'. Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0. `

rafaellop commented 6 years ago

Check the dependencies in the build.gradle file. This will tell you what versions it tries to link. Then search for the references.

netidjen commented 6 years ago

@rafaellop don't you remember that the dependencies in build.gradle is depend on project.properties? Once i change the version in project.propertie, then on build.gradle will be affacted right?

rafaellop commented 6 years ago

I think so, but project.properties is controlled by plugins so if you update any that modifies it, it will be changed. Unfortunately I don't know better way. I've got on my todo to check this when I build for Android. Would be great if the config.xml params worked like announced but they aren't.

netidjen commented 6 years ago

I agree with you sir, but i don't know exactly what version of play-service in build.gradle needed. Since i changed the version from 11.0.4 to 9.0.0 my app crashed when try to show some ads. If i change the version number to "+" then another problem above appears.

BanwariLal commented 6 years ago

I had the same issue, the app was crashing on prepare(). It worked fine when I removed plugin cordova-plugin-firebase. Is there anyway to get this fixed.

sonugpc commented 6 years ago

I am having the same issue with cordova-plugin-firebase and admob-free uninstalling one of them fix the issue. is there any other way?

coolman7 commented 6 years ago

As far as I understand common plugin is admob-free. admob-free and google analytics or admob-free and firebase does not work together. I guess the problem should be inside admob-free code.

coolman7 commented 6 years ago

On the other hand cordova-admob-pro plugin does not have this problem. It can run with cordova-plugin-google-analytics plugin.

paulstelzer commented 5 years ago

I am using cordova-plugin-firebase and cordovoa-plugin-admob-free at the same time and everything works (prepare and launch of banner, interstitial and rewarded video) using the latest version of play-services-base and play-services-ads

PS: If the banner prepare fails, check that you are using a correct size-property of the banner

puffnir commented 5 years ago

Any one solve this issue? I've found this but it didn't help too: https://github.com/dpa99c/cordova-android-play-services-gradle-release

Nir.

netidjen commented 5 years ago

@puffnir Did you use FCM/Firebase plugin?

mikealo commented 5 years ago

@netidjen maybe i'm late, anyway this may be usefull to someone else

the conflict it was raised by this plugin which use firebase https://github.com/phonegap/phonegap-plugin-push

in build.gralde(Module: app) you have to check the dependecies section and change them to a common version:

compile "com.google.firebase:firebase-messaging:11.6.2" compile "com.google.android.gms:play-services-base:11.6.2" compile "com.google.android.gms:play-services-ads:11.6.2"

i didn't test this plugin combos: https://github.com/dpa99c/cordova-android-play-services-gradle-release https://github.com/dpa99c/cordova-android-firebase-gradle-release

but it seems promising as you can manually set the version for every google service and it should fix every future problem if you change anything in the project without manually changing the versions every time

PalakjainJain commented 5 years ago

Any one found the solution??? I tried all the options mention above. But nothing is working for me :-(

paulstelzer commented 5 years ago

I can just give the advice to use the latest version of the Play Services:

    <plugin name="cordova-admob-sdk" spec="^0.18.0">
        <variable name="PLAY_SERVICES_VERSION" value="+" />
    </plugin>

And afterwards make sure that the version is set in platforms/android/app/build.gradle:

    compile "com.google.android.gms:play-services-base:+"
    compile "com.google.android.gms:play-services-ads:+"
m-itkdev commented 5 years ago

@paulstelzer Thank you for useful information!

Where should I write following code to?

    <plugin name="cordova-admob-sdk" spec="^0.18.0">
        <variable name="PLAY_SERVICES_VERSION" value="+" />
    </plugin>

cordova-plugin-admob-free does not have platforms/android/app/build.gradle. Should I create it myself?

ivanov84 commented 5 years ago

@m-itkdev in plugin directory. Then remove platform and add again with modifed plugin folder. P.S.: not cordova-plugin-admob-free but cordova-admob-sdk

paulstelzer commented 5 years ago

Where should I write following code to?

    <plugin name="cordova-admob-sdk" spec="^0.18.0">
        <variable name="PLAY_SERVICES_VERSION" value="+" />
    </plugin>

Like mentioned in the documentation: https://github.com/ratson/cordova-plugin-admob-free#customize-google-play-services-versions-android-only

platforms/android/app/build.gradleshould be in your main folder structure

code_2018-09-23_08-30-57

PS: Adding the PLAY_SERVICES_VERSION cannot work sometimes, then edit it in pluigns/corodva-admob-sdk/plugin.xml to <preference name="PLAY_SERVICES_VERSION" default="+"/>

Keep in mind to remove the platforms folder afterwards and re-run cordova platform add android

If you have multiple cordova plugins who each has it's own play services version, use the following plugin: https://github.com/dpa99c/cordova-android-play-services-gradle-release

m-itkdev commented 5 years ago

@ivanov84 @paulstelzer I'm using Monaca. So my project does not have platforms/android/app/build.gradle. I wrote following code to config.xml, resolved my problem.

    <plugin name="cordova-admob-sdk" spec="^0.18.0">
        <variable name="PLAY_SERVICES_VERSION" value="+" />
    </plugin>

Thank you for your advise!

CHUN-WEI-HSU commented 5 years ago

same issue. I called prepare funciton and got following message.

    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:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)

I develop with ionic capacitor.

paulstelzer commented 5 years ago

@gesrt Keep in mind that you have to add everything manually at Capacitor - so you need to add all Java Classes to your project, you need to edit all gradle files manually. So nothing is done automatically

CHUN-WEI-HSU commented 5 years ago

you'r right. I add following class to gradle. and It works. thank you.

    implementation 'com.google.android.gms:play-services-base:16.0.1'
    implementation 'com.google.android.gms:play-services-ads:16.0.0'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
RicardoElSabio commented 4 years ago

@gesrt Where exactly are you adding those? in which gradle file?

Filavision commented 3 years ago

I had the same problem and i just change the play service version in plugins/cordova-admob-sdk/plugin.xml to:

<preference name="PLAY_SERVICES_VERSION" default="16.0.0"/>

Then remove and add the platform and it works.

mayankkataria commented 3 years ago

Instead of doing all the above solutions I'm still facing the same issue in ionic capacitor. I added + in plugin.xml, deleted and rebuilt www folder and android folder but still the results are same. Can anybody please help me?

AngelCareaga commented 3 years ago

THIS FIXED FOR ME:

Add this to build.gradle (Module: android.app)

implementation 'com.google.firebase:firebase-ads:19.6.0'

EXTRA INFO (ionic info)

I work with Capacitor / Angular

Ionic:

   Ionic CLI                     : 6.12.3 (~node/v14.15.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.2
   @angular-devkit/build-angular : 0.1100.7
   @angular-devkit/schematics    : 11.0.7
   @angular/cli                  : 11.0.7
   @ionic/angular-toolkit        : 2.3.3

Capacitor:

   Capacitor CLI   : 2.4.6
   @capacitor/core : 2.4.6

Utility:

   cordova-res : 0.15.2
   native-run  : not installed

System:

   NodeJS : v14.15.0 (/home/angelcareaga/.nvm/versions/node/v14.15.0/bin/node)
   npm    : 6.14.8
   OS     : Linux 5.8