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.
Related
I need to import import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions; in my app code, for that I need to implement com.mapbox.maps:android:10.2.0 in build.gradle module, but it fails.
Could someone tell me, why this gradle implement fails to resolve?
implementation ('com.mapbox.maps:android:10.2.0'){
exclude group: 'group_name', module: 'module_name'
}
This is the error msg:
Failed to resolve: com.mapbox.maps:android:10.2.0
In stack trace it says: NotFound com.mapbox.maps:android:10.2.0
Show in Project Structure dialog
Affected Modules: app
build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication{
basic(BasicAuthentication)
}
credentials{
username='mapbox'
password= project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?:""
}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ERROR INFORMATION
After a a few hours of research I came to find out how to properly set up Mapbox (10.0.2) on Android
IMO, this first bullet should solve the issue, otherwise keep going.
First, in settings.gradle -> as stated previously set mode to PREFERS.SETTINGS .
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = MAPBOX_DOWNLOADS_TOKEN
}
}
}
}
Second, add the dependency as per usual to module-level build.gradle (not project level)
implementation 'com.mapbox.maps:android:10.2.0'
Third, this is what my project-level build.gradle looks like.
buildscript {
ext {
compose_version = '1.2.0-alpha02'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Last, in your gradle.property make sure you have
(GOOD) MAPBOX_DOWNLOADS_TOKEN = SECRET_ACCESS_CODE
(DO NOT) MAPBOX_DOWNLOADS_TOKEN = "SECRET_ACCESS_CODE"
I face this problem when trying to use mapbox in Android studio
Failed to resolve: com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0
what is the problem?
my build.gradle dependencies
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0'
}
my build.gradle project
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://mapbox.bintray.com/mapbox' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
it's just badly explained. you have to make a private token. public token does not work. when you create a token there is a field with "Read:Download" just mark it and generate your token. This token should work.
Version 9.5.0 (and 9.6.0) also exists (See release notes here: https://github.com/mapbox/mapbox-gl-native-android/blob/main/CHANGELOG.md). It is just that the way to access the Maven repository has changed with Mapbox Maps SDK > v9.4.0.
I would discourage you from using an outdated version like mapbox-android-sdk:8.6.7, but go for com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.0.
The new way to access the mave repo is documented here:
https://docs.mapbox.com/android/maps/overview/#configure-credentials
You now need to create a secret access token and use it to access the maven repo, where the libraries are located. Your module level build.gradle should contain this:
allprojects {
repositories {
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = 'mapbox'
// Use the secret token you stored in gradle.properties as the password
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
}
Just use this safe version and it will work on your gradle.
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.0'){
exclude group: 'group_name', module: 'module_name'
}
Found Solution by generating private key as pointed out in previous answers, and finding an actual version on maven central, neither 9.7 nor 10 was on the maven central repository at the time of writing, using version 9.2 found here
https://mvnrepository.com/artifact/com.mapbox.mapboxsdk/mapbox-android-sdk
Edit: Was able to use 9.7.0 mapbox by changing settings.gradle entry
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
to
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
and build.gradle to add mavenCentral() and google() to allprojects repositories
allprojects {
repositories {
google()
mavenCentral()
allprojects {
repositories {
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = 'mapbox'
// Use the secret token you stored in gradle.properties as the password
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
}
}
}
The only way got my project to finally work is by looking for some pointers in the project attached here:
https://github.com/mapbox/mapbox-maps-android/issues/614#issue-988592394
It uses com.mapbox.maps:android:10.0.0-rc.3 and actually works on my machine.
To make my own project work, I had to change settings.gradle from this:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "Mapbox Map"
include ':app'
to this:
rootProject.name = "Mapbox Map"
include ':app'
The default token Mapbox provides you is what I think you're using, you need to create a new private token and check this permission DOWNLOAD:READ then it should work.
I created a new token and named it first in my case, you can call it anything.
You should remove this line : maven{ url 'https://mapbox.bintray.com/mapbox' }
repositories {
google()
jcenter()
mavenCentral()
/**
if you using => maven { url 'https://mapbox.bintray.com/mapbox' }
so remove this line because mapbox remove repository from https://mapbox.bintray.com/mapbox
* */
maven { url "https://oss.sonatype.org/content/groups/public/" }
maven { url 'https://jitpack.io' }
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = 'mapbox'
// Use the secret token you stored in gradle.properties as the password
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
How about trying a version, which actually exists?
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.7'
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 :)
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.
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.