Configuration of build. gradle warehouse in flutter of solves the problem of slow download speed and failure of external network

  • 2021-12-04 11:11:04
  • OfStack

Problem description

When developing flutter projects, we often meet that we are implementing flutter run Directive, the problem of slow download of resources occurs, which eventually leads to download failure, unable to build project, and throws the phenomenon of abnormal run termination. All these will become the first difficulty for beginners to get started in flutter development, and may also persuade you to enter the world of flutter. As the saying goes, "There must be a road when the car arrives at the front of the mountain, and it will be straight when the boat arrives at the bridge". If you don't experience wind and rain, you will see the rainbow!

Solutions

It can be solved by changing the warehouse address of build. gradle in flutter project. Of course, if you can climb over the wall, you don't have to worry about it. (I think if you can climb over the wall, then you will succeed in run, so you won't look up relevant questions again, hee hee hee)

Since we need to modify the file build. gradle, of course, we need to find it first. There are two build. gradle files in the flutter project, so we only need to modify build. gradle located in the root directory of android, and the path is as follows


android\build.gradle

Add the following two places in build. gradle:


//  No. 1 1 Location at 
	buildscript {
		repositories {
		 google()
		 jcenter() 
	 }
 }
 //  No. 1 2 Location at 
 allprojects {
	 repositories {
	  google()
	  jcenter()
  }
	}

Replace with something like this:


//  No. 1 1 Location at 
	buildscript {
		repositories {
		 maven { url 'https://maven.aliyun.com/repository/google' }
	  maven { url 'https://maven.aliyun.com/repository/jcenter' }
	  maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
	  maven { url 'https://maven.aliyun.com/repository/gradle-plugin'} 
	 }
 }
 //  No. 1 2 Location at 
 allprojects {
	 repositories {
	  maven { url 'https://maven.aliyun.com/repository/google' }
	  maven { url 'https://maven.aliyun.com/repository/jcenter' }
	  maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
	  maven { url 'https://maven.aliyun.com/repository/gradle-plugin'}
  }
	}

By doing so, you can avoid executing flutter run The problem of slow download and failure of resources. If it still fails, it is recommended to execute it several times more. Or execute it first flutter clean To clean up the previous build files

Summarize


Related articles: