使Android Studio可移植(2017+版本) [英] Making Android Studio Portable (2017+ versions)

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

问题描述

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

因此,我尝试使开发工具的可移植版本尽可能多,以便在重新安装后(随意或在系统出现故障之后)可以轻松地继续我的工作.

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

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

如何通过简单的环境变量和很少的文件修改而无需进行复杂的软件/免费软件修改就可以制作Android Studio?

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

解决方案

此处使用的环境变量适用于Windows版本,但它们应该相同/适用于Linux/Mac,并且具有适当的路径更改.

简介

我至少可以使用PC和笔记本电脑,并且倾向于在6个月左右重新安装它们.我尝试使开发工具的可移植版本尽可能多,以便在重新安装后(随意安装或在系统出现故障之后)可以轻松地继续我的工作.

我通过经过实践证明的IntelliJ-IDEA可移植性方法来开发Android Studio Portable.我通过简单的环境值和一些文件修改来充分利用了这项工作.

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

使Android Studio可移植

下载Android Studio存档(zip/tar.gz)版本

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

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

设置虚拟驱动器以获得最佳可移植性

我自己使用虚拟的"tools.vhdx"用于我的便携式工具的文件,因为它使复制变得容易,因为成千上万的小文件在驱动器之间进行复制要花费很长时间.您可以在其他地方找到它以创建虚拟磁盘并将其安装到文件夹/驱动器.

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

提取下载的文件

将下载的文件提取到您首选的Android Studio便携式文件夹中.

我将 T:\ Tools \ Android \ 文件夹用于android开发.所以我将其提取到 T:\ Tools \ Android \ android-studio .

如果要使用多个版本,请重命名此文件夹以反映Studio版本.例如,我将4.1.1版本的 T:\ Tools \ Android \ android-studio.4.1.1 重命名.在本文的其余部分中,为了简化起见,我将使用上述路径,并且您需要相应地将其更改为您的路径.

准备 studio.properties 文件

Android Studio基于IntelliJ IDEA产品系列.他们使用 productname.properties 进行可移植性,即.IDEA的 idea.properties ,位于 productfolder/bin 子文件夹下.但是,默认情况下会注释掉它们的可移植性部分,因此我们需要对其进行手动操作.

T:\ Tools \ Android \ android-studio \ bin \ idea.properties 的副本复制到 T:\ Tools \ Android \ studio.properties 中./p>

现在将其打开以进行编辑.使用您使用的任何编辑器,或者如果您是此字段的新手,请遵循以下步骤:

  • 在Windows上,在文件资源管理器中打开 T:\ Tools \ Android \ ,按Shift并右键单击,在此处打开终端".应该存在,选择它以打开命令控制台,键入 notepad studio.properties
  • Linux/Mac用户应该更熟悉编辑工具和控制台,因此我相信您会找到自己的出路.

编辑 studio.properties 文件

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

 #idea.config.path = $ {user.home}/.AndroidStudio/configidea.config.path = $ {idea.home.path}/../.AndroidStudio/config#idea.system.path = $ {user.home}/.AndroidStudio/systemidea.system.path = $ {idea.home.path}/../.AndroidStudio/system#idea.plugins.path = $ {idea.config.path}/pluginsidea.plugins.path = $ {idea.config.path}/plugins#idea.log.path = $ {idea.system.path}/logidea.log.path = $ {idea.system.path}/log 

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

如果不进行这些修改(如果以前有其他版本),则默认情况下将使用这3个文件夹来存储相关文件.如果您想清除以前的非便携式用途,这也很有用.

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

设置 STUDIO_PROPERTIES 并准备运行Android Studio

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

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

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

运行并检查您的安装

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

最大的Android开发可移植性

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

设置Android SDK和设置文件夹

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

 设置ANDROID_SDK_ROOT = t:\ Tools \ Android \ sdk \设置ANDROID_HOME = t:\ Tools \ Android \ sdk \设置ANDROID_SDK_HOME = t:\ Tools \ Android \ .android设置ANDROID_PREFS_ROOT = t:\ Tools \ Android \ .android 

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

设置Gradle文件夹

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

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

已知问题

当前我不知道任何可移植性中断路径设置,因为这些设置似乎已经足够.如果我错过了某些事情,我相信我们会尽快将它们透露出来.

除此之外,安装插件还有问题.我测试了早于2.3.3的版本,并假定所有Android Studio版本都存在此问题:

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

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

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

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).

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.

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

PS: This is a self-answered question, but only does so for Windows. You may contribute by improving or extending for 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.

Introduction

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)

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.

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.

Making Android Studio Portable

Download Android Studio archived (zip/tar.gz) version

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.

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)

Set a virtual drive for best portability

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.

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.

Extract the downloaded file

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

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

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.

Prepare studio.properties file

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.

Make a copy of T:\Tools\Android\android-studio\bin\idea.properties into 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:

  • 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.

Edit studio.properties file

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

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.

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

Set STUDIO_PROPERTIES and get ready to run 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.

Run and and check your installation

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.

Maximum Android Development Portability

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.

Setting Android SDK and settings folder

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 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.

Setting Gradle folder

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.

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:

  • Plugins, at least those requiring a restart, are not installed after restart.

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

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天全站免登陆