Android kotlin introduces anko dependency problem to solve

Summary of problems when kotlin introduces anko dependency

First of all, I want to say that introducing the anko dependency gave me a headache. I spent Saturdays and Sundays racking my brains and didn’t understand why. Then let me describe my project situation. I created a new kotlIn
Android project, the studio tools are the latest version 2021.1.1. After the project is created, add the dependency of anko to the gradle of the app.

//Anko commons
implementation "org.jetbrains.anko:anko-commons:0.10.5"

Then after the synchronization, it was successful, but there was a problem with the operation, and everything was not working. The version of my project gradle corresponded to 7.1.2 corresponding to 7.2.0, and the sdk version was 31 or 32, and the lowest was 21. At first I thought It was a problem with the sdk. After modifying various versions, it still didn't work. So I added the dependency library in gradle and imported it from the Alibaba warehouse. But the result still didn't work. Well, I got angry for the time being and put it aside until the next day. I downloaded the version demo from the official website. After making some modifications, I found that it worked when I ran it again. Then I compared it. OK, I just modified three places: app's build.gradle, root gradle, and setting.gradle. The following three parts of code are:

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()
}

I just added the above module

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    
        //Anko commons
    implementation "org.jetbrains.anko:anko-commons:0.10.5"
    
    repositories {
    
    
    mavenCentral()
    google()
}

These three pieces of code, and then the following are the other two places of code as shown:
Insert image description here

Insert image description here
Comparing these two pictures, you can clearly see that, then just synchronize the project and run it.

Guess you like

Origin blog.csdn.net/mawlAndroid/article/details/125030385