Gradle creates huge number of files in project-directory - android

-- using a Linux Mint system with AndroidStudio 2.3.3 -
Even the simplest "HelloWorld" project under AndroidStudio fills the projectdirectory with 1000+ of files ??
Is there a way to avoid this or bring back the number of files to a reasonable quantity ?
( I remember when working with eclipse for Android the same simple project generated a 20+ number of files ? )
Thanks for any advice or explantion.
erics

Even the simplest "HelloWorld" project under AndroidStudio fills the projectdirectory with 1000+ of files ??
That isn't the simplest one. I just created one with 125 files in app/build/, which my guess is the source of your complaints.
The project started with ~1100 files in app/build/. Most of the ~1000-file difference between the starting point and ending point were from dependencies, particularly appcompat-v7.
Is there a way to avoid this or bring back the number of files to a reasonable quantity ?
Of all the metrics to be concerned about, the number of files in app/build/ should be a very low-priority one. But, you are certainly welcome to remove dependencies from your builds to try to reduce the number of files.

Related

Android Projects: Organize Artwork and Sound with Version control

I've been working with Android for quite some time, yet I have never seen any good explanations for this issue.
I'm working on an app with a number of artwork and sound files. Many of these files are temporary, are base files that future work will evolve from, or are large versions that will be split into multiple files later. I want to keep them under version control with this project, and I'd like to keep everything in the same place on my hard drive.
But I don't want these "work" files to end up in my apk. They are often huge and have nothing to do with the final product.
For most of my life (ie, before Android), I would simply have a subdirectory within my project called art_work_files. And this directory would be subdivided into all the various tasks. And git is fine with this, especially for SVG files (it even properly notes differences and changes).
But when I put these files in my Android Studio project, I get concerned that the AS will think these are somehow important and keep references to them--possibly even adding them to jar or apk files.
Yes, I realize that the final versions of the art needs to go in the res/drawing/ directories (and similar for sound and other resources). And I'm happy to do this final copy.
Am I over-thinking this, or is there a better way to organize and still keep Android Studio happy?
Since no one has answered this question in 7 months, I'll submit my solution.
I have created a directory under the main directectory (same level as java and res) called assets. Git recognizes this directory and will notice any files that are added, removed, or changed. I'm fine with using git to handle binaries btw.
For each type of asset, I make another subdirectory. Here's what it looks like:
app ->
libs
src ->
main ->
assets ->
font
ogg
png
svg
java
res
...
This seems to work fine and keeps everyone happy. I'm still curious how other people do this; I welcome your comments and answers.

Is it possible to recover overwritten files from Android Studio?

For a mistake i've overwritten my two project that has same names from android studio and i've dismissed that action today i've tryed to open the main project and i've found no Java classes in it and just the layout's files.
While in the second project to which i was overwritting there is a huge confusion of files and trying to recover the project version by using history of Android Studio even those files has disappeared.
Is it possible in anyway to recover the whole project?
Ps: all that remain from that project is a generated apk.
I have some solutions that may work.
Candidates are:
Search for $AppData$ folders
Search for registries
(Hardest) you may have to preserve the disk state and carve the files yourself..
Cheers, and hope it helped..!
To use the third method(file carving), you may not cause many file operations occur!!(The system may overwrite the previous data)
Hopefully you used source control such as git or svn and it is a simple matter of reverting to the last commit you made, however that is done in your chosen source control. If you don't use source control, perhaps this will serve as a lesson to do so in the future.
I've not used Android Studio, but as a JetBrains product like IntelliJ, it will have a local history record of changes. But that would only record very recent changes.
If that doesn't work, you may have to find out if your chosen operating system backed up the files in a restore point etc.
If you have turned on the file history, you can use that to go to a previous version of the folder. Can also use system restore to go back to a previous date. Can also use third party softwares such as Recuva to get deleted files back.
Make sure to keep a copy of current state somewhere before trying these out.

The size of freshly new Android project

I created a new project in Android Studio and nothing more (by that I mean having a main activity which does nothing). But when I checked the size of a project folder on my disc I saw it tooks over 40MB! I looked into the project file's content and I saw there folders for which I have questions about:
1) What is the purpose of folder (and it's content) MyProgram/build/generated? Is there a possibility to not create it? (I would save 30MB on my disc by deleting it.)
2) I presume that I shouldn't delete MyProgram/app/build/intermediates so I'm wondering if it'll grow with development of MyProgram? And if the answer is "yes" then how much the size will change? (It tooks almost 10MB now and I'm afraid what will happen when I do something more in my code.)
What is the purpose of folder (and it's content) MyProgram/build/generated?
For a module (e.g., app/) build/generated/ contains Java source code and other files that are generated as part of the build process.
If you are referring to the build/generated/ that appears off of the project root directory, that contains... a JAR. This is an odd place for the build tools to put this particular type of file.
Is there a possibility to not create it?
I don't think so. However, its contents will not go into your APK file. If your development machine is so short on disk space that a 30MB file makes a difference, you will have a very difficult time doing Android development.
I'm wondering if it'll grow with development of MyProgram?
Most likely.
how much the size will change?
That will vary by the size of your app (your code, third-party libraries that you add, etc.) and changes to the build tools over time. It is impossible to tell you exactly how large it will get.
The size from the basic "Hello world" is the minium, doesnt matter if the size is 30 mb or more, is just about the development code, when you generate de APK to share and install your app the basic "Hello world" the size is 2.5 - 3.5 mb. depends from the version of android studio are you using actually, the last version form android studio add somethings.
How i say the real size from you apk is the important, for example if you create the drawables resources for the diferents densities when you install the app just keep 1 density resources, an application size average 7 - 10 mb. A simple app is weird is the size exceeds this numbers.
1) build/ directory and build/intermediates/ is output of the build process,contains Java source code, do not delete.
2) repeat the 1) answer, do not delete.

