groovy.lang.MissingMethodException: No signature of method: ApplicationVariantData.getName() - android

This question has been asked a lot of times on SO, but I was not able to find any solution that could work for me.
I am trying to migrate from groovy to kotlin DSL and getting the following error.
All the conversion is done into kotlin DSL, but when I am trying to sync the issue starts to appear. I am using the latest version of android gradle plugin.
A problem occurred configuring project ':app'.
Failed to notify project evaluation listener.
com.android.build.gradle.internal.crash.ExternalApiUsageException: groovy.lang.MissingMethodException: No signature of method: com.android.build.gradle.internal.variant.ApplicationVariantData.getName() is applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), getClass()
KotlinJvmAndroidCompilation with name 'debug' not found.
Please let me know what can be done in this, Thanks in advance.
plugins {
id("com.android.application")
id("com.google.firebase.crashlytics")
id("io.hansel.preprocessor")
id("com.google.firebase.firebase-perf")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("com.google.gms.google-services")
}
buildscript {
apply("../buildSrc/config.gradle.kts")
}
repositories {
maven { url = uri(Config.Repositories.hansel_io) }
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs("libs")
}
}
}
android {
signingConfigs {
....
}
}
defaultConfig {
...
}
buildTypes {
getByName("debug") {
...
}
getByName("release") {
...
}
}
flavorDimensions("version")
productFlavors {
create("development") {
...
}
applicationVariants.all {
val variant = this
variant.outputs
.map { it as BaseVariantOutputImpl }
.forEach { output ->
....
}
}
}
compileOptions {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
buildFeatures {
dataBinding = true
}

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")
}
}

SourceSet with name 'main' not found

