Accessing Dependency from Artifactory using Gradle - android

I have an artifact that has been published to my local Artifactory repository and now I am trying to pull that artifact into a project with gradle.
However, I keep getting the following error:
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.company.app:myapplication:1.0.0.
Searched in the following locations:
https://jcenter.bintray.com/com/company/app/...pom
https://jcenter.bintray.com/com/company/app/...jar
file:/Users/user/Library/Android/sdk/extras/android/m2repository/com/company/app...pom
file:/Users/user/Library/Android/sdk/extras/android/m2repository/com/company/app...jar
file:/Users/user/Library/Android/sdk/extras/google/m2repository/com/company/app...pom
file:/Users/user/Library/Android/sdk/extras/google/m2repository/com/company/app....jar
This error suggests that it's not even looking at the local artifactory repository. Below are my build.gradle files
Project Level build.gradle
buildscript {
repositories {
jcenter()
maven {
url '${artifactory_contextUrl}/libs-release-local'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.0"
}
}
allprojects {
repositories {
jcenter()
}
}
App Level build.gradle
allprojects{
apply plugin: "com.jfrog.artifactory"
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.company.app:myapplication:1.0.0'
}

The issue was
The maven url needs to be outside of the buildscript
The maven url needs to be in the App level, not Project level build.gradle
Below are my current build.gradle files that work:
Project Level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
App Level build.gradle
repositories {
maven {
url '${artifactory_contextUrl}/libs-release-local'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.company.app:myapplication:1.0.0'
}
NOTE: I removed the jfrog plugin because it's only needed if you are publishing to Artifactory.

Related

Unable to run tests after migrating to junit5

I'm running tests on android using gradle and we're migrating our framework to junit5 to take advantage of some of it's tagging and filtering capabilities. I've created the dependencies in my build.gradle files and I'm able to get it to build and run using the gutter icon in android studio, but I'm unable to run my tests from the command line. I get the following error.
* What went wrong:
Execution failed for task ':app:compileTestKotlin'.
> Could not resolve all files for configuration ':app:testCompileClasspath'.
> Could not find junit:junit:5.7.0.
Searched in the following locations:
- https://jcenter.bintray.com/junit/junit/5.7.0/junit-5.7.0.pom
- https://jcenter.bintray.com/junit/junit/5.7.0/junit-5.7.0.jar
- https://repo.maven.apache.org/maven2/junit/junit/5.7.0/junit-5.7.0.pom
- https://repo.maven.apache.org/maven2/junit/junit/5.7.0/junit-5.7.0.jar
Required by:
project :app
Here's my build.gradle at the app level
plugins {
id 'io.qameta.allure' version '2.8.1' // Latest Plugin Version
id 'java'
}
allure {
autoconfigure = true
version = '2.13.7' // Latest Allure Version
useJUnit5 {
version = '2.13.7' // Latest Allure Version
}
}
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
dependencies {
testImplementation(
'org.junit.jupiter:junit-jupiter-params:5.7.0',
'org.junit.jupiter:junit-jupiter-api:5.7.0'
)
testRuntimeOnly(
'org.junit.jupiter:junit-jupiter-engine:5.7.0'
)
}
test {
useJUnitPlatform(){
includeEngines 'junit-jupiter'
}
}
apply plugin: 'kotlin'
test {
systemProperty 'platform', project.findProperty('platform')
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1'
implementation "io.appium:java-client:7.2.0"
// implementation 'junit:junit:4.12'
implementation 'junit:junit:5.7.0'
}
and here's the build.gradle at the project level.
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The error message says it. implementation 'junit:junit:5.7.0' is a non-existing dependency. Leave it away and it might already work.

Cross module dependencies with Gradle and mavenLocal

My project is an old android application (module-front) with modules (module-shared) that used to be published on maven.
I have an access to source code of the module and I want to store my module in my mavenLocal.
My directory structure :
/project
/module-front
build.gradle
/module-shared
build.gradle
build.gradle
My module-front gradle file has a dependency on the published (but removed) module-shared :
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
// Android properties here
}
dependencies {
ext {/* Versions here */}
compile group: 'module-shared group', name: 'module-shared name', version: moduleSharedVersion
// compile and testCompile here
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
apt {
// apt here
}
ModuleSharedVersion is defined in my root gradle file :
buildscript {
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
ext {
moduleSharedVersion= '2.1'
}
version = '1.4.8h'
group = 'myGroup'
}
Problem starts here:
Now I want my module-shared to be stored in mavenLocal so my module-front might access it :
apply plugin: 'application'
apply plugin: 'maven'
version = '2.1'
uploadArchives {
repositories {
mavenInstaller {
repository(url: mavenLocal().url)
pom.groupId = 'module-shared group'
pom.artifactId = 'module-shared name'
pom.version = version
}
}
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
This is my attempt to store it in mavenLocal inspired from multiple posts (example) which doesn't work...
I don't know much about gradle, not enough to fix it tbh.
Please tell me if you need any other file that might be important to understand/answer.
Thanks :)

Could not find com.google.firebase:firebase-database: 15.0.0

I'm developing an app using React-Native and I'm trying to connect it to my Firebase database. When I try to run my code (i.e., react-native run-android), I get the following:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
> Could not find com.google.firebase:firebase-database: 15.0.0.
I've looked at the solutions proposed in Could not find com.google.firebase:firebase-database:9.2.0 and react native Could not find com.google.firebase, but neither have worked for me so far...
Here is my top level build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
}
}
Here is part of my app level build.gradle file:
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.firebase:firebase-core:15.0.2"
compile "com.google.firebase:firebase-database: 15.0.0"
compile "com.google.android.gms:play-services-base:15.0.0"
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
How can I fix this issue? Thanks.
You need to update your gradle and android build plugin the add the google() repo to your project build.gradle.
Update your gradle version to at least version 4.4 by changing your gradle-wrapper.properties in gradle folder to:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Update build plugin and add google() repo to your build.gradle so that your project build.gradle will become like this:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// update to version 3.1.3
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
// the following is the same as google()
//maven { url "https://maven.google.com" }
google()
maven { url "https://jitpack.io" }
}
}
Add google() in this block:
allprojects {
repositories {
google() // add this
// others here...
}
}
It's the repo required for all Android, Firebase, and Play services dependencies. You should add it here too:
buildscript {
repositories {
google()
jcenter()
}
}
Read more about it here.

