1,hilt的工程配置

首先,我使用的gradle的版本是


然后其他配置版本一览


具体的project的build.gradle如下:

buildscript{

    ext{

        minAndroidSdk =19

        targetSdk =30

        verCode =100

        verName ="1.0.0"

        // version

        kotlin_version ="1.5.21"

        hilt_version ="2.38.1"

        hilt_androidx_version ='1.0.0-alpha03'

        lifecycle_version ="2.2.0"

        room_version ="2.2.6"

        work_version ="2.4.0"

        retrofit_version ="2.9.0"

        moshi_version ="1.12.0"

        fragment_version ="1.2.5"

        statusbarutil_version ='1.5.1'

    }

    repositories{

        google()

jcenter()

}

    dependencies{

        classpath'com.android.tools.build:gradle:7.0.1'

        classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        classpath"com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

        // NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

    }

}

allprojects{

    repositories{

        google()

jcenter()

}

}

task clean(type: Delete){

    delete rootProject.buildDir

}



App的build.gradle如下:

applyplugin:"com.android.application"

applyplugin:"kotlin-android"

applyplugin:"kotlin-kapt"

applyplugin:"dagger.hilt.android.plugin"

applyplugin:"kotlin-android-extensions"

android{

    compileSdkVersion30

    buildToolsVersion"30.0.2"

    namespace'com.vvvdj.carapp'

    defaultConfig{

        applicationId"com.vvvdj.carapp"

        minSdkVersion minAndroidSdk

targetSdkVersion targetSdk

versionCode verCode

versionName verName

testInstrumentationRunner"androidx.test.runner.AndroidJUnitRunner"

        multiDexEnabledtrue

    }

    buildTypes{

        all{

            buildConfigField("String","API_URL","\"https://api.github.com/\"")

}

        debug{

            minifyEnabledfalse

            debuggabletrue

        }

        release{

            minifyEnabledfalse

            debuggablefalse

            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"),"proguard-rules.pro"

        }

}

    //自定义打包时apk名称

    applicationVariants.all{ variant->

        variant.outputs.all{ output->// each 改为all

            def date =new Date().format("ddHHmm", TimeZone.getTimeZone("GMT+08"))

def fileName ="CarApp_${versionName}_${versionCode}_${date}.apk"

            def outFile = output.outputFile

if (outFile !=null && outFile.name.endsWith(".apk")) {

outputFileName = fileName// output.outputFile 改为outputFileName

            }

}

}

    compileOptions{

        sourceCompatibility JavaVersion.VERSION_1_8

        targetCompatibility JavaVersion.VERSION_1_8

    }

    kotlinOptions{

        jvmTarget ="1.8"

    }

    buildFeatures{

        viewBinding =true

    }

    kapt{

        generateStubs =true

    }

}

dependencies{

    implementation fileTree(dir:"libs",include: ["*.jar"])

implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    implementation"androidx.core:core-ktx:1.3.2"

    implementation"androidx.appcompat:appcompat:1.2.0"

    implementation"com.google.android.material:material:1.3.0"

    implementation"androidx.constraintlayout:constraintlayout:2.0.4"

    testImplementation"junit:junit:4.12"

    androidTestImplementation"androidx.test.ext:junit:1.1.2"

    androidTestImplementation"androidx.test.espresso:espresso-core:3.3.0"

    // hilt

    implementation"com.google.dagger:hilt-android:$hilt_version"

    kapt"com.google.dagger:hilt-android-compiler:$hilt_version"

//    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_androidx_version"

//    kapt "androidx.hilt:hilt-compiler:$hilt_androidx_version"

    implementation"androidx.fragment:fragment-ktx:$fragment_version"

    // Lifecycle - ViewModel

    implementation"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

    // Lifecycle - LiveData

    implementation"androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

    // Lifecycle - Lifecycles only (without ViewModel or LiveData)

    implementation"androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

    // Lifecycle - Saved state module for ViewModel

    implementation"androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"

    // Lifecycle - Annotation processor

// kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

// Lifecycle - alternately - if using Java8, use the following instead of lifecycle-compiler

    implementation"androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"

    // Room

    implementation"androidx.room:room-runtime:$room_version"

    // optional - Kotlin Extensions and Coroutines support for Room

    implementation"androidx.room:room-ktx:$room_version"

    kapt"androidx.room:room-compiler:$room_version"

    // Work Manager

    implementation"androidx.work:work-runtime-ktx:$work_version"

    // retrofit2

    implementation"com.squareup.retrofit2:retrofit:$retrofit_version"

    implementation"com.squareup.retrofit2:converter-moshi:$retrofit_version"

    // moshi

    implementation"com.squareup.moshi:moshi:$moshi_version"

    implementation"com.squareup.moshi:moshi-kotlin:$moshi_version"

//    implementation "com.squareup.moshi:moshi-adapters:$moshi_version"

    kapt"com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"

    // 该项目实现了Room类可用于处理特定版本SQLite的Support系列类和接口。

    // 具体地说,该项目的类将Room与适用于Android的SQLCipher连接起来,后者是SQLite的版本,可对其内容进行透明加密。

//    implementation 'com.commonsware.cwac:saferoom.x:1.2.1'

// StatusBarUtil

    implementation"com.jaeger.statusbarutil:library:$statusbarutil_version"

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容