Recently I upgraded my Cordova project from Cordova 3.0 to 5.3.3 and Android platform from 3.6 to 4.1. New android platform uses gradle for build and need to connect to internet (maven repo) every day for building. Once it connects to repo, it does not require connection for that day.
I am working behind the proxy which does not have access to maven repo. I am new to gradle build and want to configure gradle for offline building cordova application.
Here are environment details
OS -> MAC OSX
Cordova version -> 5.3.3
Cordova Android platform version -> 4.1
Kindly suggest.
Dependencies are declared in Gradle in the dependencies section and the repositories section controls where the dependencies are fetched from. For example:
repositories {
jcenter()
}
dependencies {
compile 'com.google.guava:guava:18.0'
}
This says, guava:18.0 is fetched during compile time, from the jcenter() repository. You can also use maven central as:
repositories {
mavenCentral()
}
A custom repo like a company repo as:
repositories {
maven {
url "http://repo.mycompany.com/maven2"
}
}
or, the local .m2 repo as:
repositories {
mavenLocal()
}
You can define multiple repositories as well:
repositories {
mavenLocal()
jcenter()
}
Gradle searches for dependencies in the order that the repositories are listed. So it will look in local .m2 first, and if a matching dependency isn't available, it goes out to JCenter to download dependencies.
Related
I'm aware that this error can be caused by using old versions of Gradle and the Android Gradle plugin, but in this case this build error only occurs on the remote cloud-based CI server (Nevercode) and not locally (either in Android Studio, or command line). The project is using recent versions of both. This appears to be a different cause to that mentioned in other questions about this error.
gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
root build.gradle:
buildscript {
repositories {
jcenter()
google() // <-- Error points to (line 7) here
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
jcenter()
google()
flatDir {
dirs 'libs'
}
}
}
Build error:
Could not find method google() for arguments [] on repository container.
/build.gradle' line: 7
Gradle cannot find the definition of google() but this should work with Gradle 4.0+ and Android Gradle plugin v3.0+ according to this Error:(6, 0) Gradle DSL method not found: 'google()'
Switching google() to maven { url 'https://maven.google.com' } does not fix the issue.
I have other projects that build just fine with this CI provider, using what appear to be the same configurations. The project with the issue is being built by the CI server in a fresh virtual machine, from the repository source, so I would not expect any cached state issues to cause this. It is intriguing that it builds ok locally every time, just not on the CI server.
The cause of this was that in the "app" module of the project (one level below the project root) there was a second copy of gradle and the gradle wrapper, and the gradle wrapper was configured to an old v2.2.
Locally this is not a problem, but for whatever reason Nevercode CI uses that Gradle v2.2 from the app module for builds, and then fails as the version is way too old.
If you see this scenario, check your sub-modules for stray copies of older versions of Gradle...
In Gradle project, we can define multiple remote / local Maven repository.
buildscript {
repositories {
mavenLocal()
mavenCentral()
jCenter()
maven {
url 'https://example1.mavenrepo.com/public'
}
maven {
url "https://example2.mavenrepo.com/release"
}
}
dependencies {
classpath 'com.example.mydependencies:mylibrary:1.0.0'
}
}
If mylibrary exist in all of Maven repo. Which one will Gradle choose? Can I configure Gradle to only download mylibrary in certain Maven repo?
As you can find in the doc
A project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module.
I don't think there is a way to point to the gradlew to use particular repository or order it. Gradlew by design uses a single repository for all dependencies. If any of them fail, the build fails.
[Refer]: https://github.com/gradle/gradle/issues/7965
I'm trying to use Travis CI for my Android Project but my Builds constantly failing but works on local build. I am using Android Studio Preview 3 and gradle 3 alpha 3.
I am getting this error below.
Could not find com.android.tools.build:gradle:3.0.0-alpha3.
Here is my build log
My Travis Config file
My Project gradle file
I'm getting an Access denied error to your build log, and I didn't use it, but I'll try to answer you.
As announced here:
The Android Gradle Plugin 3.0.0-alpha3 was also released through
maven.google.com.
You can try to fix it by adding Google’s Maven Repository here like this:
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Make sure that the repositories section includes a maven section with
the "https://maven.google.com" endpoint. For example:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
As commented here, this version doesn't exist in Bintray JCenter:
com.android.tools.build.gradle
latest version is 2.5.0-alpha-preview-02, there is no 3.0.0-alpha3
Also be sure to update build tools to the latest version as suggested in this related question:
Update your build tools from SDK manager
I add links to samples using the new sdkmanager command line here.
I would need a sample project reproducing the issue to check my suggestions.
When opening Android Studio I get the following error messages under messages Gradle Sync:
Please help. I need it for my work.
Add this to your project level build.gradle:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
as described here: cannot install repository and sync project - not able to use support libraries 25.2.0
I just forked fresh mapbox library and tried to add it to my project as a module. Main problem is that gradle gives error when it's synchronising, because I can't access telemetry 2.0.0-SNAPSHOT
Error:Could not find com.mapbox.mapboxsdk:mapbox-android-telemetry:2.0.0-SNAPSHOT.
Required by:
MyApp:app:unspecified > com.mapbox.mapboxsdk:MapboxGLAndroidSDK:5.0.0-SNAPSHOT
Search in build.gradle files
How can I add telemetry services to my project?
Or it's impossible and I should be patient and just check for latest public Mapbox release in git history (currently it's 4.2.2 on Android), checkout and use that version and wait for a new public release?
Finally I found out that top level gradle file was missing snapshot sonatype repository.
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
}