Add an “exclude module” rule to an entry in plugin

2020-04-11 11:34发布

I'm stucking with this error trying to build my phonegap project

enter image description here As far I know this error because there is a library is set twice in the project. I check all my libraries and I found only one library causing this(found in one of my plugins)

 <framework src="com.android.support:design:23.4.0"/>

The thing is, can I set an exclude module rule in the plugin.xml file? I think I need to exclude com.android.supportv4

2条回答
Emotional °昔
2楼-- · 2020-04-11 12:03

I would highly recommend https://github.com/dpa99c/cordova-android-support-gradle-release which is a "plugin to align various versions of the Android Support libraries specified by other plugins".

They use a clever gradle dependency resolution to solve the problem:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group in ['com.android.support'] && !(details.requested.name in ['multidex', 'multidex-instrumentation'])) { details.useVersion "26.1.0"}
    }
}

This avoids the problem of removing all Android support libs, which can lead plugins having missing dependencies/failing gradle syncs.

查看更多
成全新的幸福
3楼-- · 2020-04-11 12:05

Finally I resolved it, I had to create a build-extras.gradle file in my plugin containing the following lines:

configurations {
  all*.exclude group: 'com.android.support', module: 'support-v4'
  all*.exclude group: 'com.android.support', module: 'support-annotations'}

Then this gradle file need to imported in plugin.xml file using:

<framework src="build-extras.gradle" custom="true" type="gradleReference" />
查看更多
登录 后发表回答