程序类型已经存在:android.support.v4.app.BackStackRecord [英] Program type already present: android.support.v4.app.BackStackRecord

查看:104
本文介绍了程序类型已经存在:android.support.v4.app.BackStackRecord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经升级了Android Studio,但在最新版本中发现了很多问题.

I have upgraded my Android Studio and I found many problems in the latest version.

尽管存在许多类似的问题,但我检查了所有问题的答案,但没有一个对我有用!

Although many similar questions exist, I checked the answers to all and none of them worked for me!

这是我在编译代码时遇到的错误:

Here is the error I'm facing while compiling the code:

程序类型已经存在: android.support.v4.app.BackStackRecord $ Op 消息{种类=错误,文本=程序类型已存在: android.support.v4.app.BackStackRecord $ Op,sources = [未知源文件],工具 name = Optional.of(D8)}

Program type already present: android.support.v4.app.BackStackRecord$Op Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)}

这是我的gradle文件:

Here is my gradle file:

项目:

// Top-level build file where you can add configuration options common to 

all sub-projects/modules.

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
 }

 allprojects {
 repositories {
    google()
    jcenter()
    maven {
        url "https://jitpack.io"
          }
     }
}

task clean(type: Delete) {
delete rootProject.buildDir
}

应用:

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.alcantara.bugismart"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
            }
           }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso- 
    core:3.0.1'
    implementation 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
}

您可以告诉我是否还有其他要添加的内容,以了解我在做什么或哪里出了错.

You can tell me if there is anything else to add to understand what I'm doing or where I'm wrong.

推荐答案

程序类型已经存在: android.support.v4.app.BackStackRecord $ Op 消息{种类=错误,文本=程序类型已存在: android.support.v4.app.BackStackRecord $ Op,sources = [未知源文件],工具 name = Optional.of(D8)}

Program type already present: android.support.v4.app.BackStackRecord$Op Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)}

由于重复的支持库而发生了问题.这种依赖关系:

The problem is happened because of duplicated support library. This dependency:

implementation 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'

正在使用支持库的旧版本.如果您已经拥有支持库,请尝试排除它:

is using old version of support library. Try excluding the support library if you already have it with:

// support libraries we want to use
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'

// we already have the specific support libraries. So, exclude it
implementation ('com.github.ViksaaSkool:AwesomeSplash:v1.0.0') {    
    exclude group: 'com.android.support'
    exclude module: 'appcompat-v7'
    exclude module: 'support-v4'
}

您需要使用以下命令检查依赖性:

You need to check your dependencies with the following command:

./gradlew app:dependencies

或者,您可以始终覆盖支持库版本,方法是将冲突的库添加到所需的确切版本中.

Or alternatively, you can always override the support libraries version by adding the conflicted libraries with the exact version that you want.

有一个完整的步骤可以解决添加构建依赖项 a>文档.这里摘录:

There is a full step to fixing the dependency resolution errors at the Add build dependencies documentation. Here the excerpts:

将多个依赖项添加到应用程序项目时,这些直接和传递性依赖项可能会相互冲突. Android Gradle插件会尝试妥善解决这些冲突,但是某些冲突可能会导致编译时或运行时错误.

When you add multiple dependencies to your app project, those direct and transitive dependencies might conflict with one another. The Android Gradle Plugin tries to resolve these conflicts gracefully, but some conflicts may lead to compile time or runtime errors.

为帮助您调查哪些依赖关系导致了错误,请检查应用程序的依赖项树,并查找出现多次或版本冲突的依赖项.

To help you investigate which dependencies are contributing to errors, inspect your app's dependency tree and look for dependencies that appear more than once or with conflicting versions.

如果您无法轻松识别重复的依赖项,请尝试使用Android Studio的UI搜索包含重复项类的依赖项,如下所示:

If you can't easily identify the duplicate dependency, try using Android Studio's UI to search for dependencies that include the duplicate class as follows:

  1. 从菜单栏中选择导航> 课程.
  2. 在弹出的搜索对话框中,确保已选中包括非项目项旁边的框.
  3. 键入出现在构建错误中的类的名称.
  4. 检查结果是否包含类.
  1. Select Navigate > Class from the menu bar.
  2. In the pop-up search dialog, make sure that the box next to Include non-project items is checked.
  3. Type the name of the class that appears in the build error.
  4. Inspect the results for the dependencies that include the class.

