Could not resolve git repository as dependency in android gradle - android

I am trying to add a git repository (https://github.com/FHNW-IP5-IP6/ComposeForms) as a dependency into my project with Gradle and tried the below-listed variants (1.-3.) from Is it possible to declare git repository as dependency in android gradle? but every time when I sync the project I get an Error saying: "Could not resolve com.github.FHNW-IP5-IP6:ComposeForms:master-SNAPSHOT".
I tried the following:
Jitpack (https://jitpack.io/#FHNW-IP5-IP6/ComposeForms/master-SNAPSHOT)
allprojects {
repositories {
...
maven("https://jitpack.io") // also tried uri https://www.jitpack.io
}
}
and in app build.gradle
kotlin {
sourceSets {
named("main") {
dependencies {
...
implementation("com.github.FHNW-IP5-IP6:ComposeForms:master-SNAPSHOT")
}
}
}
}
Git Submodule (named as compose-forms)
include(":compose-forms") inside settings.gradle
kotlin {
sourceSets {
named("main") {
dependencies {
...
implementation(project(":compose-forms"))
}
}
}
}
New feature in gradle
Inside settings.gradle
sourceControl {
gitRepository(uri("https://github.com/FHNW-IP5-IP6/ComposeForms.git")) {
producesModule("compose-forms")
}
}
and in app build.gradle
kotlin {
sourceSets {
named("main") {
dependencies {
...
implementation("compose-forms") {
version {
branch = "master"
}
}
}
}
}
}
I'm running out of options and really need the git repository as a dependency. I would prefer not to have any git submodules inside my project so I prefer numbers 1 and 3 to work. Thanks in Advance for any hint :)

Open Android Studio as Administrator then add maven { url 'https://jitpack.io' } to both, build.gradle(project) and settings.gradle(project) and the respective implementation [...] to build.gradle(:app). This worked for me as every other solution proposed failed.

Related

Setting up Protobuf + Kotlin in Android Studio 2023

I spend hours on just setting up Protobuf with Kotlin in Android Studio. The endgoal is just that my proto files are compiled in Kotlin and that I can use them in my project.
I have an example project here: https://github.com/Jasperav/ProtobufAndroid. It mimics my setup in the real application: an external dir containing the proto files and the android project. It contains all the code mentioned below. This is a combined effort of tutorials I found on the internet. It is probably terrible wrong. I tried https://github.com/google/protobuf-gradle-plugin, but it just looks so complicated for something simple I am doing:
Have a dir with protofiles somewhere on your filesystem
Create a new Android project on Kotlin
In the Project build.gradle, add id 'com.google.protobuf' version '0.9.2' apply false as plugin
In the Module build.gradle, add ->
This to the dependencies: implementation 'com.google.protobuf:protobuf-lite:3.21.12'
The sourceSets at the bottom inside the android bracket
The protobuf section at the bottom between the dependencies and android section.
sourceSets:
sourceSets {
main {
kotlin {
srcDirs += 'build/generated/source/proto/main/kotlin'
}
proto {
srcDir '/Users/me/androidkotlin/proto'
}
}
}
protobuf:
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.21.12'
}
plugins {
kotlinlite {
artifact = 'com.google.protobuf:protoc-gen-kotlin:3.21.12'
}
}
generateProtoTasks {
ofSourceSet("main").forEach { task ->
task.builtins {
getByName("kotlin") {
option("lite")
}
}
}
}
}
I get this error:
A problem occurred evaluating project ':app'.
> Could not find method proto() for arguments [build_cxwfo79b6zcc266x9rsqzou9f$_run_closure1$_closure8$_closure10$_closure12#203aac02] on source set main of type com.android.build.gradle.internal.api.DefaultAndroidSourceSet.
You are in a good way, but, there is some stuff missing:
The gradle code I'll share is written in Kotlin, just in case. If you can convert your grade files to Kotlin, nice, if not you have to convert them to groovy.
The first thing to check is if you have the proto folder in the right path, it should be in
root->app->src->main->proto
In the project gradle make sure to have the plugin applied
id("com.google.protobuf") version "0.8.15" apply false
In the app gradle, make sure to have the following.
import com.google.protobuf.gradle.*
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.protobuf")
}
The dependencies:
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
implementation("com.google.protobuf:protobuf-kotlin:3.21.2")
implementation("io.grpc:grpc-stub:1.52.0")
implementation("io.grpc:grpc-protobuf:1.52.0")
implementation("io.grpc:grpc-okhttp:1.52.0")
implementation("com.google.protobuf:protobuf-java-util:3.21.7")
implementation("com.google.protobuf:protobuf-kotlin:3.21.2")
implementation("io.grpc:grpc-kotlin-stub:1.3.0")
And the protobuf task:
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${rootProject.ext["protobufVersion"]}"
}
plugins {
id("java") {
artifact = "io.grpc:protoc-gen-grpc-java:${rootProject.ext["grpcVersion"]}"
}
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${rootProject.ext["grpcVersion"]}"
}
id("grpckt") {
artifact = "io.grpc:protoc-gen-grpc-kotlin:${rootProject.ext["grpcKotlinVersion"]}:jdk8#jar"
}
}
generateProtoTasks {
all().forEach {
it.plugins {
id("java") {
option("lite")
}
id("grpc") {
option("lite")
}
id("grpckt") {
option("lite")
}
}
it.builtins {
id("kotlin") {
option("lite")
}
}
}
}
}
These are the versions I'm using:
ext["grpcVersion"] = "1.47.0"
ext["grpcKotlinVersion"] = "1.3.0" // CURRENT_GRPC_KOTLIN_VERSION
ext["protobufVersion"] = "3.21.2"
ext["coroutinesVersion"] = "1.6.2"
Having that your project should generate the code based on your proto files.
For further reference, I recently build this Android App based on Kotlin + gRPC: https://github.com/wilsoncastiblanco/notes-grpc

