我正在迁移应用程序以使用动态交付和动态功能模块,而黄油刀不再适用于新配置。
目前,butterknife 在基本:app
模块中工作,它也可以在标有apply plugin: 'com.android.library'
. 问题仅在我的新动态功能模块中,标有plugin: 'com.android.dynamic-feature
'.
这是我的项目级 gradle 文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
现在我的基本应用程序 gradle 文件(在:app
ButternifeR
中照常使用)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.elksa.ddsample"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
bundle {
language {
enableSplit = true
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dynamicFeatures = [":images"]
}
dependencies {
api 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'androidx.appcompat:appcompat:1.0.2'
api 'androidx.constraintlayout:constraintlayout:1.1.3'
// Butter Knife
api 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
// Dynamic features
implementation 'com.google.android.play:core:1.6.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
最后,这里是我的动态功能模块的 gradle 文件,其中黄油刀不起作用,绑定R
给了我null
预期的参考,并且R2
完全丢失了。
apply plugin: 'com.android.dynamic-feature'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':app')
}
最后,这是我在尝试使用黄油刀(error: package R2 does not exist
)时在我的动态功能模块中得到的
有任何想法吗?提前致谢!