hi-dhl / KtKit

KtKit 小巧而实用,用 Kotlin 语言编写的工具库(长期更新中)
https://ktkit.hi-dhl.com
Apache License 2.0
165 stars 18 forks source link

跟DataStore有冲突 #12

Closed woitaylor closed 3 years ago

woitaylor commented 3 years ago
app.gradle

   plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'androidx.navigation.safeargs.kotlin'
    id 'kotlin-parcelize'
    id "com.google.protobuf" version "0.8.12"
}

 //DataStore
    implementation "androidx.datastore:datastore:1.0.0"
    implementation "androidx.datastore:datastore-preferences:1.0.0"

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.14.0"
    }

    // Generates the java Protobuf-lite code for the Protobufs in this project. See
    // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
    // for more information.
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
        }
    }
}
user_info.proto

syntax = "proto3";

option java_package = "com.signcc.adoperations.datastore";
option java_multiple_files = true;

message UserInfo {
  string realName = 1;
  string se = 2;
  string nickname = 3;
  string userMobile = 4;
  string userName = 5;
  string userId = 6;
  int32 userStatus = 7;
}

然后添加依赖就会导致编译失败

def ktkitVersion = "1.0.2"
implementation "com.hi-dhl:ktkit:$ktkitVersion"
hi-dhl commented 3 years ago

我这里试了一下,编译是通过的,可能是项目依赖库版本的问题,可以尝试以下方案解决

    implementation ('com.hi-dhl:ktkit:$ktkitVersion') {
        exclude group: 'androidx.fragment', module: 'fragment' // 可选
        exclude group: 'androidx.fragment', module: 'fragment-ktx' // 可选
        exclude group: 'androidx.appcompat', module: 'appcompat' // 可选
        exclude group: 'androidx.activity', module: 'activity-ktx' // 可选
        exclude group: 'com.googlecode.libphonenumber', module: 'libphonenumber' // 这个需要加上, google 的依赖库的可能版本过低
    }

对于可选的依赖库,如果项目用到的 androidx 版本过低,需要加上

hi-dhl commented 3 years ago

我这里试了一下,编译是通过的,可能是项目依赖库版本的问题,可以尝试以下方案解决

    implementation ('com.hi-dhl:ktkit:$ktkitVersion') {
        exclude group: 'androidx.fragment', module: 'fragment' // 可选
        exclude group: 'androidx.fragment', module: 'fragment-ktx' // 可选
        exclude group: 'androidx.appcompat', module: 'appcompat' // 可选
        exclude group: 'androidx.activity', module: 'activity-ktx' // 可选
        exclude group: 'com.googlecode.libphonenumber', module: 'libphonenumber' // 这个需要加上, google 的依赖库的可能版本过低
    }

对于可选的依赖库,如果项目用到的 androidx 版本过低,需要加上

@woitaylor

woitaylor commented 3 years ago

我后面直接把代码拷贝过来使用,我的依赖基本是最新的。

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation project(path: ':ijkplayerlib')
    implementation project(path: ':statelayout-library')
    implementation project(path: ':imageviewer')
    def lifecycle_version = "2.4.0-beta01"
    def room_version = "2.3.0"
    def nav_version = "2.4.0-alpha06"
    def hilt_version = "2.38.1"
    def paging_version = "3.0.1"

    implementation "androidx.paging:paging-runtime-ktx:$paging_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    // Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-compiler:$hilt_version"
    // androidx core
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.fragment:fragment-ktx:1.3.6"

    // lifecycle component
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    // Saved state module for ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"

    // coroutine(协程)
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
    // 图片加载库 coil
    implementation("io.coil-kt:coil:1.2.0")
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    // recyclerview
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    // 基础依赖包,必须要依赖 android 4.4以上沉浸式实现
    implementation 'com.gyf.immersionbar:immersionbar:3.0.0'

    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    // Java language implementation

    // Kotlin navigation
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    // XPopup
    implementation 'com.github.li-xiaojun:XPopup:2.5.8'
    // DslTablayout
    implementation 'com.github.angcyo.DslTablayout:TabLayout:2.0.3'

    // RxHttp
    implementation 'com.github.liujingxing.rxhttp:rxhttp:2.6.8'
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    kapt 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.6.8' //Use the annotationProcessor instead of kapt, if you use Java

    implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'      //核心必须依赖
    implementation 'com.scwang.smart:refresh-header-classics:2.0.3'    //经典刷新头
    implementation 'com.scwang.smart:refresh-footer-classics:2.0.3'    //经典加载
    implementation  'com.scwang.smart:refresh-header-material:2.0.3'    //谷歌刷新头

