Trying to add timber to Kotlin project results in multiple 'Unable to resolve dependency for...' Gradle errors - gradle

I have added implementation 'com.jakewharton.timber:timber:4.7.1' to my Kotlin project and now I get the following Gradle errors:
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.jakewharton.timber:timber:4.7.1.
Open File
Show Details
Strangely though I can see it downloading as Gradle syncs:
I also tried adding timberkt but got a similar error.
My whole app/build.gradle file looks like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
android {
compileSdkVersion 26
defaultConfig {
applicationId "uk.co.davechambers.pegboard"
targetSdkVersion 26
minSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary= true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.0.0-beta2'
implementation 'com.jakewharton.timber:timber:4.7.1'
compile "org.jetbrains.anko:anko:$anko_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
}
kotlin {
experimental {
coroutines "enable"
}
}
androidExtensions {
experimental = true
}
Clearly I'm doing something wrong. Can anybody point me in the right direction?

I added an additional Maven url to build.gradle (Module: app):
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "http://jcenter.bintray.com"}
}
and to build.gradle (Project: projectName):
buildscript {
ext.kotlin_version = '1.2.40'
ext.anko_version = '0.10.5'
ext.serialization_version = '0.4.1'
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "http://jcenter.bintray.com"}
}
.....
After that, everything worked.

Related

How do I configure KoTest with Gradle in a LibGdx project? Currently can't build because StringSpec is not recognised

I have a standard LibGdx project setup by the LibGdx tool, only targeting desktop. It uses Gradle (Groovy DSL) to manage dependencies and tasks. I've converted the core module to Kotlin, and I'm trying to add a Kotlin test module using Kotest.
I've followed the Kotest instructions for Gradle on their GitHub but the compile is failing because StringSpec isn't reocgnised (Unresolved reference: StringSpec). I think LibGdx's default Gradle setup may be a little outdated or use older syntax/structure, and perhaps it's conflicting with Kotest's instructions intended for newer versions of Gradle?
For now I've removed any test and am just trying to get it to recognise StringSpec and compile. I've not even reached the stage of getting IntelliJ to recognise and run the tests. Here's what I have so far:
core.tests/tests/com/me/game/AcceptanceTests.kt
package com.jansky.myproject
class AcceptanceTests : StringSpec() {
}
core.tests/gradle.build
version '1.0'
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "tests/" ]
tasks.withType(Test) {
useJUnitPlatform()
}
eclipse.project.name = appName + "-core.tests"
./build.gradle (ie the root buildfile)
buildscript {
ext.kotlinVersion = '1.3.71'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "game"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "kotlin"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
}
}
project(":core") {
apply plugin: "kotlin"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
}
}
project(":core.tests") {
apply plugin: "kotlin"
test {
useJUnitPlatform()
}
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
implementation 'io.kotest:kotest-runner-junit5:4.0.2'
implementation 'io.kotest:kotest-assertions-core:4.0.2'
}
}
settings.gradle
include 'desktop', 'core', 'core.tests'
Gradle-wrapper.properties
#Sat Apr 04 15:53:20 BST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
I don't have much JVM experience, so I'm at a bit of a loss. Hopefully I've missed something that's obvious to someone that knows Gradle better. Any ideas?

AndroidX. Could not determine artifacts for androidx.multidex:multidex:2.0.0

