使用androidx,dagger2,butterknife构建Android Java代码无法构建

时间:2018-12-21 13:55:59

标签: android dagger-2 butterknife androidx

我已经尝试了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]中的属性application @ appComponentFactory value =(androidx.core.app.CoreComponentFactory)AndroidManifest.xml:22:18-86   也出现在[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value =(android.support.v4.app.CoreComponentFactory)。   建议:在AndroidManifest.xml:6:5-26:19的元素上添加'tools:replace =“ android:appComponentFactory”'以进行覆盖。
  •   

2 个答案:

答案 0 :(得分:1)

更新后的行为发生了变化: 在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 
        }

答案 1 :(得分:0)

enableSeparateAnnotationProcessing is experimental.

尝试Butterknife版本10

// BUTTERKNIFE
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'