[英]Conflict with dependency in project ':app'. Resolved versions for app (15.0.2) and test app (12.0.1) differ (possibly onesignal&firebase issue)
I cant seem to build gradle for my app on Android Studio 3.0.1 (generate apk works). 我似乎无法在Android Studio 3.0.1上为我的应用程序构建gradle(生成apk工程)。 Below was the build output.
下面是构建输出。
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.google.firebase:firebase-messaging' in project ':app'.
Resolved versions for app (15.0.2) and test app (12.0.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 23s
Here is the build.gradle file contents. 这是build.gradle文件的内容。
UPDATE 21.8.2018: 更新21.8.2018:
I notice in the external libraries, I have a conflict 我注意到在外部库中,我有冲突
I found out that I can generate the apk (Build APK) eventhough gradle produce the conflict error. 我发现我可以生成apk(Build APK)eventHough gradle产生冲突错误。 The way to remove gradle error is to remove/comment this line:
删除gradle错误的方法是删除/注释此行:
implementation 'com.google.android.gms:play-services-places:15.0.1'
but then APK wont compile. 但然后APK不会编译。 It used to work, I realized this problem may have happened after I had to include Firebase in another project (cordova based Android app) that used the same Android Studio.
它曾经工作,我意识到这个问题可能发生在我必须将Firebase包含在另一个使用相同Android Studio的项目(基于cordova的Android应用程序)之后。 This problem does not happen to my other colleague machine.
这个问题不会发生在我的其他同事机器上。 How do I really solve this ?
我该如何解决这个问题? Thanks
谢谢
Please post your build.gradle file. 请发布您的build.gradle文件。 But without seeing it my guess is that you have an
implementation
and testImplementation
that have different versions for com.google.firebase:firebase-messaging
但是没有看到我的猜测是你有一个
implementation
和testImplementation
有com.google.firebase:firebase-messaging
不同版本com.google.firebase:firebase-messaging
Try to force the version of your firebase dependency using below configuration 尝试使用以下配置强制使用firebase依赖项的版本
android {
configurations.all {
resolutionStrategy.force 'com.google.firebase:firebase-core:16.0.1'
}
}
It looks like a transitive dependency issue. 它看起来像一个传递依赖问题。 Both
com.google.android.gms:play-services
and com.onesignal:OneSignal
use com.google.firebase:firebase-messaging
, but they're probably importing different versions. com.google.android.gms:play-services
和com.onesignal:OneSignal
使用com.google.firebase:firebase-messaging
com.onesignal:OneSignal
com.google.firebase:firebase-messaging
,但他们可能导入了不同的版本。 I'd recommend upgrade to use the latest versions of these libraries. 我建议升级以使用这些库的最新版本。
It seems like there are two libraries that depend on firebase-messaging library, and they're depending on different versions. 似乎有两个库依赖于firebase-messaging库,它们依赖于不同的版本。 To find out which ones they are, go to Terminal window in your Android Studio and run this command:
要找出它们是哪些,请转到Android Studio中的终端窗口并运行以下命令:
./gradlew app:dependencies
./gradlew app:依赖项
That'll show you all the dependencies in your project in a tree structure. 这将在树结构中向您显示项目中的所有依赖项。 Once you detect which libraries add the duplicate library, you can try one of these:
一旦检测到哪些库添加了重复的库,您可以尝试以下方法之一:
1) Check for the other versions of the parent dependencies in your build.gradle which both use the same version of the transitive duplicate dependency. 1)检查build.gradle中其他版本的父依赖项,它们都使用相同版本的传递重复依赖项。
2) Exclude the dependency with the lower version from the parent dependency. 2)从父依赖项中排除较低版本的依赖项。 Example:
例:
implementation('com.example.abc:def:1.0.0') {
exclude group: 'com.google.firebase', module: 'firebase-messaging'
}
3) Enforce a fixed version w/ a resolution strategy: 3)实施具有解决策略的固定版本:
configurations.all {
resolutionStrategy {
force com.google.firebase:firebase-messaging:15.0.2
}
}
Dependency OneSignal is using old version of play-service
. 依赖性OneSignal正在使用旧版本的
play-service
。
You have these ways to solve this. 你有这些方法来解决这个问题。
play-service
from OneSignal and force to use the latest- you are using. play-service
并强制使用您正在使用的最新版本。 (As @gizembrh answer ). play-service
version as same version of OneSignal. play-service
版本降级为相同版本的OneSignal。 ( The easiest I think ) I think 3rd option best suits to you. 我认为第三种选择最适合你。 Because you just need to downgrade your play-service version.
因为您只需要降级播放服务版本。 See OneSignal
build.gradle
play-service version 请参阅OneSignal
build.gradle
播放服务版本
def playServicesVersion = '12.0.0'
implementation "com.google.android.gms:play-services-places:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
Also use in your project level build.gradle , use below version of google-services
. 也可以在项目级build.gradle中使用,使用以下版本的
google-services
。 See OneSignal build.gradle
google-services version . 请参阅OneSignal
build.gradle
google-services版本 。
classpath 'com.google.gms:google-services:4.0.1'
If you do above both changes in your gradle, you will not face this error any more. 如果您在gradle中进行了上述两项更改,则不会再出现此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.