Android Kotlin DSL - Unresolved reference: firebaseAppDistribution - android

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

Related

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)
...

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

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
}

initWith not found after upgrading to Android Gradle Plugin version to 7.0.0-beta02

After upgrading to 7.0.0-beta02, initWith cannot be found.
In build.gradle.kts:
buildscript {
repositories {
....
}
dependencies {
- classpath("com.android.tools.build:gradle:7.0.0-alpha14")
+ classpath("com.android.tools.build:gradle:7.0.0-beta02")
}
}
then in app/build.gradle.kts:
debug {
...
}
create("enterprise") {
initWith(getByName("debug")) // <------ This is not found!
}
If this method is removed from the latest version, then what will be the equivalent of initWith?

Adding separately-compiled classfiles to JavaFXPorts apk

I'm having a build.gradle file with both the gradle-clojure and the javafxports plugins. It compiles fine, but I do have one problem:
The compiled Clojure class files get placed under build/clojure/main. Since javafxports doesn't know that, I end up with an APK file that contains everything except the actual project class files.
How do I tell Gradle/JavaFXPorts to include these files when packaging?
This is my current build.gradle:
buildscript {
repositories {
jcenter()
google()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.15'
}
}
plugins {
id 'gradle-clojure.clojure' version '0.4.0'
id 'application'
id 'com.github.johnrengelman.shadow' version '2.0.4'
id 'maven-publish'
}
repositories {
mavenCentral()
maven {
name = 'clojars'
url = 'https://repo.clojars.org'
}
}
dependencies {
compile 'org.clojure:clojure:1.9.0'
compile 'clojurefx:clojurefx:0.5.0-SNAPSHOT'
testImplementation 'junit:junit:4.12'
devImplementation 'org.clojure:tools.namespace:0.3.0-alpha4'
}
apply plugin: 'org.javafxports.jfxmobile'
group = 'lyrion'
version = '0.1.0-SNAPSHOT'
mainClassName = 'lyrion.cec'
clojure {
builds {
main {
aotAll()
}
}
}
jfxmobile {
javafxportsVersion = '8.60.9'
downConfig {
version = '3.8.5'
plugins 'cache', 'device', 'lifecycle', 'orientation', 'settings', 'storage'
}
android {
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'project.clj'
}
applicationPackage = 'lyrion'
}
}
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
}
}
repositories {
maven {
name = 'clojars'
url = 'https://repo.clojars.org'
credentials {
username = System.env['CLOJARS_USER']
password = System.env['CLOJARS_PASSWORD']
}
}
}
}

How to FTP a file from an Android Gradle build?

I'm trying to FTP the signed APK after a Gradle build. I've already added the new build config that will sign the APK, but I'm stuck trying to figure out how to invoke an FTP task.
I found an official looking sample at section 59.6, however it complains that it cannot resolve dependency org.apache.ant:ant-commons-net:1.8.4. So apparently I'm missing something obvious here, like where to put a given jar file or reference it, although I thought maven would handle this sort of thing?
For reference, here is the linked sample which fails with a message about the dependency:
configurations {
ftpAntTask
}
dependencies {
ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
module("commons-net:commons-net:1.4.1") {
dependencies "oro:oro:2.0.8:jar"
}
}
}
task ftp << {
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: "ftp.apache.org", userid: "anonymous", password: "me#myorg.com") {
fileset(dir: "htdocs/manual")
}
}
}
This fails with the message:
> Could not find org.apache.ant:ant-commons-net:1.8.4.
Here is my complete gradle.build file, with some sensitive information removed:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
signingConfigs {
signed {
storeFile file("(removed)")
storePassword "(removed)"
keyAlias "(removed)"
keyPassword "(removed)"
}
}
buildTypes {
signed {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.signed
}
}
}
configurations {
ftpAntTask
}
dependencies {
ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
module("commons-net:commons-net:1.4.1") {
dependencies "oro:oro:2.0.8:jar"
}
}
}
task ftp << {
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: "(removed)", userid: "(removed)", password: "(removed)", remoteDir: "(removed)") {
fileset(dir: "(removed)") {
include(name: "(removed)")
}
}
}
}
You havn't declared a repository that can be used to resolve the declared artifacts. Try adding the following snippet to your build.gradle file:
repositories{
mavenCentral()
}
cheers,
René
You can also use the native ant get task which supports FTP, works with no outside dependencies:
ant {
get(src: "ftp://<hostname>/remote/path/to/file.jar", dest: "/local/path/to/file", username: 'anonymous', password: 'anonymous')
}

Categories

Resources