Android Studio 3.3, component-based project butterknife configuration

My project structure

  • base-libraryIs the lowest level of the library
  • frame-libraryDependence base-library, is a library file of my project
  • my-assertIs one of the components, is also a library
  • appIt is also one of the components, but the project is the final run, so it relies on the project in addition to library files frame-libraryalso depends on all the other components, such as my-assertcomponents
  • Also my Android Studio version 3.3, compileSdkVersion of the project is 28

Before the project used in butterknifeversion 7.0.1, it is apply plugin: 'com.android.application'used directly in the project, but now I also need to use the component library, in apply plugin: 'com.android.library'it use butterknife, it has been an errorattribute value must be constant

Upgrade butterknifeto the latest 10.1.0

New problems, given Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory), then the reference ( github.com/JakeWharton... ) [Issue on GitHub]

Version 9.0.0 will be reduced, while the library file @BindView all @BindView(R.id.assertNum)changed @BindView(R2.id.assertNum), namely R -> R2. However, R2 must be current library file package name below R2, since each library file will generate a R2

My last project butterknife configuration

project的gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0'
}
复制代码

base-library的gradle

apply plugin: 'com.android.library'
...
dependencies {
    ...
    api 'com.jakewharton:butterknife:9.0.0'
}
复制代码

Gradle the frame-library (library is useful to ButterKnife, but not used inside the annotation, it is not necessary to generate R2)

apply plugin: 'com.android.library'

dependencies {
    ...
    api project(path: ':baselibrary')
}
复制代码

my-assert the Gradle (need to generate this library R2)

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

dependencies {
    ...
    api project(path: ':framelibrary')
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'
}
复制代码

Gradle the app (no need to generate R2)

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.versions['compileSdkVersion']
    buildToolsVersion rootProject.ext.versions['buildToolsVersion']
    defaultConfig {
        applicationId "com.shineex"
        minSdkVersion rootProject.ext.versions.minSdkVersion
        targetSdkVersion rootProject.ext.versions.targetSdkVersion
        versionCode rootProject.ext.versions.versionCode
        versionName rootProject.ext.versions.versionName
        flavorDimensions "versionCode"
        multiDexEnabled true
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
...
dependencies {
   api project(path: ':framelibrary') 
   implementation project(':modules:myAssert')
   annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'
   ...
}
复制代码

note

1.app have in the gradle javaCompileOptionsand compileOptionsconfiguration, otherwise it will report DexArchiveBuilderExceptionan error

2.app of gradle can not add apply plugin: 'com.jakewharton.butterknife', but the library file you want to add, because the app used directly R.id, but R2 to use in the library.

Reproduced in: https: //juejin.im/post/5cef42bce51d45105d63a497

Guess you like

Origin blog.csdn.net/weixin_34014277/article/details/91428446