android - 编译时Android X库抛出错误
问题描述
在 android studio 3.1.3 中构建我的项目时出现此错误
程序类型已存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy Message{kind=ERROR, text=程序类型已存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy,sources=[未知来源文件],工具名称=Optional.of(D8)}
我开始迁移到AndroidX库gradle.build
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.jimmy.bitcoinpriceindex"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// enable databinding
dataBinding {
enabled = true
}
// add java 8 features support
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
androidTestImplementation "androidx.test:runner:$versions.test"
androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espresso"
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$versions.lifecycle"
implementation "androidx.appcompat:appcompat:$versions.support"
implementation "androidx.constraintlayout:constraintlayout:$versions.constraint_layout"
implementation "com.github.bumptech.glide:glide:$versions.glide"
// work manager dependency
implementation "android.arch.work:work-runtime:$versions.work"
implementation ("com.squareup.retrofit2:retrofit:$versions.retrofit"){
// exclude Retrofit’s OkHttp dependency module and define your own module import
exclude module: 'okhttp'
}
implementation "com.squareup.retrofit2:converter-gson:$versions.retrofit"
implementation "com.google.code.gson:gson:$versions.gson"
implementation "com.squareup.okhttp3:logging-interceptor:$versions.loggin_interceptor"
implementation "com.squareup.okhttp3:okhttp:$versions.okttp"
}
apply plugin: 'kotlin-kapt'
解决方案
首先,在迁移之前恢复到原始状态。有一个内置工具可以将您的整个 Android 项目转换为 Androidx。我正在使用 Android Studio 3.3。
重构 > 将应用程序迁移到 Androidx
这是转换/迁移后我在 gradle 中的依赖项的副本:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'com.google.android.material:material:1.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android:flexbox:0.3.0-alpha3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
}
推荐阅读
- javascript - 随机选色猜谜游戏中的逻辑错误
- javascript - 数据表中的多个 ajax 源
- python - PySpark - 如何在 csv 输出中删除科学记数法
- minizinc - MiniZinc 中的 $ 是什么意思?
- python - 无法为 pyqt5 gui 应用程序执行脚本 fbs_pyinstaller_hook
- python - 如何将多行解析为元组
- kubernetes - 无法访问 IBM Cloud 上 Kubernetes 集群的公共 LoadBalancer 或 Ingress 端口
- node.js - 无服务器框架+ postgresql中的where子句
- java - Espresso Matcher 多个子自定义视图
- javascript - 我如何“创建一个