I'd like to Maven publish in my Android app, and I'm using kotlin-dsl for gradle files. This is how I'm trying to publish my code:
subprojects {
plugins.apply("maven-publish")
afterEvaluate {
// Common settings
if (isAndroidLibrary || isAndroidApplication) {
extensions.getByType<com.android.build.gradle.BaseExtension>().apply {
compileSdkVersion(CommonVersions.targetsdk)
buildToolsVersion = CommonVersions.buildTools
defaultConfig {
minSdkVersion(CommonVersions.minsdk)
targetSdkVersion(CommonVersions.targetsdk)
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildFeatures.viewBinding = true
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
}
// Set up publishing configuration
val sourceSets: SourceSetContainer by project
print("project name: $name, ")
print("project size: ${sourceSets.size}, ")
print("project size: ${project.the<SourceSetContainer>().size}, ")
print("project size: ${the<SourceSetContainer>().size}, ")
if (!notPublishingModules.contains(name) && sourceSets.size != 0) {
configure<PublishingExtension> {
publications {
create<MavenPublication>("maven") {
groupId = "xx.yyy.zz"
artifactId = "test"
version = "0.0.0"
from(components.findByName("release"))
val sourcesJar by tasks.creating(Jar::class) {
val sourceSets: SourceSetContainer by project
from(sourceSets["main"].allJava)
classifier = "sources"
}
artifact(sourcesJar)
}
}
}
}
}
}
I always get this error: SourceSet with name 'main' not found.
As you can see I was trying to print the sourceset out, to see if it has any information or not. The size of the sourceset is always zero.
What am I doing wrong?
I use groovy with spring applications , I think you missing this in your code
sourceSets {
main {
java { srcDirs = ["src/java"] }
resources { srcDir "src/resources" }
}
}
where you define where is srcDirs are .

GRPC in Kotlin Multiplatform (Android, Desktop)

I am creating a Jetbrains Compose Multiplatform project. But I will only need Desktop (JVM) and Android, so two JVM targets. I want to factor out the logic which needs grpc, so both Android and Desktop can use it without me having to program it twice.
I can't seem to figure out a way of binding in my grpc/proto into the project, so that I can write the logic once and share it between android and desktop.
This is what my build.gradle.kts of the common project looks like:
plugins {
id("com.android.library")
kotlin("multiplatform")
id("org.jetbrains.compose")
}
kotlin {
android()
jvm("desktop")
sourceSets {
named("commonMain") {
dependencies {
api(compose.runtime)
api(compose.foundation)
api(compose.material)
api(compose.ui)
implementation(compose.preview)
implementation(compose.uiTooling)
}
}
}
}
android {
compileSdk = 31
defaultConfig {
minSdk = 21
targetSdk = 31
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/res")
}
}
}
I tried binding my protos into a sourceset but couldn't get it working.
My other approach:
Next I tried creating a second submodule where the protos and the logic would be bound, but I couldn't get that working either:
Here is the build.gradle.kts for shared-logic:
import com.google.protobuf.gradle.*
import org.gradle.kotlin.dsl.proto
plugins {
kotlin("jvm")
idea
id("com.google.protobuf")
}
version = "unspecified"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
api(project(":kotlin-common")) {
exclude(group = "io.grpc", module = "grpc-protobuf")
exclude(group = "io.grpc", module = "grpc-stub")
}
implementation("io.grpc:grpc-okhttp:${Versions.GRPC}")
api("com.google.protobuf:protobuf-java-util:${Versions.PROTOBUF}")
api("io.grpc:grpc-stub:${Versions.GRPC}")
api("io.grpc:grpc-protobuf-lite:${Versions.GRPC}")
api("io.grpc:grpc-kotlin-stub:${Versions.GRPC_KOTLIN}")
api("com.google.protobuf:protobuf-kotlin-lite:${Versions.PROTOBUF}")
api("io.insert-koin:koin-core:${Versions.KOIN}")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.COROUTINES}")
}
sourceSets {
main {
proto {
srcDirs("../protos/src/main")
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${Versions.PROTOBUF}"
}
plugins {
id("java") {
artifact = "io.grpc:protoc-gen-grpc-java:${Versions.GRPC}"
}
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${Versions.GRPC}"
}
id("grpckt") {
artifact = "io.grpc:protoc-gen-grpc-kotlin:${Versions.GRPC_KOTLIN}:jdk7#jar"
}
}
generateProtoTasks {
all().forEach {
it.plugins {
id("grpc") {
option("lite")
}
id("grpckt") {
option("lite")
}
}
it.builtins {
id("kotlin") {
option("lite")
}
}
}
}
}
Here is the build.gradle.kts for kotlin-common:
plugins {
kotlin("jvm")
}
version = "1.0.0"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
implementation("io.grpc:grpc-stub:${Versions.GRPC}")
}
Here I get resolution error I tried fixing but couldn't figure out what to exclude:
Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-java-3.19.1 (com.google.protobuf:protobuf-java:3.19.1) and jetified-protobuf-javalite-3.19.1 (com.google.protobuf:protobuf-javalite:3.19.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-java-3.19.1 (com.google.protobuf:protobuf-java:3.19.1) and jetified-protobuf-javalite-3.19.1 (com.google.protobuf:protobuf-javalite:3.19.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules jetified-protobuf-java-3.19.1 (com.google.protobuf:protobuf-java:3.19.1) and jetified-protobuf-javalite-3.19.1 (com.google.protobuf:protobuf-javalite:3.19.1)
...

How to use Android Gradle without multi-project

I would like to create an android build with a single build.gradle file. How to do that?
You need at least two build.gradles, a project-level one and a module-level one. They are not the same. You can omit neither of them.
It actually is possible.
The whole problem when trying to create an Android build with a single build.gradle comes from the fact, that a plugins block of the top-level build.gradle can only use plugins from Gradle plugin portal and cannot address anything from buildscript's classpath.
However, there is a pluginManagement block you can add to settings.gradle, that can be used to modify how plugins are resolved.
A working example:
// settings.gradle.kts
rootProject.name = "android_app"
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
resolutionStrategy {
eachPlugin {
if (requested.id.name.startsWith("com.android")) {
useModule("com.android.tools.build:gradle:${requested.version}")
}
}
}
}
// build.gradle.kts
plugins {
id ("com.android.application") version "4.2.2"
}
group = "pl.gieted.android_app"
version = "1.12-SNAPSHOT"
android {
compileSdkVersion(31)
defaultConfig {
applicationId = group.toString()
minSdkVersion(24)
targetSdkVersion(31)
versionName = version.toString()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}

Android Kotlin DSL - Unresolved reference: firebaseAppDistribution

I just migrated my Andoroid project's build system from Groovy to Kotlin DSL. On migrating, I'm unable to solve firebaseAppDistribution { .. } in build.gradle.kts.
The plugin for the FAD has already been apllied and the classpath as well.
plugins {
id("com.android.application")
//id("com.google.firebase.appdistribution") //I've tried it here but "Plugin not found"
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("com.google.gms.google-services")
}
apply(plugin = "com.google.firebase.appdistribution")
buildscript {
repositories {
google()
}
dependencies {
classpath("com.google.firebase:firebase-appdistribution-gradle:1.3.1")
}
}
.
.
productFlavors {
create("dev") {
firebaseAppDistribution {
serviceCredentialsFile = "xxx.json"
groups = "xx"
}
}
}
.
.
**Unresolved reference: firebaseAppDistribution**
How do I fix it ?
You could use :
import com.google.firebase.appdistribution.gradle.AppDistributionExtension
productFlavors {
create("dev") {
configure<AppDistributionExtension> {
serviceCredentialsFile = "path/to/serviceAccountKey.json"
releaseNotes="you release note"
...
}
}
}

Categories

Resources