Gradle can't find kotlin compiler version - android

I wanted to configure Jetpack Compose. I did it but during running the app I get that error everytime. Jetpack is in the project and I can use it but I can't run the app.
Execution failed for task ':myModule:prepareDebugKotlinCompileTask'.
Could not resolve all files for configuration ':myModule:kotlin-extension'.
Could not find androidx.compose:compose-compiler:1.0.0-alpha05.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/compose/compose-compiler/1.0.0-alpha05/compose-compiler-1.0.0-alpha05.pom
My module's Gradle file:
plugins {
id("po-android-library")
id("kotlin-kapt")
id("de.mannodermaus.android-junit5")
}
android {
defaultConfig {
renderscriptTargetApi = AndroidSdkVersions.target
renderscriptSupportModeEnabled = true
vectorDrawables.useSupportLibrary = true
}
buildFeatures {
compose = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
composeOptions {
kotlinCompilerVersion = "1.4.0"
kotlinCompilerExtensionVersion = "1.0.0-alpha05"
}
kotlinOptions {
jvmTarget = "1.8"
useIR = true
}
testOptions.unitTests.isIncludeAndroidResources = true
sourceSets {
val sharedTestDir = "src/sharedTest/java"
getByName("test") {
java.srcDir(sharedTestDir)
}
}
packagingOptions {
pickFirst("mockito-extensions/org.mockito.plugins.MockMaker")
exclude("META-INF/rxjava.properties")
exclude("META-INF/rxkotlin.properties")
}
}
dependencies {
implementation(project(":common"))
implementation(project(":android-common"))
implementation(Deps.kotlin_stdlib)
implementation("com.android.tools.build:gradle:4.1.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
implementation(Deps.androidx_appcompat)
implementation(Deps.koin_android_viewmodel)
implementation(Deps.koin_androidx_ext)
implementation(Deps.koin_android)
implementation(Deps.rxkotlin)
implementation("androidx.compose.runtime:runtime:1.0.0-alpha05")
implementation("androidx.compose.ui:ui:1.0.0-alpha05")
implementation("androidx.compose.foundation:foundation-layout:1.0.0-alpha05")
implementation("androidx.compose.material:material:1.0.0-alpha05")

From Compose compiler version 1.0.0-alpha04, we should use Android Studio 4.2 Canary 13 or later and com.android.tools.build:gradle version should be 4.2.0-alpha13
From the Official site reference

Related

How to make android and spring to exists together as modules in one project?

:) Last days I did some kotlin projects just for fun. Every project was created in kotlin as web app (spring) and mobile (android). I started to wondering if there is possibility to configure multimodule project where spring and android can be stored together as modules? I read some articles about multimodule projects but usually about web apps only. I tried doing something on my own but and nothing worked ;p
Here are my gradle files:
setting.gradle.kts (spring web)
rootProject.name = "web"
build.gradle.kts (spring web)
plugins {
id("org.springframework.boot") version "3.0.1"
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.7.22"
kotlin("plugin.spring") version "1.7.22"
kotlin("plugin.jpa") version "1.7.22"
}
group = "pl.mattiahit.myrestaurant.web"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.modelmapper:modelmapper:3.1.1")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
build.gradle.kts (android)
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "pl.mattiahit.myrestaurant.mobile"
compileSdk = 32
defaultConfig {
applicationId = "pl.mattiahit.myrestaurant.mobile"
minSdk = 24
targetSdk = 32
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("com.android.support:appcompat-v7:28.0.0")
implementation("com.android.support.constraint:constraint-layout:2.0.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
}
settings.gradle.kts (parent)
rootProject.name = "MyRestaurant"
include("web")
include("mobile")
build.gradle.kts (parent)
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
}
}
Im getting error
A problem occurred configuring root project 'MyRestaurant'.
> Could not resolve all files for configuration ':classpath'.
> Cannot resolve external dependency org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0 because no repositories are defined.
Required by:
project :
I have no experience with such projects... can anyone help me with that? Is there any good article about mulimodule projects etc ?
As the error implies, you're missing the repositories block inside your top-level ("parent") build.gradle.kts:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
}
}

How to properly call groovy gradle method from kotlin dsl