I try to migrate a project to AndroidX.
After 3 minutes of migrating it finished with error:
Gradle import
errorsC:\Users\user\AndroidStudioProjects\project\app\build.gradleproject
':app': Unable to build Kotlin project configurationDetails:
org.gradle.api.artifacts.ResolveException: Could not resolve all
dependencies for configuration
':app:implementationDependenciesMetadata'.Caused by:
org.gradle.internal.resolve.ArtifactResolveException: Could not
determine artifacts for androidx.room:room-runtime:2.0.0Caused
by: org.gradle.api.resources.ResourceException: Could not get resource
'https://dl.google.com/dl/android/maven2/androidx/room/room-runtime/2.0.0/room-runtime-2.0.0.aar'.Caused
by: org.gradle.internal.resource.transport.http.HttpRequestException:
Could not HEAD
'https://dl.google.com/dl/android/maven2/androidx/room/room-runtime/2.0.0/room-runtime-2.0.0.aar'.Caused
by: javax.net.ssl.SSLHandshakeException: Remote host closed connection
during handshakeCaused by: java.io.EOFException: SSL peer shut
down incorrectly
FAILURE: Build failed with an exception.
What went wrong:
Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
Could not determine
artifacts for androidx.multidex:multidex:2.0.0
Could not get resource 'https://dl.google.com/dl/android/maven2/androidx/multidex/multidex/2.0.0/multidex-2.0.0.aar'.
Could not HEAD 'https://dl.google.com/dl/android/maven2/androidx/multidex/multidex/2.0.0/multidex-2.0.0.aar'.
Remote host closed connection during handshake SSL peer shut down incorrectly
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
How to solve a problem with multidex and Maven?
build.gradle (project):
buildscript {
ext.compile_sdk_version = 29
ext.min_sdk_version = 16
ext.target_sdk_version = 29
ext.kotlin_version = '1.3.40'
ext.supportLibraryVersion = "28.0.0"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Firebase.
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (app):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
signingConfigs {
...
}
compileSdkVersion compile_sdk_version
defaultConfig {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
applicationIdSuffix '.debug'
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
multiDexEnabled true
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// Adds the "release" signing configuration to the release build type.
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.0'
}
UPDATE
I updated all libraries in dependencies. Then in project's build.gradle I added
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
to repositories in both branches. After compilation I got:
What went wrong: Could not determine the dependencies of task ':app:kaptDebugKotlin'.
Could not resolve all task dependencies for configuration ':app:kapt'.
Could not resolve androidx.room:room-compiler:2.1.0.
Required by:
project :app
Could not resolve androidx.room:room-compiler:2.1.0.
Could not get resource 'https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Could not GET 'https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Remote host closed connection during handshake
Could not resolve androidx.room:room-compiler:2.1.0.
Could not get resource 'https://maven.google.com/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Could not GET 'https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/2.1.0/room-compiler-2.1.0.pom'.
Remote host closed connection during handshake
I added in build.gradle (project) these lines:
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
So, it looks like:
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.40"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Then synced gradle file. It downloaded some libraries from Maven. After compiling I got another error. Then I pressed Sync Project with Gradle files again.
See also https://developer.android.com/jetpack/androidx/migrate to understand what library and styles becomes what in AndroidX.
Strange, but after compiling and removing
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
back from build.gradle, the application run again.

Gradle cannot find method android() for arguments (Gradle 2.2.3)

Gradle for my project isn't working. I've checked other questions that have had the same problem, but this one is in a newer version and I'm not sure how to solve it. I'm trying to get the Android SDK up and running for the first time, so I'm really new to this. Thorough answers are appreciated.
Here is my Gradle error:
Error:(22, 0) Could not find method android() for arguments [build_3bh8pl96cp64yo421v01fuk9s$_run_closure3#4b7fff2f] on root project 'Meet-upProject' of type org.gradle.api.Project.
And here is my build.gradle in root:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}

Gradle error: Could not find org.apache.httpcomponents:httpclient-android:4.3.5.1

I'm trying do use the Apache httpclient for Android in my Gradle project and I don't understand why I get this error when running ./gradle build:
Could not find org.apache.httpcomponents:httpclient-android:4.3.5.1.
My top-level build.gradle contains:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
My project build.gradle starts with:
apply plugin: 'com.android.application'
dependencies {
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':workspace:google_play_services:libproject:google-play-services_lib')
}
What's wrong with that?
In The Central Repository Browser of Maven the package I need is listed:
http://search.maven.org/#browse|-305040853
You have to add in your project build.gradle
repositories {
mavenCentral()
}
If you would like to put it in the top level file you can add this in the top level build.gradle:
allprojects {
repositories {
mavenCentral()
}
}

Problen add dependency android studio

I posted my library in Artifactory
https://imagizer.imageshack.us/v2/806x253q90/631/kkK1Yn.png
this is my Gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle',
version: '3.0.1')
}
}
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven {
url 'http://myartifactory:8081/artifactory/gradle-local'
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'com.android.library'
apply plugin: 'android-apt'
def AAVersion = '3.2'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
}
}
dependencies {
compile fileTree(include: ['*.jar', '*.so'], dir: 'libs')
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:support-v4:21.0.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'it.sephiroth.android.exif:library:+'
compile 'com.joanzapata.android:android-iconify:1.0.8'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.afollestad:material-dialogs:0.6.0'
compile 'com.github.lzyzsd:circleprogress:1.0.1#aar'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile(group: 'com.mylibrary.android.common', name: 'android.common', version: '1.0.0', ext: 'aar')
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.mypackage.library'
}
}
I get this error
https://imagizer.imageshack.us/v2/519x72q90/540/8ojerK.png
Gradle I found that running the route using the url wrong use "/" instead of "."
Try to find
...8081/artifactory/repo/com/mypackage/android/common/android.common/1.0.0/android.common-1.0.0.aar
but should be
...8081/artifactory/repo/com.mypackage.android.common/android.common/1.0.0/android.common-1.0.0.aar
I'm doing wrong, wrong as was published in the artefactory
Your artifact is not complaint to the standard Maven layout, in which the groupId should be separated by /, not by ..
It's not a big deal, Gradle can handle it easly, you just can't declare the repository as maven, but as ivy instead.
Actually, it will be easier to use the artifactory plugin for resolution, it also supports both Maven and Ivy layouts.
Also, please remember to set the repository in Artifactory to be with correct layout (not Maven2, probably Ivy).
And frankly, I think maybe it worth redeploying the artifact under Maven layout, it will make your life easier.

Resources