//    implementation 'com.github.iielse:imageviewer:2.1.2'
    implementation 'com.blankj:utilcodex:1.30.6'
    // 图片加载glide
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    implementation('io.github.lucksiege:pictureselector:v2.7.3-rc07') {
        exclude group: 'com.davemorrissey.labs', module: 'subsampling-scale-image-view'
    }
    // colorPicker
    implementation "com.github.skydoves:colorpickerpreference:2.0.5"
    // qiniu
    implementation 'com.qiniu:qiniu-android-sdk:8.3.0'
    // BaseRecyclerViewAdapter
    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
    //DataStore
    implementation "androidx.datastore:datastore:1.0.0"
    implementation "androidx.datastore:datastore-preferences:1.0.0"
    implementation  "com.google.protobuf:protobuf-javalite:3.14.0"

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
hi-dhl commented 3 years ago

我后面直接把代码拷贝过来使用,我的依赖基本是最新的。

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation project(path: ':ijkplayerlib')
    implementation project(path: ':statelayout-library')
    implementation project(path: ':imageviewer')
    def lifecycle_version = "2.4.0-beta01"
    def room_version = "2.3.0"
    def nav_version = "2.4.0-alpha06"
    def hilt_version = "2.38.1"
    def paging_version = "3.0.1"

    implementation "androidx.paging:paging-runtime-ktx:$paging_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    // Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-compiler:$hilt_version"
    // androidx core
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.fragment:fragment-ktx:1.3.6"

    // lifecycle component
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    // Saved state module for ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"

    // coroutine(协程)
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
    // 图片加载库 coil
    implementation("io.coil-kt:coil:1.2.0")
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    // recyclerview
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    // 基础依赖包,必须要依赖 android 4.4以上沉浸式实现
    implementation 'com.gyf.immersionbar:immersionbar:3.0.0'

    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    // Java language implementation

    // Kotlin navigation
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    // XPopup
    implementation 'com.github.li-xiaojun:XPopup:2.5.8'
    // DslTablayout
    implementation 'com.github.angcyo.DslTablayout:TabLayout:2.0.3'

    // RxHttp
    implementation 'com.github.liujingxing.rxhttp:rxhttp:2.6.8'
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    kapt 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.6.8' //Use the annotationProcessor instead of kapt, if you use Java

    implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'      //核心必须依赖
    implementation 'com.scwang.smart:refresh-header-classics:2.0.3'    //经典刷新头
    implementation 'com.scwang.smart:refresh-footer-classics:2.0.3'    //经典加载
    implementation  'com.scwang.smart:refresh-header-material:2.0.3'    //谷歌刷新头

//    implementation 'com.github.iielse:imageviewer:2.1.2'
    implementation 'com.blankj:utilcodex:1.30.6'
    // 图片加载glide
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    implementation('io.github.lucksiege:pictureselector:v2.7.3-rc07') {
        exclude group: 'com.davemorrissey.labs', module: 'subsampling-scale-image-view'
    }
    // colorPicker
    implementation "com.github.skydoves:colorpickerpreference:2.0.5"
    // qiniu
    implementation 'com.qiniu:qiniu-android-sdk:8.3.0'
    // BaseRecyclerViewAdapter
    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
    //DataStore
    implementation "androidx.datastore:datastore:1.0.0"
    implementation "androidx.datastore:datastore-preferences:1.0.0"
    implementation  "com.google.protobuf:protobuf-javalite:3.14.0"

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

先添加以下过滤吧,相同的依赖使用当前项目最新

    implementation ('com.hi-dhl:ktkit:$ktkitVersion') {
        exclude group: 'androidx.fragment', module: 'fragment' // 可选
        exclude group: 'androidx.fragment', module: 'fragment-ktx' // 可选
        exclude group: 'androidx.appcompat', module: 'appcompat' // 可选
        exclude group: 'androidx.activity', module: 'activity-ktx' // 可选
        exclude group: 'com.googlecode.libphonenumber', module: 'libphonenumber' // 这个需要加上, google 的依赖库的可能版本过低
    }