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

Multiple dex files error // using other plugins with google-play-services #187

Closed eftas-apps closed 6 years ago

eftas-apps commented 6 years ago

Hi,

first of all I'd like to say that this plugin is superb and works as supposed. When digging deeper, I wanted to use push notification via firebase. I used phonegap-plugin-push. Unfortunately following error occurs.

transformDexArchiveWithDexMergerForDebug
Dex: Error converting bytecode to dex:

Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzben;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzben;

com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzben;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)

In the GitHub push plugins GitHub page following is stated.

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md#multidex

Seems I could narrow it down to this plugin causing this error. Using one of the plugins works fine. But both together give a problem. Is there any possible solution?

P.S.: I already tried changing the play-services version as hinted in the readme.

ratson commented 6 years ago

Unfortunately, I don't have time to setup whole new project to testing it out. If you could create a simple repo demonstrating the problem, I would clone and see if could find any fix.

ivanov84 commented 6 years ago

@ratson I replace this code: cordova.system.library.8=com.google.android.gms:play-services-base:11.0.4 cordova.system.library.9=com.google.android.gms:play-services-ads:11.0.4

in project.properties

With this: cordova.system.library.8=com.google.android.gms:play-services-base:11.+ cordova.system.library.9=com.google.android.gms:play-services-ads:11.+

And: BUILD SUCCESSFUL

rafaellop commented 6 years ago

You've got info about this in the README:

Customize Google Play Services versions (Android only)

The default PLAY_SERVICES_VERSION is set to 11.0.4. If you need a different version, edit config.xml with following,

<plugin name="cordova-admob-sdk" spec="~0.13.1">
    <variable name="PLAY_SERVICES_VERSION" value="11.6.0" />
</plugin>
eftas-apps commented 6 years ago

@rafaellop I already mentioned that I tried that and that it did not help. Setting the play-services handles another issue. @ivanov84 is your post related to my issue? I'm not sure how to include your answer in my code. @ratson basically it's just creating a simple cordova app, adding phonegap-plugin-push, adding this plugin and trying to build it on android (I use 6.4.0). The build process will not succeed.

eftas-apps commented 6 years ago

oh, and my apologies. Thanks for your quick answers!

tominou commented 6 years ago

@eftas-apps Can you show me your platform/android/project.properties

eftas-apps commented 6 years ago

Hi @tominou

thanks for your help. I pasted some files you might feel interesting.

config.xml (parts)

<plugin name="phonegap-plugin-push" spec="^2.1.3">
        <variable name="FCM_VERSION" value="11.6.2" />
</plugin>
<plugin name="cordova-admob-sdk" spec="^0.15.1">
        <variable name="PLAY_SERVICES_VERSION" value="11.6.2" />
</plugin>
<plugin name="cordova-plugin-admob-free" spec="^0.15.0" />
<engine name="android" spec="~6.4.0" />

project.properties

target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-base:11.0.4
cordova.system.library.2=com.google.android.gms:play-services-ads:11.0.4
cordova.system.library.3=com.android.support:support-v13:26.+
cordova.system.library.4=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.5=com.google.firebase:firebase-messaging:11.6.2
cordova.gradle.include.1=phonegap-plugin-push/duelmenerzeitung-push.gradle

duelmenerzeitung-push.gradle

import java.util.regex.Pattern

def doExtractStringFromManifest(name) {
    def manifestFile = file("AndroidManifest.xml")
    if (!manifestFile.exists()) {
      manifestFile = file("src/main/AndroidManifest.xml")
    }
    def pattern = Pattern.compile(name + "=\"(.*?)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    return matcher.group(1)
}

android {
    defaultConfig {
        multiDexEnabled true
        applicationId = doExtractStringFromManifest("package")
    }
}

buildscript {
    repositories {
      jcenter()
            mavenLocal()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:+'
      classpath 'com.google.gms:google-services:3.0.0'
  }
}

// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

Thanks for your support!

tominou commented 6 years ago

Hi @eftas-apps

Edit your project.properties as follow:

target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-base:12.0.1
cordova.system.library.2=com.google.android.gms:play-services-ads:12.0.1
cordova.system.library.3=com.android.support:support-v13:26.+
cordova.system.library.4=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.5=com.google.firebase:firebase-messaging:12.0.1
cordova.gradle.include.1=phonegap-plugin-push/duelmenerzeitung-push.gradle

Then try to build.

eftas-apps commented 6 years ago

Hi @tominou

seems gradle does not find the library. Do I need to add another repo?

Could not find com.google.android.gms:play-services-base:12.1.0 Could not find com.google.android.gms:play-services-ads:12.1.0 Could not find com.google.firebase:firebase-messaging:12.1.0. Could not find com.google.firebase:firebase-core:12.1.0

eftas-apps commented 6 years ago

Update: seems to work with 12.0.0 but gives me this error

BUILD FAILED in 18s
39 actionable tasks: 37 executed, 2 up-to-date
(node:1384) UnhandledPromiseRejectionWarning: Error: .../platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/cliffpereira/Documents/git/2852-DuelmenerZeitung-App/platforms/android/src/name/ratson/cordova/admob/rewardvideo/RewardVideoListener.java:13: error: RewardVideoListener is not abstract and does not override abstract method onRewardedVideoCompleted() in RewardedVideoAdListener
class RewardVideoListener implements RewardedVideoAdListener {
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/cliffpereira/Documents/git/2852-DuelmenerZeitung-App/platforms/android/src/com/adobe/phonegap/push/PushPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
tominou commented 6 years ago

Sorry for the wrong version. The latest is 12.0.1 indeed. Please remove the plugin then add it back, a bug has been fixed recently.

eftas-apps commented 6 years ago

@tominou

Thanks a lot! That did the trick.

eftas-apps commented 6 years ago

Although this seems like a tiny hack, I'll close the issue. This might help others having the same issue.

tominou commented 6 years ago

Actually you can set the play service version in your config.xml `

`

But it also depends on other plugins so we can not help more about it

eftas-apps commented 6 years ago

I did that already. See my post further up where I posted parts of my config.xml. Unfortunately that did not help.

tominou commented 6 years ago

Yes because of the plugin using com.google.firebase:firebase-messaging you need to configure it to use the same version of play services (12.0.1), either in your config.xml or project.properties if there is not option to do it in config.xml.

However i am glad it is now working for you ^^

dsilvestregil commented 5 years ago

Use this plugin, it works for me: https://www.npmjs.com/package/cordova-play-services-version-adapter