git Android Studio 设置 - 清除只读状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21607317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:41:33  来源:igfitidea点击:

Android Studio setup - Clear Read-Only Status

gitandroid-studio

提问by Ante

Permission to write to certain folder isn't obtained. Android Studio asks this. Only thing I can click on "Cancel" button.

未获得写入特定文件夹的权限。Android Studio 会问这个。只有我可以点击“取消”按钮。

Clear read only-status

清除只读状态

Afterwards, when I want to leave Android Studio I get "could not save project".

之后,当我想离开 Android Studio 时,我得到“无法保存项目”。

Could not save project

无法保存项目

  • Project is downloaded from git repository.
  • Works fine on other macs.
  • Project is downloaded to user/projects/project-name.
  • Tried to play with permissions without success
  • Tried to change project directory location (another project in the same directory is working)
  • Installed all possible packages
  • 项目是从 git 存储库下载的。
  • 在其他 Mac 上运行良好。
  • 项目下载到用户/项目/项目名称。
  • 尝试使用权限但没有成功
  • 试图更改项目目录位置(同一目录中的另一个项目正在工作)
  • 安装了所有可能的包

Permissions on files in project folder

项目文件夹中文件的权限

Locked icons in Android studio.

Android Studio 中的锁定图标。

enter image description here

在此处输入图片说明

I need any suggestion in what direction to look for solution?

我需要在什么方向上寻找解决方案的任何建议?

回答by Scott Barta

The most likely explanation is that the directory and all its files are owned by a different user account on the system. Normally the "Clear Read-Only Access" dialog will fix up read permission problems if it's possible to do so; if it's not (because the files are owned by another user), the dialog will refuse to let you click the OK button.

最可能的解释是该目录及其所有文件由系统上的不同用户帐户拥有。通常情况下,“清除只读访问”对话框会在可能的情况下修复读取权限问题;如果不是(因为文件归另一个用户所有),对话框将拒绝让您单击“确定”按钮。

You can confirm this by using the lscommand from the MacOS terminal. Here's an example from a random project of mine.

您可以使用ls来自 MacOS 终端的命令来确认这一点。这是我的一个随机项目中的一个例子。

sbarta-macbookpro2:~/AndroidStudioProjects/ASProject$ ls -alh
total 80
-rw-r--r--  1 foo   eng   438B Jan  9 10:54 local.properties
-rw-r--r--  1 foo   eng   853B Jan  9 10:54 gradle.properties
drwxr-xr-x  3 foo   eng   102B Jan  9 10:54 gradle

If you run man lsyou can read the man page for the lscommand and get a lot more information on the output from the command, but the single "w" character in the output for each file tells me that those files are only writable by the file's owner. Those files are all owned by the foo user (which is what the third column of output means). I'm not foo when I'm running Android Studio, so I can't write to those files, and since I'm not foo, I don't have permissions to give myself write access to them.

如果您运行,man ls您可以阅读该ls命令的手册页并获得有关该命令输出的更多信息,但是每个文件的输出中的单个“w”字符告诉我这些文件只能由文件所有者写入. 这些文件都归 foo 用户所有(这是输出的第三列的意思)。当我运行 Android Studio 时,我不是 foo,所以我不能写入这些文件,而且由于我不是 foo,我没有权限给自己写访问它们。

You can fix it with the following command. Be very careful you use the correct path when you run this command; making large-scale filesystem changes under sudocan do a lot of damage if you make a mistake.

您可以使用以下命令修复它。运行此命令时要非常小心使用正确的路径;sudo如果你犯了一个错误,在下面进行大规模的文件系统更改会造成很大的损害。

sudo chown -R $USER /path/to/project/directory

There's probably a way to fix this through the Finder UI, but the command-line is pretty easy.

可能有一种方法可以通过 Finder UI 解决此问题,但命令行非常简单。