Gradle can't resolve androidx.ui:ui-tooling dependency by google() repository

I want to use the #Preview annotation in my brand new Jetpack Compose for Desktop project. However gradle is just not getting it done to fetch the dependecy for that.
my build.gradle.kts:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
kotlin("jvm") version "1.4.0"
// __LATEST_COMPOSE_RELEASE_VERSION__
id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.1.0-build113")
}
repositories {
jcenter()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
buildscript {
repositories {
google()
}
dependencies {
classpath("androidx.ui:ui-tooling:1.0.0-alpha07")
}
}
dependencies {
implementation(compose.desktop.currentOs)
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "KotlinJvmComposeDesktopApplication"
}
}
}
It just is not being resolved
Accordingly to the documentation, it should be working for alpha07, but for alpha08 it changed to androidx.compose.ui:ui-tooling:1.0.0-alpha08, so, if you can upgrade to alpha08, you can see if it works.
https://developer.android.com/jetpack/androidx/releases/ui#declaring_dependencies

How to reuse parts of Android configuration in Kotlin Gradle DSL for multiple modules?

I have a multi-module Android project & Kotlin Gradle DSL. There is some configuration which has to be repeated in every module and I would like to reuse the code. I would like to reuse for example this code:
android {
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
getByName("test").java.srcDirs("src/test/kotlin")
}
}
There are two methods documented in Kotlin DSL samples:
apply(from = "foo.gradle.kts")
and extension functions in buildSrc like this:
fun Project.kotlinProject() {
dependencies {
"compile"(kotlin("stdlib"))
}
}
However both these methods work only for top-level configuration, I can't access Android plugin's stuff. I'm getting errors like Unresolved reference: BaseExtension
At the end I was inspired by SUPERCILEX's code:
allprojects {
val parent = (group as String).split(".").getOrNull(1)
when {
name == "app" -> {
apply(plugin = "com.android.application")
configureAndroidModule()
}
parent == "common-android" -> {
apply(plugin = "com.android.library")
configureAndroidModule()
}
}
}
fun Project.configureAndroidModule() {
configure<BaseExtension> {
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
getByName("test").java.srcDirs("src/test/kotlin")
}
}
}​
How about using subprojects block? I have a multi-module Android project and this is how I reuse code in my build scripts.
subprojects {
apply plugin: 'com.android.library'
android {
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
getByName("test").java.srcDirs("src/test/kotlin")
}
}
}
Unresolved reference: BaseExtension
As for the above error message, if you want to use android block, you should declare your modules as android application or library by applying plugins like above build script.
If you want the settings to be repeated in only some of the modules, you can use configure block like this:
configure(subprojects - project(':${module_name}')) {
dependencies {
implementation 'com.x.y.z:abc:1.0.0'
}
}
The above block will define the dependency on all modules except the module with the given name.

insert plugin into Android gradle build using init.gradle

F-Droid is a free software app store for Android. We enforce that apps are 100% free software, so its something like Debian for Android. Since most Android apps use gradle, it makes sense to use gradle tricks to automate our enforcement. The 'com.jaredsburrows.license' plugin is one kind of thing we'd like to automatically inject into every build. init.gradle should be able to do this, but I can't quite figure out how to insert the plugin into the Android plugin. Here's where I got:
apply plugin: FDroidLicenseCheck
class FDroidLicenseCheck implements Plugin<Gradle> {
def supportedPlugins = [
'org.gradle.api.plugins.JavaPlugin',
'com.android.build.gradle.AppPlugin'
]
void apply(Gradle gradle) {
println('applying license check')
def added = false
gradle.allprojects { project ->
project.with {
if (parent == null) {
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jaredsburrows:gradle-license-plugin:0.5.0"
}
}
}
plugins.whenPluginAdded { plugin ->
println('Checking ' + plugin.class.name)
if (!added && supportedPlugins.contains(plugin.class.name)) {
println('Adding to ' + plugin.class.name)
rootProject.apply plugin: 'com.jaredsburrows.license'
added = true
}
}
}
}
}
}

Cannot add Tweet Composer dependency

I'm trying to add new TweetComposer to my project at module "app":
dependencies {
compile('com.twitter.sdk.android:tweet-composer:1.0.5#aar') {
transitive = true;
}
}
And I always got error like this:
Error:Could not find com.twitter.sdk.android:tweet-composer:1.0.5.
Required by:
reader-android:app:unspecified
Search in build.gradle files
I found the issue:
add at project level the following code
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
And at application level
dependencies {
compile('com.twitter.sdk.android:tweet-composer:1.0.5#aar') {
transitive = true;
}
}
You should then be able to sync Gradle correctly, let me know if that works for you!
Reference here

Categories

Resources