Trying to use Git with Android Studio - android

With a friend we were a long time trying to work with Git and Android Studio, but we had a problem (we are very new to git and Android Studio, we started a couple of days ago on both issues).
What happens to us is that, for example, if I cloned the git repository and I try to make a merge, then the button to execute is grayed out and it doesn't let me compile or run it, also if I display the project structure as Android or Packages I see nothing, I can only see the files in Project, Project Files, Recent Changes, etc...
I will explain in detail everything we've done.
First, the repository looks like this (p and c are just the initials).
x (c)
/
x (master)
\
x (p)
Master has the first initial commit with .gitignore and README.md, nothing more, while we (me who created the branch p, and my friend who created the branc c) have just one commit each one with executable projects, although I'm not interested in joining what I've done with what my friend has done, I just want to start a new project of Android Studio with what my friend has made.
So I start Android Studio, "Check out project from Version Control -> GitHub", I put my key and choose the repository I want to clone, after that AS ask me if I want to create a new project and I click Yes.
I hit next until the new project is created and here I can see all the branches that we have created on GitHub.
After that I make a local branch to try to work with the project of my friend, with the option "Git branches -> New Branch" and calling it p, which moves me to this local branch automatically.
After that, I choose the Merge option of the remote branch origin/c, and I get a merge failure, that says "Some untracked working tree files would be overwritten by merge. Please move or remove them before you can merge.", I choose the option to view the files and it shows me these.
Since my project is completely new, and the project that my friend uploaded worked fine for him, I just deleted these files with the red bar that my mouse is pointing and after that a message appears that says there is no difference now.
Finally, after that, I go again to the merge option of the remote branch c, and a conflict message appears, which is on the .gitignore file, in my case I put to "Accept Theirs", and I see the message that the merge was correctly.
And now it is when I see that the button to execute is grayed and if I display the project structure as Android I see nothing, I can only see the files in Project, Project Files, etc...
I think it should be something super basic what I'm asking, but we (me and my friend) had never worked with git or android studio and now we are asked to make a project using them.