Appdynamics implementation

I'm trying to add Appdynamics into my application, I'm doing those steps: https://docs.appdynamics.com/display/PRO40/Instrument+an+Android+Application#InstrumentanAndroidApplication-ToaddtheAppDynamicsAndroidagentrepositorytoyourproject but after all I have error:
Error:(15, 13) Failed to resolve: com.appdynamics:appdynamics-runtime:1.0
This is how my build.gradle (for all project) looks like:
buildscript {
configurations.classpath.resolutionStrategy.force('com.android.tools.build:gradle:1.2.3')
repositories {
maven { url uri("adeum-maven-repo") }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3', 'com.appdynamics:appdynamics-gradle-plugin:2.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
and build.gradle (from app module):
apply plugin: 'adeum'
repositories {
flatDir {
dirs 'lib'
}
maven {
url uri('adeum-maven-repo')
}
}
dependencies {
compile 'com.appdynamics:appdynamics-runtime:1.0'
and adeum-maven-repo paste into project. Any idea what am I doing wrong?
That error means that gradle is unable to resolve the dependency on com.appdynamics:appdynamics-runtime. The easiest way to fix this problem is to use the AppDynamics libraries from maven central rather than the adeum-maven-repo directory. You can do that by editing your top level gradle file to look like this:
buildscript {
configurations.classpath.resolutionStrategy.force('com.android.tools.build:gradle:1.2.3')
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.appdynamics:appdynamics-gradle-plugin:4.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Then your project-level gradle file would look like:
apply plugin: 'adeum'
repositories {
flatDir {
dirs 'lib'
}
}
dependencies {
compile 'com.appdynamics:appdynamics-runtime:4.+'
}
Note that I have removed the references to adeum-maven-repo, and changed the version numbers on the AppDynamics artifacts to refer to them as they exist in maven central. Once you've done this, you no longer need adeum-maven-repo in your project, since gradle is now downloading these dependencies automatically.

Understanding Gradle build scripts

I'm new in Gradle so maybe this is a silly question. I'm trying to add my Maven repository to download dependencies from Gradle, but I'm a little confused.
Project module is the root one and app module is the only subproject.
build.gradle (Project)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
credentials {
username 'xxxxxx'
password 'xxxxxx'
}
}
}
}
build.gradle (App module)
buildscript {
repositories {
mavenCentral()
maven {
url 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
credentials {
username 'xxxxx'
password 'xxxxx'
}
}
}
dependencies {
//more dependencies from mavenCentral()
classpath 'my.group.id:my-artifact:1.0.0' //<--- this dependency is from my repository
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//more dependencies
compile 'my.group.id:my-artifact:1.0.0' //<--- this dependency is from my repository
}
Have I to put my repository's configuration in both files? Why? I mean, I have already put it in allprojects in project's build.gradle. How can I reference my repository in app module's build.project without put its configuration again?
Can I put this information in ~/.gradle/gradle.properties file?
I want to understand how configure it correctly.
Thanks.
your App is your root project? Is that what you mean? then the project is the subprojects? If that's the case you can put everything in allprojects configuration and you can put the your credentials in the gradle.properties and flop the property names here for user and password.
allprojects {
repositories {
mavenCentral()
maven {
url 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
credentials {
username 'xxxxx'
password 'xxxxx'
}
}
}
}
Hope this helps.

Categories

Resources