我在编译代码时遇到了这个错误:
<!-- 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
}
有什么建议吗?
最佳答案
找了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
如 this answer 中所述.
3- 你可能会在 MainActivity
中遇到错误的最后一步,因为你仍然从支持库中导入 AppCompatActivity
,所以你应该删除旧的导入并从中重新导入androidx
包
import androidx.appcompat.app.AppCompatActivity;
关于android - 程序类型已经存在 : com. google.android.material.internal.package-info,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51524303/