以下各节描述了您可能会遇到的不同类型的依赖关系解决错误以及如何解决它们.

The following sections describe the different types of dependency resolution errors you may encounter and how to fix them.

如果一个类在运行时类路径上多次出现,则会出现类似于以下的错误:

If a class appears more than once on the runtime classpath, you get an error similar to the following:

Program type already present com.example.MyClass

通常由于以下情况之一而发生此错误:

This error typically occurs due to one of the following circumstances:

  • 二进制依赖项包含一个库,您的应用程序还包含一个库作为直接依赖项.例如,您的应用声明了对库A和库B的直接依赖关系,但是库A已在其二进制文件中包含库B.

  • A binary dependency includes a library that your app also includes as a direct dependency. For example, your app declares a direct dependency on Library A and Library B, but Library A already includes Library B in its binary.

  • 要解决此问题,请删除库B作为直接依赖项.
  • To resolve this issue, remove Library B as a direct dependency.

您的应用在同一库上具有本地二进制依赖关系和远程二进制依赖关系.

Your app has a local binary dependency and a remote binary dependency on the same library.

  • 要解决此问题,请删除二进制依赖项之一.
  • To resolve this issue, remove one of the binary dependencies.

当Gradle解析编译类路径时,它首先解析 runtime 类路径,并使用结果确定应将哪些版本的依赖项添加到编译类路径.换句话说,运行时类路径确定对下游类路径的相同依赖项所需的版本号.

When Gradle resolves the compile classpath, it first resolves the runtime classpath and uses the result to determine what versions of dependencies should be added to the compile classpath. In other words, the runtime classpath determines the required version numbers for identical dependencies on downstream classpaths.

您的应用程序的运行时类路径还确定Gradle匹配应用程序的测试APK的运行时类路径中的依赖项所需的版本号.下图描述了类路径的层次结构:

Your app's runtime classpath also determines the version numbers that Gradle requires for matching dependencies in the runtime classpath for the app's test APK. The hierarchy of classpaths is described in figure below:

例如,当您的应用程序使用implementation

A conflict where different versions of the same dependency appears across multiple classpaths migh occur when, for example, your app includes a version of a dependency using the implementation dependency configuration and a library module includes a different version of the dependency using the runtimeOnly configuration.

在解决对运行时和编译时类路径的依赖时,Android Gradle插件3.3.0及更高版本会尝试自动修复某些下游版本冲突.例如,如果运行时类路径包括Library A版本2.0,而编译类路径包括Library A版本1.0,则插件会自动将对编译类路径的依赖关系更新为Library A版本2.0,以避免错误.

When resolving dependencies on your runtime and compile time classpaths, Android Gradle plugin 3.3.0 and higher attempt to automatically fix certain downstream version conflicts. For example, if the runtime classpath includes Library A version 2.0 and the compile classpath includes Library A version 1.0, the plugin automatically updates the dependency on the compile classpath to Library A version 2.0 to avoid errors.

但是,如果运行时类路径包括Library A版本1.0,而编译类路径包括Library A版本2.0,则该插件不会将对编译类路径的依赖关系降级为Library A版本1.0,并且您仍然会收到类似于以下内容的错误:以下:

However, if the runtime classpath includes Library A version 1.0 and the compile classpath includes Library A version 2.0, the plugin does not downgrade the dependency on the compile classpath to Library A version 1.0, and you still get an error similar to the following:

Conflict with dependency 'com.example.library:some-lib:2.0' in project 'my-library'.
Resolved versions for runtime classpath (1.0) and compile classpath (2.0) differ.

要解决此问题,请执行以下一项操作:

To resolve this issue, do one of the following:

  • Include the desired version of the dependency as an api dependency to your library module. That is, only your library module declares the dependency, but the app module will also have access to its API, transitively.
  • Alternatively, you can declare the dependency in both modules, but you should make sure that each module uses the same version of the dependency. Consider configuring project-wide properties to ensure versions of each dependency remain consistent throughout your project.

这篇关于程序类型已经存在:android.support.v4.app.BackStackRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