关于compose和kotlin的一些兼容性问题

最近需要将项目中的一些模块封装成aar给客户使用。于是新建了构建脚本为KSL项目。但在项目模块迁移的过程中出现了兼容性问题。记录下方便后来者。

以下是出现的兼容性问题之一:

androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.4.3) expects a minimum runtime version of 1.0.0

.这个问题要添加运行时依赖项:

implementation("androidx.compose.runtime:runtime:1.5.0-alpha01")

以下是app下的build.gradle.kts

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
}

android {
    namespace = "com.xxx.xxx"
    compileSdk = 33

    defaultConfig {
        applicationId = "com.xxx.xxx"
        minSdk = 23
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"//1.4.3
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {

    implementation("androidx.core:core-ktx:1.9.0")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
    implementation("androidx.activity:activity-compose:1.7.0")
    implementation(platform("androidx.compose:compose-bom:2023.03.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

    

    implementation("androidx.compose.runtime:runtime:1.5.0-alpha01")

}

以下是需要封装模块下的build.gradle.kts

plugins {
    id("com.android.library")
    id("org.greenrobot.greendao")
    id("kotlin-android")
    id("kotlin-kapt")
}

android {
    namespace = "com.stonex.surpadbasesdk"
    compileSdk = 33

    defaultConfig {
        minSdk = 23

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles("consumer-rules.pro")

        ndk {
            //设置支持的so库架构,iAppPDFLib只支持armeabi
            //abiFilters 'armeabi-v7a', 'arm64-v8a'//, 'x86', 'x86_64' //不支持armeabi
            //abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
            abiFilters += setOf("armeabi","armeabi-v7a","x86", "mips")
            //abiFilters "armeabi"
        }


    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    dataBinding {
        enable=true
    }
    buildFeatures {
        dataBinding=true
        compose=true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"//1.4.3
    }

    buildFeatures {
        viewBinding=true
    }
    greendao {
        schemaVersion=1 //数据库版本号
        daoPackage="com.xxx.xxx// 设置DaoMaster、DaoSession、Dao 包名
        //targetGenDir=File("src/main/java")//设置DaoMaster、DaoSession、Dao目录,
        generateTests=false //设置为true以自动生成单元测试。
        //targetGenDirTests=File("src/main/java") //应存储生成的单元测试的基本目录。默认为 src / androidTest / java。
    }
}

dependencies {

    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.8.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

    implementation("androidx.compose.runtime:runtime:1.5.0-alpha01")

    

    /*okhttp网络框架*/
    api("com.squareup.okhttp3:okhttp:4.0.1")
    /*retrofit框架*/
    api("com.squareup.retrofit2:retrofit:2.7.2")
    api("com.squareup.retrofit2:adapter-rxjava2:2.7.2")

    /*rxjava框架*/
    api("io.reactivex.rxjava2:rxjava:2.2.21")
    api("io.reactivex.rxjava2:rxandroid:2.1.1")

    /*rxrelay*/
    api("com.jakewharton.rxrelay2:rxrelay:2.1.0")
    /**
     * 使用Rxlifecycle解决RxJava引起的内存泄漏
     */
    api("com.trello.rxlifecycle2:rxlifecycle-android-lifecycle:2.2.2")

    //LifecycleService存在于扩展包中
    api("android.arch.lifecycle:extensions:1.1.1")
    /*gson*/
    api("com.google.code.gson:gson:2.8.5")

    /*greendao数据库框架*/
    api("org.greenrobot:greendao:3.3.0")
    implementation("org.greenrobot:greendao-generator:3.3.0")
    //支持数据库数据迁移
    api("io.github.yuweiguocn:GreenDaoUpgradeHelper:v2.2.1")
    //快速适配器
    api("com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4")

    /*圆形图片*/
    api("de.hdodenhof:circleimageview:2.2.0")
    /*图形库glide*/
    api("com.github.bumptech.glide:glide:4.8.0")
    implementation("jp.wasabeef:glide-transformations:3.0.1")

    /*switchbutton*/
    api("com.kyleduo.switchbutton:library:2.0.0")
    /*状态栏*/
    api("com.gyf.immersionbar:immersionbar:2.3.3-beta15")
    //mmkv
    implementation("com.tencent:mmkv-static:1.2.7")
    /*dialog*/
    api("com.afollestad.material-dialogs:core:0.9.6.0")
    /*loading特效*/
    api("com.wang.avi:library:2.1.3")

    //viewmodel
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")


    
}
以下是项目下的build.gradle.kts
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {

        mavenCentral() // add repository
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.0.2")
        classpath("org.greenrobot:greendao-gradle-plugin:3.3.1")
        classpath("com.google.dagger:hilt-android-gradle-plugin:2.42")
    }
}

plugins {
    id("com.android.application") version "8.1.1" apply false
    id("org.jetbrains.kotlin.android") version "1.8.10" apply false
    //id("org.jetbrains.kotlin.android") version "1.7.10" apply false
    id("com.android.library") version "8.1.1" apply false
}

注意compose
composeOptions {
    kotlinCompilerExtensionVersion = "1.4.3"//1.4.3
}

和kotlin的兼容性问题

id("org.jetbrains.kotlin.android") version "1.8.10" apply false

以下是兼容对照表:

Compose 与 Kotlin 的兼容性对应关系  |  Android 开发者  |  Android Developers (google.cn)

注意这个编译选项

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

和下面这里需要一致:

注意setting.gradle.kts,防止依赖下载不下来:

import java.net.URI

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()

        maven { url=(uri("https://maven.aliyun.com/nexus/content/repositories/google"))}
        maven { url=(uri("https://maven.aliyun.com/repository/public")) }
        maven { url=(uri("https://maven.aliyun.com/nexus/content/repositories/jcenter"))}

        maven { url=(uri("https://maven.aliyun.com/nexus/content/groups/public/"))}

        maven { url=(uri("https://maven.aliyun.com/nexus/content/repositories/gradle-plugin'"))}
        maven { url=(uri("https://jitpack.io"))}
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        maven { url=(uri("https://maven.aliyun.com/nexus/content/repositories/google"))}
        maven { url=(uri("https://maven.aliyun.com/repository/public")) }
        maven { url=(uri("https://maven.aliyun.com/nexus/content/repositories/jcenter"))}

        maven { url=(uri("https://maven.aliyun.com/nexus/content/groups/public/"))}

        maven { url=(uri("https://maven.aliyun.com/nexus/content/repositories/gradle-plugin'"))}
        maven { url=(uri("https://jitpack.io"))}
    }
}

rootProject.name = "xxx"
include(":app")
include(":xxx")

编译成功!

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker Compose文件和Docker的兼容性是通过Compose文件格式来确定的。Compose文件格式有多个版本,包括1、2、2.x和3.x。不同的Docker Engine版本支持不同的Compose文件格式。例如,Docker Engine 19.03.0支持Compose文件格式3.8,而Docker Engine 18.02.0支持Compose文件格式3.5。具体的兼容性列表可以参考引用和引用[2]中提供的信息。需要注意的是,除了显示在兼容性列表中的Compose文件格式版本外,Compose本身也在发布计划中进行更新,但文件格式版本不一定随每个版本增加。例如,Compose文件格式3.0首次在Compose版本1.10.0中引入,并在后续版本中逐步进行版本化。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [docker-compose 与 docker 兼容性矩阵](https://blog.csdn.net/weixin_48505120/article/details/127663245)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [docker-compose-ui:Docker Compose的Web界面](https://download.csdn.net/download/weixin_42170064/14986791)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值