Overwriting the repositories warehouse address in gradle in Flutter and Android

Cover the warehouse address of Android third-party library

problem scenario

Flutter uses a positioning permission librarylocation_permissions, the following error is reported when running.

* What went wrong:
A problem occurred configuring project ':location_permissions'.
> Could not resolve all artifacts for configuration ':location_permissions:classpath'.
   > Could not resolve org.ow2.asm:asm-util:6.0.
     Required by:
         project :location_permissions > com.android.tools.build:gradle:3.5.0
         project :location_permissions > com.android.tools.build:gradle:3.5.0 > com.android.tools.build:builder:3.5.0
         project :location_permissions > com.android.tools.build:gradle:3.5.0 > com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta04
      > Could not resolve org.ow2.asm:asm-util:6.0.
         > Could not get resource 'https://jcenter.bintray.com/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom'.
            > Could not HEAD 'https://jcenter.bintray.com/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':location_permissions' of type org.gradle.api.Project.
   > Could not get unknown property 'android' for project ':location_permissions' of type org.gradle.api.Project.

problem analysis

According to the error message, this library depends on other third-party libraries.jcenterRepository download failed.
But the default jcenter warehouse and maven warehouse have been replaced in android, why are they still downloaded from jcenter.

we openedGithub repository for location_permissions, open build.gradle in the android directory

You will understand when you see this. It turns out that the android configuration of the plug-in uses the jencter warehouse, so the dependencies related to the plug-in will be downloaded from jencter.

solution

Next we overwrite the repositories references in the third-party library.
Open settings.gradle.
Add the following

dependencyResolutionManagement {
  repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
  }
  repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
}

Open build.gradle in the project root directory

buildscript {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
    }
	......
}

allprojects {
    buildscript {
	    repositories {
            maven {
                url 'https://maven.aliyun.com/repository/public/'
            }
            maven {
                url 'https://maven.aliyun.com/repository/central/'
            }
            maven {
                url 'https://maven.aliyun.com/repository/google/'
            }
            maven {
                url 'https://maven.aliyun.com/repository/gradle-plugin/'
            }
	    }
	}
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
    }
}

Run it again, and the dependencies in the third-party library will be downloaded normally, and no download failure error will be reported.

Replace the repository of flutter sdk

problem scenario

Run it again and still find the following error

* Where:
Build file '/Users/ado/Developer/project/x_creator/android/app/build.gradle' line: 33

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all artifacts for configuration 'classpath'.
   > Could not resolve com.google.flatbuffers:flatbuffers-java:1.12.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve com.google.flatbuffers:flatbuffers-java:1.12.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/com/google/flatbuffers/flatbuffers-java/1.12.0/flatbuffers-java-1.12.0.pom'.
            > Could not HEAD 'https://repo.maven.apache.org/maven2/com/google/flatbuffers/flatbuffers-java/1.12.0/flatbuffers-java-1.12.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-metadata/0.1.0-rc1/tensorflow-lite-metadata-0.1.0-rc1.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-metadata/0.1.0-rc1/tensorflow-lite-metadata-0.1.0-rc1.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake

problem analysis

According to the error message, find app/build.gradle and find the following reference on line 33.
When the Android side runs or compiles, the gradle warehouse configuration in the flutter sdk will be called to download the corresponding dependencies.

Then we went to flutter.gradle in the corresponding directory of flutter sdk based on this address and found the following warehouse configuration. It just corresponds to the gradle version number 4.1.0 in the error message above.

solution

We only need to replace google and mavenCentral() with domestic warehouse images.

buildscript {
    repositories {
        //google()
        //mavenCentral()
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

reference:Cannot override Gradle repositories in transitive plugin dependencies

Related Posts

Android set background color transparency

Use ADB to batch install apk

Unity exports the Android project and creates a new activity to place the privacy agreement

Dialog of Getx series

IDEA background interacts with Android data

Teach you step by step how to make the navigation bar at the bottom of your mobile phone, and your boss will agree after reading it

Installing third-party firmware on x3-55 letv (by quqi99)

IDEA2021.2 installation and configuration (continuous updates)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*