使 Android Studio 便携(2017+ 版本) [英] Making Android Studio Portable (2017+ versions)

查看:51
本文介绍了使 Android Studio 便携(2017+ 版本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我至少有一台 PC 和一台笔记本电脑可以使用,并且倾向于在 6 个月左右重新安装它们.

I have at least a PC and a laptop to work on and have a tendency to reinstall them around 6 months.

因此我尽量制作可移植版本的开发工具,以便在重新安装后(随意或系统故障后)我可以轻松地继续我的工作.

Thus I try to make portable versions of development tools as much possible, so I can easily continue my works after reinstalls ( at will or after system failures).

我现在打算使用 Android Studio 学习/开发 Android 应用程序,并想要一种方法使其可移植.

I now intend to learn/develop Android application with Android Studio and want a way to make it portable.

我在网上搜索,大多数文章都不清楚要做什么以及为什么要这样做,或者我只是在信息的海洋中错过了好的.

I searched the net and most of articles are not clear on what to do and why to do so, or I just miss good ones in a sea of information.

如何不用复杂的软件/免费软件修改,通过简单的环境变量和少量的文件修改来制作Android Studio?

How can I make Android Studio without complex software/freeware modification and through simple environment variables and few file modification?

PS:这是一个自我回答的问题,但仅适用于 Windows.您可以通过改进或扩展 Linux/Mac 做出贡献.

PS: This is a self-answered question, but only does so for Windows. You may contribute by improving or extending for Linux/Mac.

推荐答案

这里使用的环境变量适用于 Windows 版本,但它们应该相同/适用于 Linux/Mac 以及适当的路径更改.

Environment variables used here are for Windows version, but they should be same/applicable to Linux/Mac as well with suitable path changes.

我至少有一台 PC 和一台笔记本电脑可以使用,并且倾向于在大约 6 个月后重新安装它们.我尽量制作可移植版本的开发工具,以便在重新安装后(随意或系统故障后)可以轻松地继续我的工作

I have at least a PC and a laptop to work on and have a tendency to reinstall them around 6 months. I try to make portable versions of development tools as much possible, so I can easily continue my works after reinstalls ( at will or after system failures)

我致力于通过经过验证的 IntelliJ-IDEA 可移植性方法使 Android Studio 可移植.我通过简单的环境值和一些文件修改充分利用了工作.

I work on making Android Studio Portable, through the proved IntelliJ-IDEA method of portability. I made the most of the work with simple environmental values and a few file modification.

我对 v2.3.3、v4.1 和 v4.1.1 使用了相同的步骤,因此可以安全地假设它适用于所有当前可用的版本.

I used the same steps for v2.3.3, v4.1 and v4.1.1 so it is safe to assume it works for all currently available versions.

浏览到 Android Studio 下载档案.该页面欢迎用户使用 Android Studio 的条款和条件.点击我同意条款";按钮获取所有新、旧和开发版本的列表.

Browse to Android Studio download archives. The page welcomes users with a terms and conditions on using Android Studio. Click on "I Agree To The Terms" button to get a list of all new, old and development versions.

它们的大小从 500MB 到 1GB 不等.获取最新或您要使用的压缩版本.(Canary、Beta 和 RC 版本不适合长期使用)

Their sizes are ranging from 500MB up to 1GB. Grab zipped version of the latest or the one you want to use. (Canary, Beta and RC versions are not for long term use)

我自己使用虚拟的tools.vhdx"用于我的便携式工具的文件,因为它使复制更容易,因为在驱动器之间复制数十万个小文件需要很长时间.您可以在其他地方找到它来创建虚拟磁盘并将其安装到文件夹/驱动器.

I myself use a virtual "tools.vhdx" file for my portable tools as it makes copying easier as hundreds of thousands of small files takes tremendously long to copy between drives. You can find it somewhere else to create a virtual disk and mount it to a folder/drive.

我将我的虚拟驱动器安装在 T:\ 驱动器(T 代表工具)上,并将工具解压到 T:\Tools 文件夹中.其余步骤将包括此路径.

I have my virtual drive mounted on T:\ drive (T for tools) and have tools extracted into T:\Tools folder. Remaining steps will include this path.

将下载的文件解压到您首选的 Android Studio 便携文件夹.

Extract downloaded file to your preferred portable folder for Android Studio.

我使用 T:\Tools\Android\ 文件夹进行 android 开发.所以我把它解压到T:\Tools\Android\android-studio.

I use T:\Tools\Android\ folder for android development. So I extracted it into T:\Tools\Android\android-studio.

如果要使用多个版本,请重命名此文件夹以反映工作室版本.例如,我将 T:\Tools\Android\android-studio.4.1.1 重命名为 4.1.1 版本.为简单起见,我将在本文的其余部分使用上述路径,您需要根据自己的路径进行相应更改.

If you want to use many versions rename this folder to reflect the studio version. for example, I renamed T:\Tools\Android\android-studio.4.1.1 for 4.1.1 version. I will use the above path for simplicity for the rest of this post, and you need to change this accordingly to your paths.

Android Studio 基于 IntelliJ IDEA 产品系列.他们使用 productname.properties 来实现便携性,即.idea.properties 用于 IDEA,位于 productfolder/bin 子文件夹下.但是默认情况下它们的可移植性部分被注释掉了,所以我们需要手动触摸它们.

Android Studio is based on IntelliJ IDEA product family. They use a productname.properties for portability, ie. idea.properties for IDEA, found under productfolder/bin subfolder. However their portability portions are commented out by default, so we need manual touch on them.

T:\Tools\Android\android-studio\bin\idea.properties 复制到 T:\Tools\Android\studio.properties.

现在打开它进行编辑.如果您是该领域的新手,请使用您使用的任何编辑器或按照此操作:

Now open it for editing. Use any editor you use or follow this if you are new into this field:

  • 在 Windows 上,在文件资源管理器中打开 T:\Tools\Android\,按 shift 并右键单击,在此处打开终端"应该在那里,选择它打开命令控制台,输入 notepad studio.properties
  • Linux/Mac 用户应该更熟悉编辑工具和控制台,因此我相信您会找到自己的方法.
  • On windows, open T:\Tools\Android\ in file explorer, press shift and right click, "open terminal here" should be there, select it to open command console, type notepad studio.properties
  • Linux/Mac users should be more familiar with editing tools and console thus I believe you will find your way.

现在找到并编辑这些行.# 表示这些行被注释掉,如果不取消注释就不会使用.默认情况下,即使您取消注释它们,它们也会将配置安装到用户的主目录中,这会破坏可移植性,因此请注意不要运行 Studio.

Now find and edit these lines. # means these lines are commented out, and are not used if you don't uncomment them. By default, even if you uncomment them, they will install configurations into User's Home directory, which breaks portability thus be careful not to run Studio yet.

# idea.config.path=${user.home}/.AndroidStudio/config
idea.config.path=${idea.home.path}/../.AndroidStudio/config

# idea.system.path=${user.home}/.AndroidStudio/system
idea.system.path=${idea.home.path}/../.AndroidStudio/system

# idea.plugins.path=${idea.config.path}/plugins
idea.plugins.path=${idea.config.path}/plugins

# idea.log.path=${idea.system.path}/log
 idea.log.path=${idea.system.path}/log

这里 idea.home.path 在 Android Studio 运行时设置为 T:\Tools\Android\android-studio\.所以基本上 ${idea.home.path}/../.AndroidStudio 将我们的配置文件设置为 T:\Tools\Android\.AndroidStudio.

Here idea.home.path is set to T:\Tools\Android\android-studio\ when Android Studio runs. So basically ${idea.home.path}/../.AndroidStudio sets our configuration files into T:\Tools\Android\.AndroidStudio.

如果没有这些修改(如果您之前有其他版本),默认情况下会使用这 3 个文件夹来存储相关文件.如果您想清除以前不可移植的用途,这也很有用.

Without these modifications (and if you had other versions before) these 3 folders are used by default to store related files. This is also useful if you want to clear previously non-portable uses.

  • %USER%\.AndroidStudiox.x
  • %USER%\AppData\Roaming\Google\.AndroidStudiox.x
  • %USER%\AppData\Local\Google\.AndroidStudiox.x

现在完成我们的移植,在T:\Tools\Android\下创建一个批处理文件start-studio.bat,复制这两行,并保存,然后双击它运行 Android Studio.

Now to finish our portability, create a batch file start-studio.bat under T:\Tools\Android\, copy these two lines, and save it, then double click on it to run Android Studio.

set STUDIO_PROPERTIES=t:\Tools\Android\studio.properties
start t:\Tools\Android\android-studio\bin\studio64.exe

您也可以将此属性设置为用户/系统环境变量,或在打开的控制台中主动使用.

You can also set this property into user/system environment variables, or use actively in an open console.

双击start-studio.bat 运行Android Studio.它现在应该创建 .AndroidStudio/config.AndroidStudio/system.如果没有,那么你做错了什么.您可以安全地移除这些文件夹并重新开始.

Double click on start-studio.bat to run Android Studio. It should now create .AndroidStudio/config and .AndroidStudio/system. If not then you did something wrong. You can safely remove these folders and start over.

使 Android Studio 具有可移植性并不足以使 Android 开发具有可移植性.尽管您可以将它们放在各自的文件夹中,但通过 Studio 保留 Gradle 和 Android SDK 文件/设置可为 Android 开发提供更好的灵活性.

Making Android Studio portable is not alone enough to make Android development portable. Though you can have them in their respective folders, keeping Gradle and Android SDK files/settings with Studio gives a better flexibility on Android development.

在批处理文件中添加这两行代码将使您的 Android SDK 和设置文件夹可通过 Studio 移植.每对夫妇都有旧版本和新版本的环境变量.这些文件夹将在首次使用时创建,因此您无需手动创建.

Adding these two couple of lines in your batch file will set your Android SDK and settings folders portable with Studio. Each couple has the environment variable for older and newer version. These folders will be created on first use, so you don't need them created manually.

set ANDROID_SDK_ROOT=t:\Tools\Android\sdk\
set ANDROID_HOME=t:\Tools\Android\sdk\

set ANDROID_SDK_HOME=t:\Tools\Android\.android
set ANDROID_PREFS_ROOT=t:\Tools\Android\.android

SDK 文件将在首次运行时下载.您稍后还需要下载虚拟设备.对于每个 SDK 版本,这些可能有很多 GB.

SDK files will be downloaded at first run. You will also need to download virtual devices later. These can be many GBs for each SDK version.

设置 Gradle 可能会很痛苦.最好将 Android Studio 使用的版本放在我们用于 Android 开发的同一文件夹中,以确保我们始终拥有正确的版本.首次使用时也会创建此文件夹,并下载 Gradle 版本(最初下载约 100MB)

Setting Gradle can be a pain. It is best to have the versions used by Android Studio in the same folder we use for Android development to ensure we always have the right one. This folder will also be created on first use, and a Gradle version will be downloaded (about 100MB downloaded at first)

set GRADLE_USER_HOME=t:\Tools\Android\.gradle

已知问题

目前我不知道任何可移植性中断路径设置,因为这些设置似乎足够了.如果我错过了什么,我相信我们会立即将它们揭露出来.

Known Problems

Currently I am not aware of any portability breaking path setting as these setting seems enough. If I missed something I am sure we will have them revealed in no time.

除此之外,安装插件也有问题.我测试了 2.3.3 之前的版本,并假设所有 Android Studio 版本都有这个问题:

Besides this, there is a problem installing plugins. I tested versions as old as 2.3.3 and assume all Android Studio versions have this problem:

  • 重新启动后不会安装插件,至少是那些需要重新启动的插件.

我在此链接中打开了错误报告.IDEA版本没​​有这个问题.

I opened a bug report in this link. IDEA versions does not have this problem.

目前的解决方案是手动处理该过程:浏览到 t:\Tools\Android\.AndroidStudio\system\plugins\ 文件夹,选择插件的 zip 文件,将它们解压缩到 >t:\Tools\Android\.AndroidStudio\config\plugins\.

A solution for now is to handle the process manually: browse into t:\Tools\Android\.AndroidStudio\system\plugins\ folder, select zip files of plugins, extract them into t:\Tools\Android\.AndroidStudio\config\plugins\.

这篇关于使 Android Studio 便携(2017+ 版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