Android Studio 3.1:混合版本可能导致运行时崩溃

时间:2018-04-20 20:38:54

标签: android gradle android-gradle

最近升级到Android Studio 3.1,同时我正在尝试Android P预览。

编译时出现以下错误:

  

所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到的版本是28.0.0-alpha1,26.1.0。示例包括com.android.support:animated-vector-drawable:28.0.0-alpha1和com.android.support:support-media-compat:26.1.0 less ...(Ctrl + F1)   有些库或工具和库的组合不兼容,或者可能导致错误。一个这样的不兼容性是使用不是最新版本的Android支持库版本(或者特别是低于targetSdkVersion的版本)进行编译。

但我无法在任何地方看到26.1.0的任何实例。我在Gradle中的所有内容都是:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'

我已尝试清除缓存,重建应用等。但错误仍然存​​在。

12 个答案:

答案 0 :(得分:40)

您需要通过将冲突的库添加到依赖项块

来覆盖冲突的库
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:customtabs:28.0.0-alpha1'
implementation 'com.android.support:support-vector-drawable:28.0.0-alpha1'
implementation 'com.android.support:support-media-compat:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'

答案 1 :(得分:11)

您需要通过将冲突的库添加到依赖项块来覆盖冲突的库。例如,您可以在错误日志中找到以下内容:

  

发现版本28.0.0-alpha1,26.1.0。例子包括   com.android.support:animated-vector-drawable:28.0.0-alpha1和   com.android.support:support-media-compat:26.1.0 less ...

您可以通过添加以下类似的库来删除错误:

dependencies {
   implementation 'com.android.support:animated-vector-drawable:28.0.0-alpha1`
   implementation 'com.android.support:support-media-compat:28.0.0-alpha1`
}

答案 2 :(得分:10)

以上警告并非特定于与媒体兼容的依赖项。他们只是添加了示例来解释该问题。通过为我添加v4 lib解决了该问题。

implementation 'com.android.support:support-v4:28.0.0'

implementation 'com.android.support:appcompat-v7:28.0.0'

无需包含

implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'

答案 3 :(得分:4)

将应用程序连接到Firebase时出现此错误。

无需添加任何内容。

只需将鼠标光标放在错误行(在下面)上,然后按Alt + Enter

(implementation 'com.android.support:appcompat-v7:28.0.0')

在列表中输入第一个选项。(无检查)

之后看起来像这样

//noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:28.0.0'

答案 4 :(得分:2)

Some dependency — perhaps playLicensing — has a transitive dependency on at least support-media-compat, for version 26.1.0.

To work around this:

  • Identify each Support Library artifact that shows up in "External Libraries" that is older than 28.0.0-alpha1. Based on the error, those older ones should all be 26.1.0, and it will be at least support-media-compat.

  • For each of those, add your own implementation line to your dependencies, requesting that artifact, but for 28.0.0-alpha1. This will cause Gradle to use the newer artifact, which happens to be what you want.

  • Hope that whatever is depending on those older artifacts will survive with the newer artifacts.

So, at minimum, you are adding:

implementation 'com.android.support:support-media-compat:28.0.0-alpha1'

答案 5 :(得分:1)

添加build.grad(Module.app)的依赖项

dependencies {

//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'

}

答案 6 :(得分:1)

//覆盖冲突的库

实现'com.android.support:support-v4:28.0.0-alpha1'

实现'com.android.support:animated-vector-drawable:28.0.0-alpha1'

实现'com.android.support:exifinterface:28.0.0-alpha1'

答案 7 :(得分:1)

就我而言,添加support-v4帮助我摆脱了警告。

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    // other dependencies
}

答案 8 :(得分:0)

您在项目中使用Firebase吗? 使用Firebase Core或Firebase应用程序索引似乎是造成此问题的原因。 我遇到了同样的问题,但是对Firebase软件包进行注释会使错误消失

//    implementation 'com.google.firebase:firebase-core:16.0.8'
//    implementation 'com.google.firebase:firebase-ads:17.2.0'
//    implementation 'com.google.firebase:firebase-appindexing:17.1.0'

答案 9 :(得分:0)

简单易用的解决方案是添加手动冲突版本的android-support。

Mixing version can lead to runtime crashes

只需关注并解决您的问题即可。

转到您的gradle脚本->在依赖项部分中构建gradle(Module:app)并实现有冲突的版本,以方便转到链接。

确保在实施过程中没有空间。

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import Qt, QRect
from PyQt5.QtGui import QScreen
from PyQt5.QtWidgets import QApplication

class KpeWindow(QtWidgets.QLabel):
    def __init__(self, parent=None):
        QtWidgets.QLabel.__init__(self,parent)

        self.selection = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle, self)


    def keyPressEvent(self, event):
        if event.key() == QtCore.Qt.Key_Return:
            rect = self.getCoverage()
            print(rect)
        self.parent().keyPressEvent(event)
    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            position = QtCore.QPoint(event.pos())
            if self.selection.isVisible():
                # visible selection
                print("UPPER: ")
                print(self.upper_left)
                print("LOWER: ")
                print(self.lower_right)
                if (self.upper_left - position).manhattanLength() < 20:
                    # close to upper left corner, drag it
                    self.mode = "drag_upper_left"
                elif (self.lower_right - position).manhattanLength() < 20:
                    # close to lower right corner, drag it
                    self.mode = "drag_lower_right"
                else:
                    # clicked somewhere else, hide selection
                    self.selection.hide()
            else:
                # no visible selection, start new selection
                self.upper_left = position
                self.lower_right = position
                self.mode = "drag_lower_right"
                self.selection.show()


    def getCoverage(self):
        localCoords = self.contentsRect()
        print("localCoords: ", localCoords)
        TL = self.mapToGlobal(localCoords.topLeft())
        BR = localCoords.bottomRight()
        # TL+BR to get width & height
        widgetCoords = QRect(TL, TL+BR)
        print("widgetCoords: ", widgetCoords)
        return widgetCoords

class MainWindow(QtWidgets.QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        QtWidgets.QMainWindow.__init__(self)

        layout = QtWidgets.QVBoxLayout(self)

        label = KpeWindow(self)
        pixmap = QScreen.grabWindow(app.primaryScreen(), app.desktop().winId())
        label.setPixmap(pixmap)
        layout.addWidget(label)
        #new
        label.setFocusPolicy(Qt.StrongFocus)
        self.setFocusProxy(label)
        label.setFocus(True)

        self.setLayout(layout)

        geometry = app.desktop().availableGeometry()

        self.setFixedSize(geometry.width(), geometry.height())
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())

您可以点击链接。

答案 10 :(得分:0)

我认为您的gradle文件具有以下依赖性。将此添加到您的应用程序级别build.gradle。

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:mediarouter-v7:28.0.0-alpha1'
implementation 'com.android.support:support-vector-drawable:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'

答案 11 :(得分:0)

就我而言,我通过将其添加到错误行下方来解决了此问题。

实现'com.android.support:support-media-compat:28.0.0'     实施'com.android.support:support-v4:28.0.0'