码迷,mamicode.com
首页 > 移动开发 > 详细

Android Studio官方推荐内网离线配置

时间:2019-10-24 00:27:38      阅读:858      评论:0      收藏:0      [点我收藏+]

标签:instead   mit   ini   fail   配置   hat   remove   date   版本问题   

TODO

参考:https://developer.android.com/studio/intro/studio-config
版本:Android Studio 3.5.1
官方离线组件版本:android-gradle-plugin-3.5.0-beta01@20191023, gmaven_stable@20191023

  • 按照本文下方复制的官方推荐方法配置好后,部分问题就解决了。
  • 接下来会遇到gradle版本问题。自行下载所需的gradle版本。解压到本地目录${GRADLE_ROOT}。打开设置File -> Settings -> Build, Execution, Deployment -> Gradle,选中Use local Gradle distribution,然后在下面填写${GRADLE_ROOT}。这样Android Studio就会使用你自己的Gradle版本。
  • 下面遇到的是版本问题。build过程中,遇到大量版本问题。

官方提供方法:
Turn on Offline Mode for Gradle: If you have limited bandwitch, turn on Offline Mode to prevent Gradle from attempting to download missing dependencies during your build. When Offline Mode is on, Gradle will issue a build failure if you are missing any dependencies, instead of attempting to download them. To turn on Offline Mode, do the following:

Click File > Settings (on macOS, Android Studio > Preferences) to open the Settings dialog.
In the left pane, expand Build, Execution, Deployment and then click Gradle.
Under Global Gradle settings, check the Offline work checkbox.
Click Apply or OK for your changes to take effect.

Configure offline build dependencies
If you‘d like to build your project without a network connection, follow the steps below to configure the IDE to use offline versions of the Android Gradle Plugin and Google Maven dependencies.

If you haven‘t already done so, download the offline components from the downloads page.

Download and unzip offline components
After you have downloaded the offline components, unzip their contents into the following directory, which you might need to create if it doesn’t already exist:

On Windows: %USER_HOME%/.android/manual-offline-m2/
On macOS and Linux: ~/.android/manual-offline-m2/
To update the offline components, proceed as follows:

Delete the content inside the manual-offline-m2/ directory.
Re-download the offline components.
Unzip the contents of the ZIP files you downloaded into the manual-offline-m2/ directory.
Include offline components in your Gradle project
To tell the Android build system to use the offline components you‘ve downloaded and unzipped, you need to create a script, as described below. Keep in mind, you need to create and save this script only once, even after updating your offline components.

Create an empty text file with the following path and file name:
On Windows: %USER_HOME%/.gradle/init.d/offline.gradle
On macOS and Linux: ~/.gradle/init.d/offline.gradle
Open the text file and include the following script:

def reposDir = new File(System.properties[‘user.home‘], ".android/manual-offline-m2")
def repos = new ArrayList()
reposDir.eachDir {repos.add(it) }
repos.sort()

allprojects {
buildscript {
repositories {
for (repo in repos) {
maven {
name = "injected_offline_${repo.name}"
url = repo.toURI().toURL()
}
}
}
}
repositories {
for (repo in repos) {
maven {
name = "injected_offline_${repo.name}"
url = repo.toURI().toURL()
}
}
}
}

Save the text file.

(Optional) If you’d like to verify that the offline components are working as intended, remove the online repositories from your project’s build.gradle files, as shown below. After you‘ve confirmed that your project builds correctly without these repositories, you can put them back into your build.gradle files.

buildscript {
repositories {
// Hide these repositories to test your build against
// the offline components. You can include them again after
// you‘ve confirmed that your project builds ‘offline’.
// google()
// jcenter()
}
...
}
allprojects {
repositories {
// google()
// jcenter()
}
...
}

Android Studio官方推荐内网离线配置

标签:instead   mit   ini   fail   配置   hat   remove   date   版本问题   

原文地址:https://www.cnblogs.com/zhaocnblogs01/p/11729499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!