Why there is two r files under r directory in android studio?

I am beginner in Android app development.I have a doubt in R files.I can see two r files under r directory in android studio.What is the significance of both files.I believe one R file under my specific project folder is to display the layout.What is the need of the other one. Please help me to clear this query.
The one under android.support.v7.appcompat hold "resources" (I am using this word very very loosely) for appCompatv7. This is important because in the future, you may find yourself needing to make your app compatible for older versions, hence, an "appCompat"ibility resource is needed.
The one under com.example.apzalbahin.basiccheck is where the IDs of your views (TextViews, EditTexts, etc) are filed in.
Normally, you don't touch the R files since they would cause major problems for your application. This was a common mistake back when Android Studio wasn't out yet and Eclipse had to be used -- people accidentally modifying or deleting the R.java file.
Just leave it all on it's own and you won't have problems.
There are two configuration mode: Debug and Release ... so two R.java files.. however both have the same codes i guess.

Debug on many phones in Android Studio

Is it possible to debug an app on many phones at the same time in Android Studio? By this I mean launching multiple debug instances, each one on a different phone, like in Eclipse.
At the time of posting this question probably the only solution was the one posted by George V.M. Now, after several updates of Android Studio, this can be easily done by creating N copies of the same Debug configuration and launching each of them on a separate phone.
Update
You might want to take a look at Vlad's answer. This one is pointless for newer versions of Android Studio. In case anyone is still curious, this was my really hacky way of solving the problem
In case anyone out there is still looking for a solution to this, here's what I've found.
I'm working on a project that requires wireless communication between 2 instances of the same app running on 2 phones (actually, 2 or more). There were a lot of times where I wished I could debug 2 devices at a time. It wasn't until recently that I figured out how to do it.
It's actually quite simple: Have 2 instances of Android Studio open and you can debug multiple devices at once, (one device on each Android Studio instance) with breakpoints and everything!
Catch 1: You can't open two instances of the same project
I haven't been able to run two instances of Android Studio where both instances have the same project open. It will just redirect you to the already open project.
Solution:
The solution to this is to just make a copy of your project somewhere on your PC and open that project allowing you to have two copies of the same project open.
Catch 2: Changes have to be made on each copy manually.
Now here's a new problem. What if while debugging, you find a mistake in your code and amend it. Now you have to make sure you make that exact same amendment in your second copy of the project so that the second device doesn't have the same error if it hits those lines. This is annoying, having to remember to make a change twice; once in each copy of the project.
Solution:
My solution to this problem was to just make a 'symbolic link' of the project instead of a physical copy.
(A symbolic link is a 'nickname' or a 'reference' to a file. If you make a symbolic link fileB that points to fileA, although they seem like two distinct files to the OS, they in fact point to the exact same physical file. Any changes made on fileA will be reflected in fileB since they point to the same physical file/data on the disk. Instructions on how to create symbolic links are given below)
Now hold on just one second!!! Making a symbolic link of the entire project might not be a very smart idea since you'll have two Android Studios trying to edit the same files. This could lead to problems, especially in the case of build files and IDE files.
So what I did was make a symbolic link of only the source files, or any file which I'd be editing directly and which AS wouldn't normally touch, and make a physical copy of every other file.
The only thing you need to do is remember to hit Ctrl+S after making changes to your code in one AS instance so that the changes will be reflected on the second one. It might still take a couple of seconds for those changes to be reflected in the second instance but you can just click the "Synchronize" button (top left, next to "Open" and "Save") on your second AS which will cause all externally changed files, i.e., the file you just edited in your first instance, to be reloaded from disk.
You still need to be careful though. Every time you make a change in one AS, make sure you save all those changes and that those changes are reflected in the second AS before you try doing any editing in the second AS. Otherwise conflicts could cause you to lose the changes you made in one copy. One way around this is to force yourself to make changes to a file only on one AS and not the other.
Actual Instructions:
Okay that was a lot of talk. Here are the steps you can follow along with tips:
Close Android Studio and make a copy of your project into another folder on your PC
Go to your second copy and delete all your source code files since we're going to make symbolic links of them.
(these are the files I usually make symbolic links of instead of a copy:
all build.gradle files
the entire app/src folder
if you have any other loose source or resource files or othwerwise non IDE files that you might edit, make symbolic links of them as well
Make a symbolic link of all those non IDE files from the first project folder into your second project folder.
to make a symbolic link of a file in Windows, use
mklink path\to\symbolic\link path\to\original\file
to make symbolic link of a folder in Windows, use
mklink /j "path\to\symbolic\link" "path\to\original\folder"
to make a symbolic link of a file or folder in Linux, use
ln -s "path/to/original/file_or_folder" "path/to/link"
Open up Android Studio again. It will probably open the original copy of your project if that was the last project you opened in AS.
Go to File>Open and open up the second project copy on your PC.
You will now have 2 copies of your project running and you will be able to debug your app on 2 devices at the same time! (Remember that breakpoints won't be shared between the two copies)
If you are talking about attaching the debugger to several phones, I'm going to say no.
The port will be blocked with that traffic from one phone.
Unless someone figure out a hacky way to do this, atm It's not possible as far as my knowledge.
Android studio has its VM devices, but it requires installing Intel Accelerator because it's too slow until it show up. alternatively, I recommended "Genymotion" for running multiple instances and different devices. I'm using it and its working perfectly.
It may takes a while for setup and installing but once its installed it will be light weight and I promise you'll be pleased while working on it =)
Here is the link:
genymotion intallation user guide,
genymotion website

Categories

Resources