I may be missing something here but, how come my android project tree used to look like that when I created my first project 5 months ago (with folders like .idea, build, or R.java)
And now, I've just created a new projet and it looks like that :
Did I make a mistake at some point ? How can I display all the folders and files like R.java ?
Thank you.
If you look at the files outside of Android Studio, you should find that the structure is nearly identical.
What you are seeing is the new Android project view. Note that at the very top of your screenshots the first one says "project" and the second one says "Android."
The Android project view simplifies the way the information is present a bit- for example, it will put all your Gradle scripts together and it will combine drawables with the same name to make finding different versions of the same drawable a bit easier.
If you don't like the new view, you can click on "Android" to see a dropdown containing other options, including the old Project view.
Sorry, silly mistake : the view was different.
Related
Not sure if this is possible, but I have many multi module projects. Each module essentially follows module/src/main/java/packages... This is shown in photo below
Currently I have to click src -> main -> java -> etc....
Ideally I would like to just click src and have the whole directory open up. This would save me a good amount of time in the long run. I have searched for an Android Studio setting that does this but no luck. Would I have to write some kind of script for this? I'm lost on how to achieve this
Thanks
You can use the key * on the numeric keypad, it will automatically expand the tree. This setting can be configured with a different key by searching:
Fully Expand Tree Node
I don't think exactly what you're looking for exists (to my knowledge, and I've been using Android Studio since its beta).
I think the closest thing you're looking for are these two things: 'Compact Middle Packages' and/or setting your project view to 'Android' (see screenshots below).
I hope this helps, if not, you could create a feature request to the Android Studio team.
Set your project view to 'Android' and select 'Flatten Packages' as shown in image.
When you expand java it will show list of all packages (check below image).
I used to give simple ids to Android Views, but lately, I stopped that altogether because of this issue.
Let's say I have 2 layouts, one named first_layout.xml and second named second_layout.xml. In each of these layouts, there is a view with id username_input. This id is used in different activity classes to access target view, be it ButterKnife binding, Kotlin Android Extensions, or even findViewById.
Now, for whatever reason, I need to rename id in just one layout. Thus I do Refactor -> Rename. What happens? Android Studio simply replaces id username_input in the whole project, messing other layouts that had view the same id. Most people don't use a unique id for each and every view in the project since it's not mandatory, but I do because I do lots of refactoring, and many times I lost hours because of this non-contextual replacement in the project.
What are my options in this case? Is there a way to make Android Studio do the contextual replacement in such a situation, or should I keep making unique ids in my project?
Moments ago I was facing this same issue and I found it to be the Android Studio's expected behavior, as other elements might be constrained to the element whose ID is getting changed. So you need to update all the IDs particularly in your new layout file through its text editor AND NOT from the Attribute section of its design editor
Its working fine for me, and so must work well for you too :)
I too faced same issue, when i copied widget from an one activity to another activity and tried to change ID in copied widget. It prompt a dialog box and i clicked "No (Local Only)". But, i feel no use of that option. it still updated ID in old activity too.
Workaround:
Try to change ID or Attributes through Code(Text Editor) not from Design.
I feel google should address this issue and remove this bug.
Right click on the id you want to rename the go to:
Refactor -> Rename
Now you will see an option "Scope" and under Scope you need to select "Current File" in order to rename the id in that file only.
(Not sure if it was there when this question was asked!)
I just came across this post because I was having a similar problem. I have an app with different flavors. In one of my layouts I have 12 buttons. In a different flavor, I want all of those buttons plus I add 4 more. So, I created a new version of the layout in a flavor-specific directory. The problem is every time I tried to change anything that has an ID it would change the identically-named layout in the main directory.
With flavors, you're supposed to be able to override the main directory's layout with a flavor specific one. This was extremely frustrating!
This MUST be a bug in Android Studio. The frustrating part is that it's still not fixed. I installed Android Studio via the JetBrains toolbox since I use other JetBrains IDEs. Currently I'm on version 3.5.3
My workaround
To get around this bug I created a "test" project. I copied the layout code that I wanted to modify, pasted it in the test project and edited it there. When I was done altering it the way I wanted, I created the alternative layout in the flavor specific directory (using the same name as the main directory's layout that I want to override) of the actual project I was working on. Then I copied the layout from my test project and pasted it into the flavor specific file. By doing this, it didn't alter the layout in the project's main directory.
My thoughts
You shouldn't have to do this. It's certainly not the intuitive way. This is why I can't believe that this is anything but a bug. With that said, I hope I have provided a clear workaround for anyone else who's stuck. If I haven't comment below and I will clarify what I can.
This is the image of my main_avtivity:
This is the image of my activity_main.xml layout:
I have imported com.example.calculator.R class. I even tried to clean the project so many times. I even made a new Project two times. Moreover my ADT Plugin is properly installed. Plz help me. I have done everything mentioned in other StackOverflow answers but nothing seems to be working for me.
R.java won't generate properly if there are errors in your XML files. So look through your XML files and look for any possible issues. The errors in the console at the bottom of your second screenshot would be a good place to start.
First SaveAll your changes then go to project>Clean Project and Build it again. Its seems like you didn't save your project.
Firstly thanks to Mark Murphy, regarding comment 10 and the link to a really blank activity template in Android Issue 67513
Now the question regarding the new template: Is it intended that it should still create a new appcompat_v7_n+1 library project?
When I tried it, one was created. I deleted it, removed the reference from the blank activity project, then had to delete references to appcompat styles in the values folders and a style in the manifest.
Don't get me wrong, doing that was no big deal and it's a vast improvement but I'm wondering if that was intended.
Is it intended that it should still create a new appcompat_v7_n+1 library project?
Crap.
The new-project wizard adds some of that. I thought it was all in the new-activity wizard, which also adds some of that when using the stock templates.
I'll need to fork the NewAndroidApplication template to get rid of those bits. I'll work on that. I've added a note to the project README in the interim.
Thanks for pointing this out!
OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res