This is because you have added .idea folder in your git repository.Sample .gitignore file can be like this
build/
.gradle/
*.iml
.idea/
src/main/gen/*
*~
*.swp
local.properties
*.keystore
*.keystore.password
Also you need to delete this folder from git repo. You can use below command
git rm -rf .idea/
git commit -m "deleting .idea, updated .gitignore"
Then try to merge

Followed by #Akhil's answer, click "Make Project" icon to awake your Run button. Sometimes this button makes Android Studio recognize your project runnable again.

Related

how to fix the red class to green can be pushed on github

how to fix the red class to green can be pushed on github, every time I go to github, I don't go to push because it's still red, after editing it's usually green
If files are Red means files are not added to Git.To Add files to git follow below steps
Steps for Add files to git:
Select File which is need to add,next write click on file -> Git->Add
Please refer below screenshot for adding files to git:-
After follow these steps now you can commit and push the files to git.
Steps for Commit files:
Click on VCS->Commit
Refer below screenshot for Commit:-
I hope it works for you
The below file is red because its not added to your git repository.
for adding and committing it to the git repository you must add->commit->push.
There are multiple ways to do so, one way is using the Gui controls available in the android Studio or using the Command line commands.
Below screenshot shows how it is done in android studio.
You can Commit and Push the files whichever you want to be updated in the repository.
Commands to update your new files into repository are :
git stash
git pull
git stash apply
//resolve your conflicts
git add <filename>
git commit -m "<commit message>"
git push
it because you just create a new file and not insert into the commit file, if you binding your git into android studio select VCS -> GIT -> Commit File.
Then on the dialog make sure you have already a checkmark on the file still red, then you can commit the file, after you do that, that will become green when you have changes on your file.
Solved
right clicked the file -> GIT -> Add.

Android Studio Git Push Rejected

I'm trying to uploading my Android Project on github but I get this error when I try to push:
Push rejected: Push to origin/master was rejected
I made this steps:
VCS->Import into version control->Create new repository...
From the git bash in Project folder:
git remote add origin https://github.com/[username]/[project_name].git
Git->Add
Git-> Commit directory
Git-> Push
after push follow these,
VCS --> Git --> Branches
then select origin/master --> Rebase
after finish rebase successful message, you could able to push to remote directory.
As suggested in the comments you should pull the changes first, if you are working on a new repository that could happened when you create your remote repo with a readme or a licence file. To pull the changes from the user interface you should use, VCS > Git > Pull then select the master branch (depends)
after that you can Git > Push without problem.
Just go to the root directory of your project and follow below steps:
Right Click-> Git Bash Here
Type git init (For initializing git).
Type git add -A (Get all files in the staging area).
Type git commit -m "First Commit"(Commit Changes)
Type git remote add origin https://your_git_url.git (Your repo URL)
Type git push -u origin master(master - Branch name)
OR
Type git push -f origin master(master - Branch name) (-f for Force push and make sure there are no changes in your branch to push code.)
You can also make use of Git GUI client:
Github Desktop for github users Download
GitKracken for Windows, Mac and Linux Download (Free for public repositories)
SourceTree for Windows and Mac Download
For Android Studio if your "Push" is rejected, go ahead and try this:
Try to Pull.(Origin/Master).Right after that:
VCS-->Git-->Branches..-->Remote Branches(origin/master)-->Rebase Current onto Selected
This will eradicate all your contradicting configurations.
Try this
This type of error was also coming in my project because i have create a new project and paste my old config and some classes file in new project.
I have pushed the code by creating new branch
Go to VCS->Git->Branches->New Branch
If none of the above solution works then you can check this out..
Log in to the GitHub account and go the settings.
In settings open Emails section and check whether it is public or private.
If it is public then other solution will work out finely and if your email is private then declare it public.
Because of the private email you aren't able to push the files in the repository from your IDE. So, make it public
Another Solution.!!
The unversioned code is not versioned, the changes are committed but don't push.
Following are the steps to make the files versioned.
Open the project tab(must be in the left side toolbar, if not then press 'Alt + F1')
At the top, there is a dropdown with 'Android', open the dropdown and select the 'Project'
In the list shown, right click your project folder
There must be a option of 'Git', select it
Choose the 'Add' option.
And there it is!.
Now simply try to commit and push operation as usual.
**NOTE :**You've to add files everytime using the above steps to upload the files successfully.!!
Thank you folks :)
I had this same problem. I finally tried it from the command line and and received this message:
remote: error: GH007: Your push would publish a private email address.
remote: You can make your email public or disable this protection by visiting:
remote: http://github.com/settings/emails
There you should see two checkboxes. You will need to uncheck one of them.
Keep my email address private
Block command line pushes that expose my email
This is the case when you make a repository with a readme file default and so you can either pull first or make a new repository without a readme file and dont forget to change the repo URL. Hope it helps. Cheers.
I had the same problem, just solve it by doing this:-
Go to Github account settings
(1)
(2)
I had the same issue when I Fork from my another github account and clone it in Android Studio, I changed some file and commit(success) and pushed and that is rejected.
The problem was, I have logged into GitHub in Android Studio with my other account, not the one I'm fork the project. Check out your's from:
File -> Setting -> Version Control -> GitHub
If account information is not match with the repo cloned account, change it.
Then you can Push without a problem.
We can get around this "limitation" by editing the .git/config on the destination server. Add the following to allow a git repository to be pushed to even if it is "checked out":
[receive]
denyCurrentBranch = warn
or
[receive]
denyCurrentBranch = false
If you are pushing for the first time, Delete the repository from git, Share the project again on Git from Android Studio 3
When I encountered the same error in Android Studio; I just simply renamed my remote name and it fixed the error.
Steps which I followed are:
Right click on project name and go to Repository option.
Then select Remotes.
Then you will be asked to Define Remote by providing a name of the remote and URL of your GitHub repository. Just change the name according to your choice if 'origin' is already filled and then fill the URL of your GitHub repository.
I am giving clear note here skip steps you already done..
first create new repository in github. (dont close the tab until work done)
then you have to check whether you are log into your github account in android studio. if not you can log in setting-->Version Control --> github.
Then go to VCS -> Import into Version Control.
now in android studio project tab change it from android to project .Android to Project.
step 3:
then Right click on your project select git then +add. again Right click -> commit and again Right click -->git--> repository--> push.
in the new window select origin ->master then push.. if you already do this part and get the error in here do this.(i think this is the first time you try to add your project to github and github repo is empty.)
goto terminal (bottom of the ide) remove origin using this command.
git remote rm origin
now do step 3 again. after that you will asked to enter github repository url.
whenever you add url make sure to add .git .at the end of the url.
like this. https://github.com//xylophoneApp.git
for anyone maybe Suffers with this issue like me, the entire problem was with executionHistory.bin file, and don't ask me why because I don't know at all.
just create commit without this file and push it, this was the solution for my issue.
Hope this help someone.
In my case initially, I had created a new repository with a Readme file.That's causing the issue. Next time when I create new repo without the Readme file, everything works fine

Migrating SVN to Android Studio

I'm migrating my Android project from Eclipse to Android Studio. I use Subversion and am wondering how I can migrate my SVN to the new file structure used in Android Studio without losing my history.
Thanks for any help!
Posting this because it might help someone else.
I ran into the same problem as well. #user714965 was inspiring but didn't solve my problem because I couldn't figure out how to get SVN recognize that I moved a file from the original folder to the new structure in my working copy.
For the following, you will need TortoiseSVN or a similar SVN GUI client to do this.
Here is what I did:
Commit the Eclipse project last changes into the SVN repo.
Open Android Studio and use that to import the Eclipse project working copy.
Android Studio will nicely convert the Eclipse project into a Android Studio/Gradle project. Let's call this project "PrjGradle".
Open the converted Gradle project folder window and keep it one side of your screen
Go into your SVN repo where you have your project (using TortoiseSVN).
Backup your current trunk into a branch or a tag and call it "final_eclipse" or whatever.
Now, mirror the folder structure of the newly converted Gradle project on your local machine directly on the TortoiseSVN Repo Browser window. Meaning, look at how the directory is structured in "PrkGradle" and create/delete/rename folders directly on the trunk repository. This will be painstakingly tedious but you have to bear with it if you want to preserve your SVN history.
When you move files around (not copy) directly on the repo, the history of the files remain intact.
Once you complete, check out the restructured directory into your local machine. Let's call this "NewPrj".
Use a suitable Folder compare program (such as Beyond Compare) to synchronize missing items (such as build.gradle, .iml files, etc.)
Rename your converted project to "PrjGradle_old", and rename the newly checked out project (NewPrj) to "PrjGradle".
Open "PrjGradle" in Android Studio. That's it!
Hope it works out.
I don't know the differences of both file structures. But it would try it this way:
Check out your project (maybe better use a client like TortoiseSVN)
Build the new file structure (new folders)
Commit
Move the files from the old structure to the new
Commit (check the commit dialog if there are move actions only!)
Delete old folders which you don't need anymore
Commit
SVN will recognize these move operations. You will see if it works by the operations in the commit dialog. If there are "delete"/"new" actions something went wrong there should only be "move" actions.

eGit move project to a different location?

I was working on an Android project in Eclipse and I then decided to Git it. Being new, instead of creating a local repository in the parent of the project, I ended up creating it in C:\Users\Little\.git\LocalRepository.
Now, I am facing a lot of problems in my Android project; specifically with adding user libraries to my build path.
Based on this answer here:
Eclipse will not recognize project as library (ActionBarSherlock/ViewPagerIndicator)
I have imported all the user libraries to my workspace. However, my project itself is in a different folder and hence I am stuck. There is also a comment on the answer which says:
Thanks. In my case, I forgot that my project was imported from git and
was physically located in another folder than all other projects.
I believe I have to do the same. How do I get the project from local repo to my workspace?
May be below command help someone to get rid of same issue with command line :
Step 1 : To make sure that ur git does not contains any local changes do :
git status
make sure here there is files where u have changes something and is in red color
Step 2: To check when and how commited last do :
git log
Step 3 :
rm -rf .git
Make sure u just take backup.
Step 4 : do git clone to dir u need :
git clone ssh://firstname.lastname#xx.x.xx.xx:xxxxx/project_name

How to push Eclipse project to Github

I'm new to Git and Github and I'm trying to figure out how to push to the root directory on Github from Eclipse (Windows).
I have created a Github project called MyProject. MyProject is an Android project with the usual Android directory structure:
MyProject
src (+ res, assets, etc)
From Eclipse I push my Android project called MyGame to MyProject. MyProject now becomes a sub-directory to MyGame, so that the readme file in MyProject isn't visible unless the user first clicks on MyProject on Github to drill down one level in the directory hierarchy.
How can I push MyGame so that its contents (src folder, res folder, readme) become visible at the root level in the Github project.
Update: I tried using command line:
git remote add origin git#github.com:username/reponame.git
git push origin master
This has the same result, on Github the directory hierarchy is:
MyProject
MyGame
src
How can I make it
MyProject
src
?
I believe your problem may be that your git repo in Eclipse is in the parent folder of the project. What you need is for your git repo to be in the project folder.
Now, Eclipse seems to recommend that Git repos be set up in the parent folder of their projects. I am guessing that this is so that later related projects that may be needed can be easily added to the git repo. If you're not worried about that, and just want it to work as you described, see below.
Note that I'm running Ubuntu Linux, and so my Eclipse and desktop will probably look different from yours.
First we're going to find out if my guess as to the problem is correct:
Open the "Git Repository Exploring" perspective in Eclipse.
Look at the "Git Repositories" view. See if the path given for your repository is pointing to the folder containing your project. If it is, continue with the instructions below.
If your repo is in the folder above your project, then the problem shapes up like this: Git will recreate all the paths in your repo relative to the repository itself when you push it to GitHub. If it is in the folder above your project, then all the paths will include the folder containing your project. So, you'll need to move your repo into the folder containing your project. I'll describe the steps to achieve that below.
To begin, you'll want to make sure you don't have any uncommitted changes, or any stashed changes (if you don't know what stashed changes are, don't worry about them).
As a matter of caution, you may want to create a complete copy of your current code & repository at this point if it's at all important.
Open Windows Explorer and navigate to the folder containing your git repo, per the path given in the "Git Repositories" view.
At this point, you may want to close Eclipse, to avoid changes startling it (they shouldn't, but "you never can tell with bees!")
If you can see a .git folder in Windows Explorer, then go on to the next step. If not, you'll need to show hidden files. http://windows.microsoft.com/en-US/windows7/show-hidden-files gives instructions for Win7.
Now you should be able to see a .git folder. Copy this into your project folder.
Start Eclipse (if you closed it) and open the "Git Repositories" view again.
Click the button to add an existing local git repository. Choose the project folder.
Go back to the normal Eclipse Java perspective. Right-click your project and choose Team > Disconnect to temporarily stop heeding the old repository.
Right-click on the project again and choose Team > Share Project.... When prompted for a repository, check the box to use the one in the project/parent folder. In the view below, check the box of the one which is directly within the project folder (it will probably have one dot next to a folder.) Then click the Finish button.
Now you'll probably have a lot of catching up to do. Git will believe that you have deleted every file in your project and replaced it with a file with one less layer of directory path. You'll need to commit all those changes to get a clean repo.
Push the changes from step ten to GitHub. Check that it looks as you expect.
I hope this helps. Please comment if something's unclear or there's another issue. Please make sure to have a backup before you try this... I've not tested it entirely, and I don't want to cause any unneeded grief.

Categories

Resources