It will ask you for an administrator password, and after that it should make you the owner of those files and the "Clear Read-Only Status" dialog should work for you.

它会要求您输入管理员密码,然后它应该让您成为这些文件的所有者,并且“清除只读状态”对话框应该适合您。

回答by Alex Burov

I had the same problem with Android Studio for Linux (IntelliJ IDEA) It looked like this: when I was trying to edit some project files (i.e. build.txt or build.gradle) the Studio displayed a "Clear Read-Only Status" dialog window with the "OK" button throwing another warning "Failed to change read-only status for the following files:"

我在 Android Studio for Linux (IntelliJ IDEA) 上遇到了同样的问题 它看起来像这样:当我尝试编辑一些项目文件(即 build.txt 或 build.gradle)时,Studio 显示了一个“清除只读状态”对话框带有“确定”按钮的窗口抛出另一个警告“无法更改以下文件的只读状态:”

enter image description here

在此处输入图片说明

Steps to fix ( I will use the user "alex") 1) Ensure you are under the right user

修复步骤(我将使用用户“alex”)1)确保您在正确的用户下

echo $USER

alex

2) Check the ownership rights of the troubled file (Example:"build.txt)

2)检查问题文件的所有权(例如:“build.txt)

 ls -als Downloads/android-studio/

total 56
 4 drwxrwxr-x  8 alex alex  4096 Nov 10 11:51 .
 4 drwxr-xr-x 16 alex alex  4096 Apr 25 11:13 ..
 4 drwxrwxr-x  3 alex alex  4096 Feb  7 15:44 bin
 4 -rw-r--r--  1 root root    14 Nov  9 10:26 build.txt
 4 drwxrwxr-x  4 alex alex  4096 Nov 10 11:51 gradle
 4 -rw-r--r--  1 alex alex  1934 Nov  9 10:26 Install-Linux-tar.txt
 4 drwxrwxr-x  6 alex alex  4096 Nov 10 11:51 jre
 4 drwxrwxr-x  5 alex alex  4096 Nov 10 11:51 lib
 4 drwxrwxr-x  2 alex alex  4096 Nov 10 11:51 license
12 -rw-r--r--  1 alex alex 11352 Nov  9 10:26 LICENSE.txt
 4 -rw-r--r--  1 alex alex   397 Nov  9 10:26 NOTICE.txt
 4 drwxrwxr-x 39 alex alex  4096 Nov 10 11:51 plugins

That build.txt is owned by the root! That's why the Android Studio cannot edit it.

那 build.txt 归根所有!这就是 Android Studio 无法编辑它的原因。

3) Fix the ownership rights for the whole project directory

3) 修复整个项目目录的所有权

sudo chown -R $USER /project/directory/

回答by Andrew Dremov

I had the same problem and was playing with permissions and settings for a while. I found 2 solutions for this problem:

我遇到了同样的问题,并且玩了一段时间的权限和设置。我为这个问题找到了 2 个解决方案:

  1. Just launch your Android Studio from the terminal using sudo. For example
    cd /Applications/Android\ Studio.app/Contents/MacOS/ sudo ./studio

  2. Choose a folder with your android projects -> Get Info -> scroll down to 'Sharing & Permissions' -> set the permission for 'staff' as 'Read & Write' -> press small settings wheel icon below -> choose 'Apply to enclosed items'.

  1. 只需使用sudo. 例如
    cd /Applications/Android\ Studio.app/Contents/MacOS/ sudo ./studio

  2. 选择一个包含您的 android 项目的文件夹 -> 获取信息 -> 向下滚动到“共享和权限”-> 将“员工”的权限设置为“读取和写入”-> 按下面的小设置轮图标 -> 选择“应用到”封闭的物品”。

If there is no possibility to choose 'Apply to enclosed items' than u need to unlock the small lock icon first.

如果无法选择“应用于封闭物品”,则您需要先解锁小锁图标。

回答by Irfan Ul Haq

