程序类型已存在:com.google.android.material.internal.package-info

5

我在编译代码时遇到了这个错误:

<!-- language: lang-none -->        
Program type already present: 
    com.google.android.material.internal.package-info
    Message{kind=ERROR, text=Program type already present: 
    com.google.android.material.internal.package-info, sources= 
    [Unknown source file], tool name=Optional.of(D8)}

当我搜索类似的错误时,建议添加


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

或者将以下几行代码添加到“gradle.properties”文件中。
android.useAndroidX = true
android.enableJetifier = false

但是这些解决方案都不适用于我,这是我的Gradle文件。
app 

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 28  
    defaultConfig {
        applicationId "com.example.agh.yaomi"
        minSdkVersion 17
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // added meta data in manifiest to resolve
    //suppport version conflict
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:support-annotations:28.0.0-beta01'
    implementation "org.jetbrains.anko:anko:0.10.4"
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-media-compat:28.0.0-alpha3'

    // added to solve merge dex error
    implementation 'com.android.support:multidex:1.0.3'

    implementation ('com.github.omadahealth:lollipin:2.1.0@aar') {
        transitive = true
    }
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

项目

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.21'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

allprojects {
    repositories {
        google()
        jcenter()
        maven{ url "https://github.com/omadahealth/omada-nexus/raw/master/release" }
    }
}

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

有什么建议吗?

重新缩进代码部分。 - Nic3500
有解决方案了吗? - IntelliJ Amiya
1个回答

3

在搜索了三个小时后,我解决了这个问题:

问题是:当添加 material:1.0.0-beta01 依赖项,并使用任何版本的支持库时,会出现此错误。

解决方案:

1- 您应该使用所有的 androidx 依赖项。

因此,这些行

implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:support-annotations:28.0.0-beta01'
implementation "org.jetbrains.anko:anko:0.10.4"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-media-compat:28.0.0-alpha3'

把它们改成:
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.annotation:annotation:1.0.0-alpha1'
implementation "org.jetbrains.anko:anko:0.10.4"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.media:media:1.0.0-alpha1'

我们删除了 design:28.0.0-alpha3,因为它已经包含在material:1.0.0-beta01中。
2- 将以下行添加到gradle.properties文件中。
android.useAndroidX = true
android.enableJetifier = false

此答案所述。

3- 最后一步可能会在MainActivity中出现错误,因为您仍然从支持库导入AppCompatActivity,所以您应该删除旧的导入并再次从androidx包中导入它,如下:

import androidx.appcompat.app.AppCompatActivity;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接