我正在处理Android中的现有项目,我想将Android项目转换为Android库。在该项目中,butterknife库用于绑定UI组件。当我尝试使用引用将项目转换为库时,项目成功同步,但使用butterknife的所有文件,我收到以下错误“属性值必须为常量”,适用于所有@BindView组件。
下面是我对Gradle文件所做的更改。
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 doc并进行了相应的更改。但是我无法解决R2的错误。
@BindView(R2.id.user) EditText userName;
我怎样才能做到这一点?
任何帮助都将不胜感激。
1条答案
按热度按时间pxy2qtax1#
ButterKnife不能用于图书馆项目,图书馆开发人员JakeWharton自己也证实了这一点,请使用view binding。