Как интегрировать Butterknife в библиотеку Android?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как интегрировать Butterknife в библиотеку Android?

Сообщение Anonymous »

Я работаю над существующим проектом в Android и хочу преобразовать проект Android в библиотеку Android.
В этом проекте библиотека Butterknife используется для привязки компонентов пользовательского интерфейса. Когда я попытался преобразовать проект в библиотеку, используя ссылку, проект успешно синхронизировался, но во всех файлах, где используется сливочный нож, я получаю сообщение об ошибке «Значение атрибута должно быть постоянным» для всех компонентов @BindView.
Ниже приведены изменения, которые я внес в файл градиента.
  • Градус уровня приложения:

    Код: Выделить всё

        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"
    }
    }
    
    
  • Градус уровня проекта:
    // Файл сборки верхнего уровня, в котором вы можно добавлять параметры конфигурации, общие для всех подпроектов/модулей.

Код: Выделить всё

    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;
Как я могу этого добиться?
Любая помощь будет оценена по достоинству.

Подробнее здесь: https://stackoverflow.com/questions/642 ... id-library
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»