android - 使用 androidx、dagger2、butterknife 构建 Android java 代码不会构建
问题描述
我已经尝试了 2 天无济于事,阅读了类似的帖子,但仍然找不到任何有用的帮助,非常感谢.. 最好的问候
这是我的最后一次尝试:排除模块:'support-compat' 和所有其他选项似乎相同,尝试使用不同的组合并没有解决问题......启用 jetifier 添加另一个错误..所以它暂时禁用..
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId 'XXXX'
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-compat:28.0.0'
// the lib is old dependencies version;
// resolutionStrategy.force 'com.google.android.material:material:1.1.0-alpha02]' // the lib is old dependencies version;
}
dependencies {
def lifecycle_version = '2.0.0'
def room__version = '2.1.0-alpha03'
def firebase_version = '16.1.0'
def dagger_version = '2.19'
def butterknife_version = "9.0.0-rc2"
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
// FIREBASE
// implementation "com.google.firebase:firebase-storage:$firebase_version"
// implementation "com.google.firebase:firebase-auth:$firebase_version"
// implementation "com.google.firebase:firebase-core:$firebase_version"
// implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13-beta-1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
// //GLIDE
// implementation 'com.github.bumptech.glide:glide:4.8.0'
// annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
// DAGGER 2
implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
// if you use the support libraries
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
// // Dagger 2
// implementation 'com.google.dagger:dagger-android-support:2.19'
// implementation "com.google.dagger:dagger:2.19"
// kapt "com.google.dagger:dagger-compiler:2.19"
// kapt "com.google.dagger:dagger-android-processor:2.19"
//RETROFIT
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// Room components
implementation "androidx.room:room-runtime:$room__version"
annotationProcessor "androidx.room:room-compiler:$room__version"
implementation "androidx.room:room-compiler:$room__version"
androidTestImplementation 'androidx.annotation:annotation:1.0.1'
// GSON
implementation 'com.google.code.gson:gson:2.8.5'
// BUTTERKNIFE
// implementation "com.jakewharton:butterknife:$butterknife_version"
// annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife_version"
implementation ('com.jakewharton:butterknife:9.0.0-rc2')***{
exclude module: 'support-compat'
}***
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2'
}
- 出了什么问题:任务“:app:processDebugManifest”执行失败。清单合并失败:[androidx.core:core:1.1.0-alpha02] AndroidManifest.xml:22:18-86 中的属性 application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) 也存在于 [com.android .support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory)。建议:将 'tools:replace="android:appComponentFactory"' 添加到 AndroidManifest.xml:6:5-26:19 的元素以覆盖。
解决方案
更新后行为改变:在 build.gradle
// BUTTERKNIFE
implementation 'com.jakewharton:butterknife:9.0.0-rc3'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc3'
并在 gradle.properties 中设置:
android.enableJetifier=true
android.useAndroidX=true
android.enableSeparateAnnotationProcessing=true
现在这就是我得到的:
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules jetified-guava-23.5-jre.jar (com.google.guava:guava:23.5-jre) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)
Go to the documentation to learn how to Fix dependency resolution errors.
这就是解决错误的原因:
implementation ("androidx.room:room-compiler:$room__version")
{
exclude group: 'com.google.guava' //this is what fixed the library duplication error
}
推荐阅读
- ruby-on-rails - Rails 服务器端验证问题
- node.js - 在 Sequelize 中加入或填充查询
- android-emulator - 模拟器:模拟器:错误:没有足够的空间来创建用户数据分区
- msdeploy - MSdeploy 跳过根 webconfig
- ruby - 替换字符串中的反斜杠
- java - 如何在 Android 中支持 EditText 的 setError 弹出消息中的其他语言?
- xamarin.forms - 将 css 样式与 xamarin 表单一起使用时,对象引用未设置为对象的实例
- xilinx - Vivado、Zynq、BRAM 控制器、窄 AXI 突发选项
- android - 当我使用 Jenkins 构建时,Android 构建总是失败
- java - 同步数组列表中的竞争条件