The most easiest way is to open the class file in android studio and then goto file > Make file writable. please check this: http://android.okhelp.cz/android-studio-lock-unlock-file-make-read-only-or-writable/

最简单的方法是在android studio中打开class文件,然后goto file > Make file writable。请检查:http: //android.okhelp.cz/android-studio-lock-unlock-file-make-read-only-or-writable/

回答by Joel Jerushan

CD to your project root path and run this command sudo chown -R YOUR_PROJECT_FOLDER_NAME

CD 到您的项目根路径并运行此命令 sudo chown -R YOUR_PROJECT_FOLDER_NAME

this will solve your problem.

这将解决您的问题。

回答by Amrit Grewal

In Windows I fixed the issue (after I had deleted .idea folder. I don't know if that makes any difference) by Selecting Import Non-Android Studio Projectoption from the Welcome to Android Studioscreen. You get this screen when no project is open.

在 Windows 中,我通过Import Non-Android Studio ProjectWelcome to Android Studio屏幕中选择选项解决了这个问题(在我删除了 .idea 文件夹之后。我不知道这是否有任何区别)。当没有项目打开时,您会看到此屏幕。

Things that I tried but didn't work for me:

我尝试过但对我不起作用的事情:

  1. executed as admin from cmd ----> attrib -r +s c:\workingdir and attrib -r +s c:\workingdir\*
  2. Changed the read only flag from properties.
  3. Changed permissions while in safe mode.
  1. 从 cmd 以管理员身份执行 ----> attrib -r +s c:\workingdir and attrib -r +s c:\workingdir\*
  2. 更改了属性中的只读标志。
  3. 在安全模式下更改权限。

回答by Onat Korucu

You can try giving read-write permission to your Android project, its sub-modules, their sub-modules, theirs etc. ...

您可以尝试为您的 Android 项目、其子模块、它们的子模块、它们的等授予读写权限。...

yourName-MacBook-Pro:androidProjectsFolder yourusername$ sudo chmod -R 777 .   

(Don't forget the dot "." at the end)

(不要忘记末尾的点“.”)

-R stands for recursion. 777 is for "read-write"

-R 代表递归。777 表示“读写”

EDIT: Remember, checking if permission is causing the problem first is advised. In Mac, go to the path of trouble file path, right click, click "Get info", scroll down, see which permission is given (Read Only, Read&Write, Custom etc.). If the problem is not permission, giving high access level may cause security issues.

编辑:请记住,建议首先检查权限是否导致问题。在 Mac 中,转到故障文件路径的路径,右键单击,单击“获取信息”,向下滚动,查看授予的权限(只读、读写、自定义等)。如果问题不是权限,则授予高访问级别可能会导致安全问题。

回答by Himanshu -

Well, the best way to solve this problem is:

那么,解决这个问题的最好方法是:

  • Download VS studio from Microsoft.

  • Just save and close your project completely.

  • Now edit or Open your file with VS studio.

  • Make changes and save it.

  • Enjoy!

  • 从 Microsoft 下载 VS Studio。

  • 只需保存并完全关闭您的项目。

  • 现在使用 VS Studio 编辑或打开您的文件。

  • 进行更改并保存。

  • 享受!

回答by Satyam Goyal

Close Android Studio. Save .idea folder for future restore (if something happend) Remove .idea folder Start Android Studio and open project.

关闭 Android Studio。保存 .idea 文件夹以备将来恢复(如果发生了什么) 删除 .idea 文件夹 启动 Android Studio 并打开项目。

回答by Kai Wang

Do this.

做这个。

1, change something of the file;

1、改变文件的一些东西;

2, a dialog is shown, in right down corner should be a line asking you "do you want to remove delete";

2、弹出一个对话框,在右下角应该有一行问你“是否要删除删除”;

3, check that line;

3、检查那条线;

  1. press ok.
  1. 按确定。

the read only will be gone.

只读将消失。