My project structure
base-library
Is the lowest level of the libraryframe-library
Dependencebase-library
, is a library file of my projectmy-assert
Is one of the components, is also a libraryapp
It is also one of the components, but the project is the final run, so it relies on the project in addition to library filesframe-library
also depends on all the other components, such asmy-assert
components- Also my Android Studio version 3.3, compileSdkVersion of the project is 28
Before the project used in butterknife
version 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
butterknife
to 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 javaCompileOptions
and compileOptions
configuration, otherwise it will report DexArchiveBuilderException
an 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