I'm using gradle 5.6.2. Actually, this is a flutter project and I build it using:
flutter build apk
My project has 2 build.gradle files:
android/
---- build.gragle
---- app/
---- build.gradle
I deleted the google()
and jcenter()
reposistories from the parent build.gradle, and configured a nexus repository. My buiild.gradle looks like this:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
if (!hasProperty('NEXUS_CREDENTIALS_USR')) {
ext.NEXUS_CREDENTIALS_USR = ''
}
if (!hasProperty('NEXUS_CREDENTIALS_PSW')) {
ext.NEXUS_CREDENTIALS_PSW = ''
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-google-android"
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-public"
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-snapshots"
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-group"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
rootProject.buildDir = '../build'
allprojects {
repositories {
if (!hasProperty('NEXUS_CREDENTIALS_USR')) {
ext.NEXUS_CREDENTIALS_USR = ''
}
if (!hasProperty('NEXUS_CREDENTIALS_PSW')) {
ext.NEXUS_CREDENTIALS_PSW = ''
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-google-android"
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-public"
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-snapshots"
}
maven {
credentials {
username = "${NEXUS_CREDENTIALS_USR}"
password = "${NEXUS_CREDENTIALS_PSW}"
}
url "https://somenexusrepo.com/repository/maven-group"
}
}
}
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
But when I try to build the project, it still tries to get some dependencies from other repositories. I'm trying to build it from a private network and I can not access either dl.google.com or repo.maven.apache.org repositories, that's why I am getting this error:
A problem occurred evaluating project ':app'.
[ ] > Could not resolve all artifacts for configuration 'classpath'.
[ ] > Could not resolve com.android.tools.build:gradle:4.1.0.
[ ] Required by:
[ ] unspecified:unspecified:unspecified
[ ] > Could not resolve com.android.tools.build:gradle:4.1.0.
[ ] > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
[ ] > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
[ ] > Connect to dl.google.com:443 [dl.google.com, dl.google.com] failed: No route to host (connect failed)
[ ] > Could not resolve com.android.tools.build:gradle:4.1.0.
[ ] > Could not get resource 'https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
[ ] > Could not GET 'https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
[ ] > Connect to repo.maven.apache.org:443 [repo.maven.apache.org, repo.maven.apache.org] failed: connect timed out
Even if I try to execute gradle build
command, I get the same error.
Is there a way to avoid using these repositories?
CodePudding user response:
I replaced repositories in flutter.gradle ($FLUTTER_ROOT/packages/flutter_tools/gradle/flutter.gradle)
file and now flutter is looking for the packages in the custom repo.