I am trying to upgrade this Modular project to latest dependencies but gradle build fails with could not resolve androidx.room:room-runtime:2.4.2 I have aleady included mavenCentral() to repositories but doesn't seem to help.
Note: same versions work on different app with monolithic architecture, not sure modular architecture has anything to do with it.
app/build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:${Versions.gradle}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.nav}"
}
}
buildSrc/build.gradle
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
mavenCentral()
}
dependencies.kts
object Versions {
const val kotlin = "1.6.10"
const val gradle = "7.0.2"
const val room = "2.4.2"
...
}
object Libraries {
const val roomCompiler = "androidx.room:room-compiler:${Versions.room}"
const val roomRunTime = "androidx.room:room-runtime:${Versions.room}"
const val roomKtx = "androidx.room:room-ktx:${Versions.room}"
...
}
Here is a link to my Git Repo
Cheers!
I've clone your repository in upgrade branch. It seems the module doesn't get the repository.
It's because your :data:model module is used as plain kotlin project, and it can't implement room library. In fact, many of your module is not registered as Android Library.
If you intent to use the module to setup Android configuration or use android library like room, please implement library plugin in your build.gradle.
I suppose you can implement "com.android.library" to all your modules first, and please for the love of god... do a better gradle configuration for your modules.
Related
I am in the process of migrating buildSrc convention plugins into standalone plugins. There are a lot of examples for creating Gradle plugins for Project objects, but a real dearth for Settings and Gradle. I want to centralize the list of repositories that we use in our gradle.settings.kts files, so I've created a Gradle Settings plugin: RepositoriesPlugin.
It is implemented in the same manner at a Project plugin, however, I am unsure about how to interpret the following quote from Gradle's docs: "A plugin can instead receive a parameter of type Settings, in which case the plugin can be applied in a settings script.", as stated in the documentation at this link: Gradle 7.2 Doc
The following example shows how I've applied my settings plugin in a settings.gradle.kts file. Is this how a settings plugin is applied, as per the documentation?
I've included the basic settings plugin code, below, too.
I'd appreciate your help to clarify that I am doing this properly. I am sure that this posting will help others who stray away from just Project plugins.
Thanks for your time and interest..
// settings.gradle.kts
pluginManagement {
plugins {
id("com.abitofhelp.gradle.plugins.repositoriesplugin") version "1.0.0-1"
}
settings.extensions
getByType(RepositoriesPluginExtension::class).apply {
localRepoName = "local-repo"
localRepositoryPath = "../../local-repo"
}
// Set the plugin repositories for all projects.
//repositories {
// maven { name = "localRepo"; url = uri(file("./local-repo")) }
// gradlePluginPortal()
// mavenCentral()
//}
}
// repositoriesplugin.kt
open class RepositoriesPlugin: Plugin<Settings> {
override fun apply(settings: Settings) {
val extension: RepositoriesPluginExtension =
settings.extensions.create("repositoriesPlugin", RepositoriesPluginExtension::class.java)
val localRepositoryName = extension.localRepositoryName?.let { it }?: "../../localRepo"
val localRepositoryPath = extension.localRepositoryPath?.let { it }?: "../../local-repo"
settings.pluginManagement.repositories.apply {
// Set the PLUGIN REPOSITORIES for all subprojects.
maven { repository ->
repository.name = localRepositoryName
repository.url = URI.create(localRepositoryPath)
}
gradlePluginPortal()
mavenCentral()
}
settings.dependencyResolutionManagement.repositories.apply {
// Set the DEPENDENCY REPOSITORIES for all subprojects.
maven {
it.name = localRepositoryName
it.url = URI.create(localRepositoryPath)
}
mavenCentral()
gradlePluginPortal()
}
}
}
I just had to figure this out myself. You weren't far off with your initial attempt but the plugins block actually has to go after the pluginManagement block. The basic layout of my working implementation looks like this:
// settings.gradle.kts
rootProject.name = "myProject"
pluginManagement {
repositories {
maven {
url = uri("/tmp/maven-local")
gradlePluginPortal()
}
}
}
plugins {
id("com.example.my-plugin") version "1.0-SNAPSHOT"
}
I believe you need to add the plugin to settings.gradle classpath via buildscript closure. pluginManagement.plugins makes the plugin availabile to the root (& sub) project build.gradle classpath, but I think that is a different classpath from the settings.gradle script.
To add to settings gradle, give this a try:
// settings.gradle
buildscript {
repositories {
maven { url "http://repo.where.plugin.is.published" }
}
classpath("complete.maven.coordinates:your-settings-plugin:version")
}
pluginManager.apply(your.settings.plugin.id)
As Justin Warkentin already noted, you first need to add your repo in the pluginManagement section and then you can apply your plugin like any other.
If you want to bypass the repository, you can also add the plugin project as composite build via includeBuild in the pluginManagement section.
In my example I have combined both methods. If the plugin project exists locally, this one is used, otherwise the version from the repo is used. This way you can (temporarily) add your plugin project to develop on it and test it directly in including projects.
pluginManagement {
repositories {
// your plugin repo; maybe...
mavenLocal()
}
// use local copy of your plugin if available,
// otherwise load plugin from repo
def name = 'your_plugin_project'
if (file(name).isDirectory()) {
includeBuild(name)
}
}
plugins {
// apply your plugin
id 'your.plugin.id'
}
I have a sdk and a client app. The client app is using the sdk. When I build the sdk, it generates multiple aar files which I can add it in libs folder in my client project.
Now if I modify the sdk, every time I need to build the sdk code using gradlew and then add the aar in client code. This is becoming a lengthy process.
My top level build.gradle file looks like below:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.2'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Is there a way to link the sdk code with client code. So the sdk changes will be automatically picked by the client code. I am using Android Studio 3.6.
Thanks,
Arindam.
you can use the maven, or maven-publish to publish to your own maven repositories, it can be local. the config like that in build.gradle
uploadArchives {
repositories {
configuration = configurations.archives
mavenDeployer {
// the local repo address
repository(url: uri('../repo'))
pom.project {
version '1.0.1'
artifactId 'artifactId'
groupId 'groupId'
packaging 'aar'
description 'version 1.0.1'
}
}
}
}
then add this repository in project build.gradle
maven {
url "file://Users.../yourProject/repo/"
}
after that, you can use that as the third library. after you change it, you only need to execute it, then build the current project.
if you also want to look at the source code about SDK in the current project.
you can change to use maven-publish plugin.
I am making an app in Android Studio and I need to use GSON library. I have downloaded gson-2.8.2-javadoc. And then I followed this way
File->New->New Module->Import .JAR/.AAR
Package->gson-2.8.2-javadoc->Finish
After that
File->Project Structure->app->Dependencies->Module
Dependency->gson-2.8.2-javadoc->OK
but Android Studio did not recognize the Gson. I googled and saw the this as solution :
dependencies {
implementation 'com.google.code.gson:gson:2.8.2'
}
but this is not working too.
My gradle version was 4.4 and I upgraded it 4.9 , again this is not working too. Here is my build.gradle file:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
mavenCentral()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
By the way, I tried same ways different versions of Gson Library, it did not work as well. So, what is the reason for this issue? And What is the exact solution?
I think you may have to had
buildscript {
repositories {
mavenCentral()
}
}
allprojects {
repositories {
mavenCentral()
}
}
to your application build.gradle file. Then build and it will be good
At first, Make sure you removed gson MODULE from your Project.
Read How to delete a module in Android Studio ?
"File -> Project Structure" -> Select gson Module and then Click Red Mark Negative Sign.
FYI
You should use latest version.
implementation 'com.google.code.gson:gson:2.8.5'
Then Clean-Rebuild-Run.
I have a kotlin multiplatform project A setup for iOS and Android, it works well. It has a common module for sharing business logic, and platform-android and platform-ios module for implementing the platform API.
After I adding the common and platform-android module from project A to another Android project B, the Android Studio IDE reports tons of syntax error, but the codes build and run from Android studio without a problem.
The syntax looks like the kotlin-stdlib is not there while it's indeed in the build.gradle, otherwise it won't build.
For instance:
val filterMap = mutableMapOf<String, MenuFilter>()
Android studio will say Unresolved reference: mutableMapOf
Some facts:
common module has the problem
no problem for platform-android.
and of course, no problem when I use IDEA to edit project A
my build.gradle for common module looks like this:
apply plugin: 'kotlin-platform-common'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
}
sourceSets {
main.kotlin.srcDirs += 'main/'
test.kotlin.srcDirs += 'test/'
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.kotlin
}
artifacts {
archives sourcesJar
}
kotlin {
experimental {
coroutines "enable"
}
}
The rootProject build.gradle in Android Studio is:
buildscript {
ext{
kotlin_version = '1.2.41'
anko_version = '0.10.4'
dagger_version = '2.15'
support_lib_version = '27.1.1'
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the settings.gradle file for Android project B
def projectA_path = "path/to/projectA"
include(":common")
project(":common").projectDir = new File("$projectA_path/common")
include(":platforms:android")
project(":platforms:android").projectDir = new File("$projectA_path/platforms/android")
Even the two are from different projects, according to the setup here. Shouldn't the two just work? What am I missing here?
IDE version:
IDEA Ultimate 2018.1
Android studio 3.1.2
Try adding this in build.gradle
apply plugin: 'org.jetbrains.kotlin.multiplatform'
What is the preferred way to share some code (E.g. a Utils class) between two projects when building two apps using Gradle to build?
Can I do this without creating extra jar files? I just want my code to sit outside the app projects, be imported/compiled into both app projects. Or is this simply not possible?
I'm familiar with the approach that uses jars or Android library projects, but both seem a bit unwieldy.
My favorite way of doing this is by keeping it in a local Maven repo. The repo can even live in your SCM so it's the same across workspaces.
Create a new Android Studio project and then set it as a maven project your build.gradle config:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
repositories {
mavenCentral()
}
configurations {
archives {
extendsFrom configurations.default
}
}
group = 'com.mypackage.mylibrary'
version = '1.0.0'
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: uri("relative/path/to/localrepo"))
pom.project {
artifactId 'mylibrary'
name 'My Library'
packaging 'aar'
}
}
}
}
android {
// copy old android config here
}
You'll need to deploy the library before you can use it. Do this by using the uploadArchives task [./gradlew uploadArchives]
Now you should be able to use this library in any project by doing this:
repositories {
maven { url 'relative/path/to/localrepo' }
}
dependencies {
compile ('com.mypackage.mylibrary:1.0.0')
}
When you make changes to your library, you'll have to re-deploy (uploadArchives) with a new version, then update the dependency reference in whatever project needs the new version.