使用 android、dagger2、butterknife 构建 Android java 代码无法构建
building Android java code using androidx, dagger2, butterknife doesnt build
我已经尝试了 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'
}
- What went wrong:
Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.1.0-alpha02] AndroidManifest.xml:22:18-86
is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:6:5-26:19 to override.
更新后行为发生了变化:
在 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
}
enableSeparateAnnotationProcessing is experimental.
试用 Butterknife 版本 10
// BUTTERKNIFE
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
我已经尝试了 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'
}
- What went wrong: Execution failed for task ':app:processDebugManifest'. Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.1.0-alpha02] AndroidManifest.xml:22:18-86 is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:6:5-26:19 to override.
更新后行为发生了变化: 在 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
}
enableSeparateAnnotationProcessing is experimental.
试用 Butterknife 版本 10
// BUTTERKNIFE
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'