kotlin引入 anko依赖的问题总结
首先啊, 我想说,这个引入 anko依赖头疼死我了,折腾了周六周日,绞尽脑汁,不明白为啥, 然后下面我叙述一下我的项目情况,
我是 新建了一个kotlIn的安卓项目,studio的工具是最新版本 2021.1.1这样的, 项目新建后就是 在 app的gradle添加 anko的依赖
//Anko commons
implementation "org.jetbrains.anko:anko-commons:0.10.5"
然后同步后,成功,但是呢,运行就出问题,各种不行,我的项目 gradle的版本对应是 7.1.2 对应 7.2.0 ,sdk版本 也就是 31 或者32 ,最低是21 ,一开始我以为是 sdk的问题,修改个各种版本还是不行, 就在 gradle中添加 依赖库,阿里仓库引入,结果 呢 还是不行,好吧, 暂时生气了,搁置到第二天,在官网下载了版本demo,修改了一番,再次运行发现可以了, 然后对比一下,额 好吧, 就是 修改了 三个地方 分别是 app的build.gradle和 根gradle,以及setting.gradle,如下三部分代码:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.tecocity.myankotest"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
//Kotlin Libraries
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Anko commons
implementation "org.jetbrains.anko:anko-commons:0.10.5"
}
repositories {
mavenCentral()
google()
}
上面模块我仅仅添加了
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//Anko commons
implementation "org.jetbrains.anko:anko-commons:0.10.5"
repositories {
mavenCentral()
google()
}
这三段代码,然后下面的是 另外两个地方代码 如图:
这两个图,大家对比一下很明显看出来的, 然后就是 同步项目 ,运行即可了,。