Android Studio:使用 Mac (OSX) 和 Windows 更改同一项目的 SDK 位置 [英] Android Studio: SDK location changes for same project using Mac (OSX) and Windows

查看:27
本文介绍了Android Studio:使用 Mac (OSX) 和 Windows 更改同一项目的 SDK 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Android Studio 项目,我的团队成员使用 Windows,我使用 OSX.

I am working on an Android Studio project where my team members use Windows and I use OSX.

问题是,当我从 git 中提取新代码然后打开项目时,我会根据 Mac 的 SDK 位置获得各种更改:

The problem is that when I pull new code from git and then open the project, I get all sorts of changes based on the Mac's SDK location:

首先是打开项目时的一个提示:

First a notice when opening the project:

git diff 记录了一系列与此类似的更改:

git diff logs a bunch of changes similar to this one:

我们如何配置 Android Studio 项目,以便不必发生这些自动代码更改,或者是否有一种方法可以最大限度地减少更改的文件数量?

How do we configure the Android Studio project so that these automatic code changes do not have to occur, or maybe there is a way to minimize the number of files changed?

更新:

我更新了 .gitignore 并将其推送到远程仓库.

I updated the .gitignore and pushed it to the remote repo.

当我的团队更新更多代码并且我将其拉出时,我仍然遇到相同的问题.

When my team updated more code and I pulled it, I still got the same issues.

这是我拉取后的 git status 片段(我使用..."表示该文件夹中的多个文件):

Here is a snippet of my git status after pulling (I used "..." to denote multiple files from that folder):

modified:   .idea/gradle.xml
modified:   .idea/misc.xml
modified:   .idea/modules.xml
modified:   .idea/vcs.xml
modified:   app/app.iml
modified:   app/build/intermediates/incremental/mergeAssets/androidTest/debug/merger.xml
…
    modified:   app/build/intermediates/incremental/mergeResources/debug/merger.xml
    modified:   app/build/intermediates/res/debug/anim/abc_fade_in.xml
...
    modified:   app/build/intermediates/res/debug/anim/abc_slide_out_top.xml
    modified:   app/build/intermediates/res/debug/color-v11/abc_background_cache_hint_selector_material_dark.xml
    modified:   app/build/intermediates/res/debug/color-v11/abc_background_cache_hint_selector_material_light.xml
    modified:   app/build/intermediates/res/debug/color/abc_background_cache_hint_selector_material_dark.xml
...
    modified:   app/build/intermediates/res/debug/color/wallet_secondary_text_holo_dark.xml
    modified:   app/build/intermediates/res/debug/drawable/abc_btn_borderless_material.xml
...
    modified:   app/build/intermediates/res/debug/drawable/timeline_button_hover.xml
    modified:   app/build/intermediates/res/debug/layout/abc_action_bar_title_item.xml
...
    modified:   app/build/intermediates/res/debug/layout/support_simple_spinner_dropdown_item.xml
    modified:   app/build/intermediates/res/debug/menu/menu_all_locations.xml
    modified:   app/build/intermediates/res/debug/menu/menu_main.xml
    modified:   app/build/intermediates/res/debug/values-af/values-af.xml
...
    modified:   app/build/intermediates/res/debug/values/values.xml
    modified:   app/build/intermediates/resources/resources-debug-androidTest.ap_
    modified:   app/build/intermediates/resources/resources-debug.ap_
    modified:   build/intermediates/gradle_project_sync_data.bin
    modified:   local.properties

这是我的 .gitignore,正如@Gabriele Mariotti 所建议的:

Here is my .gitignore, as suggested by @Gabriele Mariotti:

#built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

# Eclipse project files
.classpath
.project

# Android Studio
*.iws
*.iml
.idea
.gradle
build/
*/build/

我需要额外的 .gitignore 配置吗?如果我排除 .idea 那么为什么这些文件显示为已更改?

Do I need additional .gitignore configurations? If I'm excluding .idea then why are these files showing up as changed?

推荐答案

在项目里面你会发现一些 Android Studio 文件,例如 .ideaiml每个模块内的文件.
另请查看此答案了解更多详情.

Inside the project you will find some Android Studio files, for example the .idea and the iml files inside each module.
Check also this answer for more details.

这些资源包含本地路径和引用,您应该从您的 git 存储库中排除它们(.idea 文件夹和 iml 文件).

These resources contain local paths and references and you should exclude them (the .idea folder and iml files) from your git repo.

这是我们在 Mac、Linux 和 Windows 用户中使用的 .gitignore 示例.

It is an example of .gitignore we are using with Mac, Linux and Windows users.

#built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

# Eclipse project files
.classpath
.project

# Android Studio
*.iws
*.iml
.idea
.gradle
build/
*/build/

如果这些文件在 git repo 中,你应该将它们从远程 repo 中删除,然后重新构建本地项目.

If these files are in git repo, you should remove them from the remote repo, and then rebuild the local projects.

这篇关于Android Studio:使用 Mac (OSX) 和 Windows 更改同一项目的 SDK 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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