Code Monkey home page Code Monkey logo

Comments (13)

cortinico avatar cortinico commented on July 18, 2024 2

You can always overcome the lack of a plugin marker by specifying a custom resolution strategy. That's actually what this template was doing long before this issue was fixed for AGP:

resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.android.library") {
useModule("com.android.tools.build:gradle:${requested.version}")
}
if (requested.id.id == "com.android.application") {
useModule("com.android.tools.build:gradle:${requested.version}")
}
}
}

from kotlin-android-template.

cortinico avatar cortinico commented on July 18, 2024 1

Should I add them inside buildSrc folder?

AGP and Kotlin bump, you can do them if you wish.

As for hilt and safe-args, I won't add them for now.
I'm thinking about having a more opinionated branch where some small setup is also included.

from kotlin-android-template.

darkpandawarrior avatar darkpandawarrior commented on July 18, 2024 1

Has this been resolved?
Can someone give the solution on how to setup dagger hilt & navigation in this template?

from kotlin-android-template.

VincentJoshuaET avatar VincentJoshuaET commented on July 18, 2024

Should I add them inside buildSrc folder?

AGP and Kotlin bump, you can do them if you wish.

As for hilt and safe-args, I won't add them for now.
I'm thinking about having a more opinionated branch where some small setup is also included.

Where do you suggest I add them? I can't use the new plugins block with them

from kotlin-android-template.

cortinico avatar cortinico commented on July 18, 2024

I can't use the new plugins block with them

Why not?

from kotlin-android-template.

VincentJoshuaET avatar VincentJoshuaET commented on July 18, 2024

I can't use the new plugins block with them

Why not?

Screenshot_20210904-172103_Samsung Internet.png

https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers

https://issuetracker.google.com/issues/64551265

Google's fault

Fixed for the AGP, but not for Navigation or Dagger Hilt

from kotlin-android-template.

VincentJoshuaET avatar VincentJoshuaET commented on July 18, 2024

Does not seem to work for Hilt:

The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            when (requested.id.id) {
                "androidx.navigation.safeargs.kotlin" -> {
                    useModule("androidx.navigation:navigation-safe-args-gradle-plugin:${requested.version}")
                }
                "dagger.hilt.android.plugin" -> {
                    useModule("com.google.dagger:hilt-android-gradle-plugin:${requested.version}")
                }
            }
        }
    }
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}

from kotlin-android-template.

cortinico avatar cortinico commented on July 18, 2024

The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.

You're missing the necessary dependencies in order to make Hilt work:
https://stackoverflow.com/a/62882856/3765748

from kotlin-android-template.

VincentJoshuaET avatar VincentJoshuaET commented on July 18, 2024

I have those already. I dont have this issue if I use the code in my original post.

from kotlin-android-template.

cortinico avatar cortinico commented on July 18, 2024

I have those already. I dont have this issue if I use the code in my original post.

Don't you mind sharing your project and/or your build.gradle[.kts] files?

from kotlin-android-template.

VincentJoshuaET avatar VincentJoshuaET commented on July 18, 2024

I cannot post the whole files, but here are the important ones.

I omitted the unrelated dependencies. This is working as expected. Once I implement the logic in pluginManagement and remove the Hilt and AndroidX Navigation Safe Args plugins from buildSrc, and set their versions to the root build.gradle.kts file, it fails.

build.gradle.kts:

plugins {
    `android-app` apply false
    `android-library` apply false
    `kotlin-android` apply false
    `kotlin-kapt` apply false
    `kotlin-serialization` version PluginVersions.Kotlin apply false
    `kotlin-parcelize` apply false
    `hilt-android` apply false
    `androidx-navigation-safe-args` apply false
}

allprojects {
    group = ""
    repositories {
        google()
        mavenCentral()
    }
}

buildSrc/build.gradle.kts

plugins {
    `kotlin-dsl`
}

repositories {
    google()
    mavenCentral()
}

dependencies {
    implementation(group = "com.android.tools.build", name = "gradle", version = "7.0.2")
    implementation(kotlin(module = "gradle-plugin", version = "1.5.30"))
    implementation(group = "com.google.dagger", name = "hilt-android-gradle-plugin", version = "2.38.1")
    implementation(group = "androidx.navigation", name = "navigation-safe-args-gradle-plugin", version = "2.3.5")
}

app/build.gradle.kts

plugins {
    `android-app`
    `kotlin-android`
    `kotlin-kapt`
    `kotlin-serialization`
    `kotlin-parcelize`
    `hilt-android`
    `androidx-navigation-safe-args`
}

android {
    compileSdk = Android.CompileSdkVersion
    buildToolsVersion = Android.BuildToolsVersion
    ndkVersion = Android.NdkVersion

    defaultConfig {
        applicationId = ""
        minSdk = Android.MinSdk
        targetSdk = Android.TargetSdk
        versionCode = Android.VersionCode
        versionName = Android.VersionName
    }

    signingConfigs {
        register("release") {
            enableV1Signing = true
            enableV2Signing = true
            enableV3Signing = true
            enableV4Signing = true
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix = ".debug"
        }
        release {
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            ndk {
                debugSymbolLevel = "FULL"
            }
        }
    }

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
        freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
    }

    buildFeatures {
        viewBinding = true
    }

    lint {
        isCheckDependencies = true
    }
}

dependencies {
    implementation(libs.androidx.hilt.work)
    kapt(libs.androidx.hilt.compiler)
    implementation(libs.hilt.android)
    kapt(libs.hilt.compiler)
}

kapt {
    correctErrorTypes = true
}

hilt {
    enableAggregatingTask = true
}

from kotlin-android-template.

cortinico avatar cortinico commented on July 18, 2024

Seems like you're using precompiled script plugins right? How comes you have those implementation dependencies inside buildSrc/build.gradle.kts?

from kotlin-android-template.

VincentJoshuaET avatar VincentJoshuaET commented on July 18, 2024

Originally I had those in the buildscript block in the root directory build.gradle.kts, but I didn't know where to move them hence this post.

from kotlin-android-template.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.