In the #NowInAndroid sample app a Kotlin file NiaBuildType
from an included module is being imported in the app modules build.gradle.kts file.
###build.gradle.kts (:app)
import com.google.samples.apps.nowinandroid.NiaBuildType
I have tried achieving almost the same result but every time I get Unresolved reference: au
error.
My package structure in the included build is the same as my app module to enable transitive dependency.
unlike the NIA app I don't have convention plugins in a submodule (convention module is included in the build-logic module which itself is included in the project using pluginmanager{}
) and only have one included buildplugin
module.
Here is my file in my included module buildplugin
:
package au.com.myproject
object AppVersion {
const val versionCode = 1
const val versionName = "1.0"
}
here is the project's settings.gradle.kts
file:
pluginManagement {
includeBuild("buildplugin")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
This is my buildplugin
module build.gradle.kts
file:
plugins {
`kotlin-dsl`
}
group = "au.com.myproject.buildplugin"
repositories {
google()
mavenCentral()
}
dependencies {
compileOnly(gradleApi())
implementation("com.android.tools.build:gradle:8.1.0")
implementation(kotlin("gradle-plugin"))
}
and this is my usage in the app modules build.gradle.kts
:
import au.com.myproject.AppVersion
plugins {
...
}
android {
namespace = "au.com.myproject"
compileSdk = 34
defaultConfig {
applicationId = "au.com.myproject.pai"
minSdk = 24
//noinspection OldTargetApi
targetSdk = 33
versionCode = AppVersion.versionCode
versionName = AppVersion.versionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
...
If I use buildSrc
instead of composite build, the object can be imported without any issue.
I am not sure what I am missing and have been smashing my head against the wall for a couple of days now trying different approaches.
app/build.gradle.kts
and it now recognises the files in the "buildplugin" included module. I thought having it only as included build should grant access for other modules to access its file but seems that wasn't the case. – Varistor