I have separate groovy script that adds flavors to my android project. And i can apply it no problem in build.gradle files. But calling it from kotlin build.gradle.kts file im getting error.
I have flavors.gradle file
ext.configFlavors = {
flavorDimensions "brand"
productFlavors {
myBrand {
dimension "brand"
}
}
And i can easilly call this from build.gradle files
android{
...
with configFlavors
}
But in build.gradle.kts files i get:
Could not find method flavorDimensions() for arguments [brand] on project ': myModule' of type org.gradle.api.Project.
My build.gradle.kts looks like this:
import com.android.build.gradle.LibraryExtension
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
apply(from ="${rootProject.projectDir}/buildSrc/flavors.gradle" )
val configFlavors: groovy.lang.Closure<LibraryExtension> by extra
android {
compileSdk = Versions.compile_sdk_version
defaultConfig {
minSdk = Versions.min_sdk_version
targetSdk = Versions.target_sdk_version
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
//Dev
create("dev") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
//Staging
create("staging") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
//Production
create("production") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
// I am able to call the closure but i got the error
configFlavors()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
}
}
dependencies {
implementation(fileTree("include" to listOf("*.jar"), "dir" to "libs"))
implementation(project(":domain"))
// list of dependencies
}
Extra properties can be accessed with the following syntax:
// get an extra property from the current project
val myProperty: String by extra
// or from the root project
val myNewProperty: String by rootProject.extra
However, configFlavours is not a simple primitive value, it's a Closure.
It's possible to access Closures in Kotlin, but without knowing what type the Closure should apply to, it's not possible to use it.
// Replace `Any` with the actual type, if known
val configFlavours: groovy.lang.Closure<Any> by extra
println(configFlavours)
// > Configure project :
// flavours_atn69ibjqzvnwf0cp7hb75l45$_run_closure1#398b577e
There are more through examples in the Gradle docs
P.S. your code has both flavour and flavor - pick a spelling please :)
I ended up adding another closure that takes libraryExtension as parameter. And using it from gradle.build.kts files. It is not optimal but it seems to work.
ext.configFlavorsWithParam = { libraryExtension ->
libraryExtension.flavorDimensions "brand"
libraryExtension.productFlavors {
brand1 {
dimension "brand"
}
}
And im calling it like this
android{
...
configFlavorsWithParam(this)
}

Unresolved reference Issue in Android Gradle Kotlin Dsl

i migrated my gradle file to kotlin dsl from groovy. Everything works fine but there is a problem with improting values to gradle from another kotlin file. I can import variables and autocomplete just works fine but when i build project, it gives me Unresolved reference error.
Appreciate any help.
Gradle version : 7.1.1
Android studio : Arctic Fox
build.gradle.kts that i created under buildSrc :
plugins {
`java-gradle-plugin`
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
}
repositories {
mavenCentral()
}
File that i import from in buildSrc/src/main/java/Dependencies :
object Versions {
const val compose_version = "1.0.0"
}
object Dependencies {
const val compose_ui = "androidx.compose.ui:ui:${Versions.compose_version}"
const val compose_material = "androidx.compose.material:material:${Versions.compose_version}"
const val compose_ui_tooling_preview = "androidx.compose.ui:ui-tooling-preview:${Versions.compose_version}"
const val compose_ui_tooling = "androidx.compose.ui:ui-tooling:${Versions.compose_version}"
const val compose_ui_test = "androidx.compose.ui:ui-test-junit4:${Versions.compose_version}"
}
app build.gradle.kts file :
plugins {
id("com.android.application")
kotlin("android")
}
android {
compileSdk = 30
defaultConfig {
applicationId = "com.example.compose"
minSdk = 21
targetSdk = 30
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
debug {
isMinifyEnabled = false
isDebuggable = true
}
release {
isMinifyEnabled = true
isDebuggable = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.0.0"
}
packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("com.google.android.material:material:1.4.0")
// Jetpack Compose
implementation(Dependencies.compose_ui)
implementation(Dependencies.compose_material)
implementation(Dependencies.compose_ui_tooling_preview)
debugImplementation(Dependencies.compose_ui_tooling)
androidTestImplementation(Dependencies.compose_ui_test)
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
implementation("androidx.activity:activity-compose:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}
You said that your other file is under buildSrc/src/main/java/Dependencies. Since this is a Kotlin file, it should be buildSrc/src/main/kotlin/Dependencies instead.

How can I add docstrings to android maven-publish .aar files in build.gradle.kts?

I have a project with the standard java library and this creates several .jar files, one being a docset and another the source set. Now I have successfully created an android-library using the maven-publish plugin, but when I add the .aar files to another project, they don't contain neither source nor comments as the .jar version did, so I don't get help inside the IDE or look into the implementation of methods.
What do I need to add to my build.gradle.kts to include docstrings and sources in the debug version of the .aar I'm publishing locally as a file? The linked gradle documentation from that Android developer page does not mention anything about docstrings or sources at all.
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
}
group = "com.wavelt.libs"
version = "1.0.0"
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes")
}
}
dependencies {
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.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")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test:rules:1.0.2")
}
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
repositories {
maven {
// https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories
url = uri("$buildDir/repository")
}
}
publications {
create<MavenPublication>("debug") {
// Applies the component for the release build variant.
from(components["debug"])
artifactId = "wavelt-android-debug"
artifact("androidJavadocsJar") // Doesn't seem to work
}
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
artifactId = "wavelt-android"
}
}
}
}
While I've read about other devs being able to cram the javadocs into the .aar file, this is not explicitly necessary at all to gain documentation and source code inspection from inside IDEs like Android Studio. In fact, looking at the way a typical java library works, it creates files like:
foo-ver.jar
foo-ver-sources.jar
foo-ver-javadoc.jar
The only difference with an Android library would be having these files:
foo-ver.aar
foo-ver-sources.jar
foo-ver-javadoc.jar
Which means that the sources and javadoc jars can still be copied along the .aar and the IDE will load them. Having said that, the publish example code only creates the .aar file, looking at other questions like this one I was able to modify the script to create the .aar plus the two other .jar packages:
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
id("org.jetbrains.dokka") version "0.9.17"
}
group = "com.wavelt.libs"
version = "1.0.0"
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes")
}
}
dependencies {
//implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.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")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test:rules:1.0.2")
}
tasks.dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
moduleName = rootProject.name
}
val dokkaJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokka)
dependsOn(tasks.dokka)
}
val sourcesJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles sources JAR"
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
}
artifacts {
archives(sourcesJar)
archives(dokkaJar)
}
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
repositories {
maven {
// https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories
url = uri("$buildDir/repository")
}
}
publications {
create<MavenPublication>("debug") {
// Applies the component for the release build variant.
from(components["debug"])
artifactId = "wavelt-android-debug"
artifact(sourcesJar)
artifact(dokkaJar)
}
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
artifactId = "wavelt-android"
}
}
}
}
With these modifications the ./gradlew publish task will generate all files, and despite one of them having .aar they work the same as .jar when copied together into another project.

Jetpack Compose setup issue: Unable to load class 'org.jetbrains.kotlin.gradle.tasks.KotlinCompile'

I have a new Android project and I want to make use of Jetpack Compose, but following the steps outlined here gives me the following build error:
Unable to load class 'org.jetbrains.kotlin.gradle.tasks.KotlinCompile'.
This is an unexpected error. Please file a bug containing the idea.log file.
Perhaps I'm compounding the issue by using Kotlin DSL build.gradle.kts, but here's my gradle setup:
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
android {
compileSdkVersion(30)
defaultConfig {
applicationId = "..."
minSdkVersion(24)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}
buildFeatures {
dataBinding = true
compose = true
}
kotlinOptions {
jvmTarget = "1.8"
useIR = true
}
composeOptions {
kotlinCompilerVersion = "1.4.20"
kotlinCompilerExtensionVersion = "1.0.0-alpha08"
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
//...
}
Try '1.0.0-alpha09'and Kotlin version "1.4.21" and you should be good to go.
Have you got this in your buildscript?
buildscript {
ext {
compose_version = '1.0.0-alpha09'
}
ext.kotlin_version = "1.4.21"

Categories

Resources