如何在android库中集成Butterknife



我正在android中处理现有项目,我想将android项目转换为android库。在该项目中,butterknife库用于绑定UI组件。当我尝试使用引用将项目转换为库时,项目成功同步,但使用了butterknife的所有文件,我得到了以下错误">属性值必须是常量";用于所有@BindView组件。

以下是我对渐变文件所做的更改。

  1. 应用程序级别等级:
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def verionMajor = 2
def versionMinor = 1
def versionPatch = 1

android {
compileSdkVersion 28
flavorDimensions "general"

defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 6
versionName "$verionMajor.$versionMinor.$versionPatch"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}

productFlavors {
general {
buildConfigField 'String', 'appName', '"Finetra"'
buildConfigField 'String', 'applicationType', '"General"'
resValue "string", "app_name", "Finetra"
}

flavor1 {
buildConfigField 'String', 'appName', '"Finetra"'
buildConfigField 'String', 'applicationType', '"Flavor"'
resValue "string", "app_name", "Finetra"
}
}

dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
}

packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}

}

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
maven { url 'http://dl.bintray.com/dev-fingerlinks/maven' }
maven { url "https://jitpack.io" }

dependencies {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v13'
}
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.android.support:design:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.cardview:cardview:1.0.0"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'com.google.firebase:firebase-core:16.0.5'

implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'

implementation 'com.github.lzyzsd:circleprogress:1.2.1'

implementation 'org.fingerlinks.mobile.android:Navigator:0.1.5'

implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.google.code.gson:gson:2.8.5'

implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'

implementation 'com.wdullaer:materialdatetimepicker:3.0.0'

implementation 'com.pixplicity.easyprefs:library:1.9.0'


implementation 'com.facebook.fresco:fresco:2.0.0'
implementation 'com.facebook.fresco:animated-gif:1.9.0'

implementation 'com.github.crosswall:Android-Coverflow:release-v1.0.5'

implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'

implementation 'com.kaopiz:kprogresshud:1.2.0'

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

implementation 'com.mikhaellopez:circularimageview:3.2.0'

implementation 'com.google.android.gms:play-services-auth:17.0.0'

implementation "com.priyankvasa.android:cameraview-ex:3.5.5-alpha"

implementation(name: 'highcharts-release', ext: 'aar')

implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'

implementation 'com.github.warkiz.widget:indicatorseekbar:2.1.2'


implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
}

ext {
versions = [
'javacv': '1.4.2',
'ffmpeg': '4.0.1'
]
}

dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.41"

implementation(group: 'org.bytedeco', name: 'javacv-platform', version: versions.javacv) {
exclude group: 'org.bytedeco.javacpp-presets'
}
implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: "${versions.ffmpeg}-${versions.javacv}"
implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: "${versions.ffmpeg}-${versions.javacv}", classifier: 'android-arm'
implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: "${versions.ffmpeg}-${versions.javacv}", classifier: 'android-arm64'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
implementation project(path: ':mylibrary')
}

android {

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
  1. 项目级别等级:

    //顶级生成文件,您可以在其中添加所有子项目/模块通用的配置选项。

buildscript {
ext.kotlin_version = '1.3.50'


repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// Add the Crashlytics Gradle plugin.
//        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta02'

classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'

}
}

allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}

ext {
rxJava = '2.2.0'
rxAndroid = '2.1.0'
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我也参考了butterknife文档,并做了相应的更改。但我无法解决R2的错误。

@BindView(R2.id.user) EditText userName;

我怎样才能做到这一点?

任何帮助都将不胜感激。

ButterKnife不能在库项目中使用。图书馆开发商JakeWharton自己也证实了这一点。请改用视图绑定。

android {
...
buildFeatures {
viewBinding = true
}
}

最新更新