android java模块项目【子模块java与kotlin混合开发】问题
1.集成kotlin (1) 主模build:gradle块添加
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// butterknife
classpath "com.jakewharton:butterknife-gradle-plugin:10.2.1"
// arouter
classpath "com.alibaba:arouter-register:1.0.2"
// kotlin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
(2)子模块添加
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'//findViewById后从xml中实例化赋值
apply plugin: 'kotlin-kapt'//用于kotlin依赖,和java不一样
defaultConfig {
if (config.isMoudleAsApp) {
applicationId "com.cmmboy.module_login"
}
minSdkVersion config.android.minSdkVersion
targetSdkVersion config.android.targetSdkVersion
versionCode config.android.versionCode
versionName config.android.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
arguments = [AROUTER_MODULE_NAME : project.getName()]
}
}
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.ld:switchView:1.1.7'
//6.0+系统权限管理
implementation 'com.mylhyl:acp:1.2.0'
api project(':lib_basic')
annotationProcessor config.dependencies["arouter-compiler"]
annotationProcessor config.dependencies["butterknife-compiler"]
annotationProcessor config.dependencies["lombok"]
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
kapt config.dependencies["arouter-compiler"]
kapt config.dependencies["butterknife-compiler"]
kapt config.dependencies["lombok"]
}
问题: 1.添加kotlin后 butterknife不可用 解决:添加:kapt config.dependencies[“butterknife-compiler”] 2.添加kotlin后lombok不可用【java类中不可引用get方法】 解决:添加:kapt config.dependencies[“lombok”] 无效 暂时解决==> bean中手动生成get/set方法。