如何在Android Studio中正确使用Git? [英] How to use Git correctly in Android Studio?
问题描述
我知道这是一个在stackoverflow上讨论得很多的话题,但我无法弄清楚如何使这项工作。我希望:
$ b
- 创建一个Android Studio项目
- 使用git
- 将项目推送到bitbucket
- 在另一台计算机上拉项目
这是我使用的.gitignore(基本上是Android Studio创建的一个,我删除了* .iml文件 - 因为这没有奏效)
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/ build
/ captures
但不知何故,这种方法无效。无论我的gitignore文件是什么,Android Studio都不会识别该项目。
所以,真正的问题是:如何将Android Studio项目推送到git中,以便我可以简单地把它拉到另一个客户继续工作?
编辑:
所以这里是我做事情,步骤
$ b
- 在Android Studio中创建项目GitTest
- 在Bitbucket上创建一个git存储库在Android Studio中选择启用版本控制集成 - 选择git
- 浏览到gitignore文件并将其更改为与Mauker的
在左侧项目下选择Project,然后在Git下添加
解决方案在其他计算机上,您可以尝试导入项目,而不是打开它。
实际上,您不要必须将项目特定的文件提交到您的git仓库。使用IntelliJ IDEA,您不仅可以从$ b创建一个Android项目,而且还可以从$ b中创建一个Android项目。
$ b从头开始,还可以导入使用其他
工具开发的现有项目。最常见的一种情况是导入现有的
Android-Gradle项目。但是,您也可以导入Maven,Eclipse
或Flash Builder项目,甚至可以从一堆
源文件中创建一个新项目。
就像这样:
这里有一个很好的和更详细的教程关于如何从源和其他地方导入Android Studio上的项目。
对于
.gitignore
我强烈建议您使用gitignore.io
网站。
另外,如果您已经提交了不应该存在的文件,请检查
下面是一个
.gitignore $>的例子。 c $ c>我在其中一个项目中使用的文件。
#由https://www.gitignore.io创建/ api / android,osx,windows,linux,intellij,java
### Android ###
#构建的应用程序文件
* .apk
*。 ap_
#Dalvik VM文件
* .dex
#Java类文件
* .class
#生成的文件
bin /
gen /
#Gradle文件
.gradle /
build /
#本地配置文件(sdk路径等)
local.properties
由Eclipse生成的Proguard文件夹
proguard /
#日志文件
*。日志
#Android Studio导航编辑器临时文件
.navigation /
### Android补丁###
gen-external-apklibs
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
#图标必须以两个\\ \\ r
图标
#缩略图
._ *
#可能出现在卷的根目录中的文件
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
#可能在远程法新社分享的目录
.AppleDB
.AppleDesktop
网络垃圾箱文件夹
临时项目
.apdisk
### Windows ###
#Windows映像文件缓存
Thumbs.db
ehthumbs.db
#文件夹配置文件
Desktop.ini
#用于文件共享的回收站
$ RECYCLE.BIN /
#Windows安装程序文件
* .cab
* .msi
* .msm
* .msp
#Windows快捷键
* .lnk
### Linux ###
*〜
#KDE目录首选项
.directory
#可能出现在任何分区或磁盘上的Linux垃圾文件夹
.Trash- *
### Intellij ###
#涵盖JetBrains IDE:IntelliJ,RubyMine,PhpStorm,AppCode,PyCharm,C Lion,Android Studio
* .iml
##基于目录的项目格式:
.idea /
#如果删除上述规则,至少忽略以下内容:
#用户特定的东西:
#.idea / workspace.xml
#.idea / tasks.xml
#.idea /字典
#敏感或高分辨率文件:
#.idea / dataSources.ids
#.idea / dataSources.xml
#.idea / sqlDataSources.xml
#.idea / dynamic.xml
#.idea / uiDesigner.xml
#Gradle:
#.idea / gradle.xml
#。 idea / libraries
#Mongo Explorer插件:
#.idea / mongoSettings.xml
##基于文件的项目格式:
* .ipr
* .iws
##特定于插件的文件:
#IntelliJ
/ out /
#mpeltonen / sbt-idea插件
.idea_modules /
#JIRA插件
atlassian-ide-plugin.xml
#Crashlytics插件(适用于Android Studio和IntelliJ )
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build。属性
### Java ###
* .class
#Java移动工具(J2ME)
.mtj。 tmp /
#程序包文件#
* .jar
* .war
* .ear
I know this is a much-discussed topic on stackoverflow, but I just can't figure out how to make this work. I would like to:
- create an Android Studio project
- check the project in with git
- push the project to bitbucket
- pull the project on a different computer
This is the .gitignore I'm using (basically the Android Studio created one, where I removed the *.iml files - cause that didn't work)
.gradle /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store /build /captures
But somehow, it just won't work. Android Studio won't recognise the Project, no matter what my gitignore file looks like.
So actual question: how do I push an Android Studio project to git so I can simply pull it into another client to continue working?
EDIT:
So here’s how I do things, step-by-step:
- create project GitTest in Android Studio
- create a git repository on Bitbucket
- in Android Studio: select "enable version control integration" - pick "git"
- browse to the gitignore files and change it to match Mauker’s
under "project on the left" select "Project" then under Git "Add"
commit/push the changes (define the remote repo in the process)
at this point, the project is on bitbucket. Next comes the "import project" part:
- open android studio
- select "Check out project from Version Control"
- Import Project from Gradle (using the default grade wrapper as recommended)
- Unregistered VCS root detected -> add root
The project loads, I get some sort of NullPointerException
解决方案On the other computer you could try to import the project, instead of opening it.
Actually, you don't have to commit project specific files to your git repo. Android Studio is smart enough to import a project from many different sources.
With IntelliJ IDEA you can not only create an Android project from scratch, but also import an existing project developed using other tools. One of the most common scenarios is importing an existing Android-Gradle project. However, you can also import a Maven, Eclipse or Flash Builder project, or even build a new project from a bunch of source files.
Just like this:
And here's a nice and more detailed tutorial on how to import a project on Android Studio from source and other places.
For your
.gitignore
file I strongly recommend you to get one usinggitignore.io
website.Also, if you already commited files that are not supposed to be there, check this question and see how you can remove them.
Here's an example of a
.gitignore
file that I use on one of my projects.# Created by https://www.gitignore.io/api/android,osx,windows,linux,intellij,java ### Android ### # Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ ### Android Patch ### gen-external-apklibs ### OSX ### .DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon # Thumbnails ._* # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk ### Windows ### # Windows image file caches Thumbs.db ehthumbs.db # Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Windows Installer files *.cab *.msi *.msm *.msp # Windows shortcuts *.lnk ### Linux ### *~ # KDE directory preferences .directory # Linux trash folder which might appear on any partition or disk .Trash-* ### Intellij ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio *.iml ## Directory-based project format: .idea/ # if you remove the above rule, at least ignore the following: # User-specific stuff: # .idea/workspace.xml # .idea/tasks.xml # .idea/dictionaries # Sensitive or high-churn files: # .idea/dataSources.ids # .idea/dataSources.xml # .idea/sqlDataSources.xml # .idea/dynamic.xml # .idea/uiDesigner.xml # Gradle: # .idea/gradle.xml # .idea/libraries # Mongo Explorer plugin: # .idea/mongoSettings.xml ## File-based project format: *.ipr *.iws ## Plugin-specific files: # IntelliJ /out/ # mpeltonen/sbt-idea plugin .idea_modules/ # JIRA plugin atlassian-ide-plugin.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties ### Java ### *.class # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.ear
这篇关于如何在Android Studio中正确使用Git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!